Skip to content

LanguageServices.getDocumentHighlights does not find references within JSX #4175

@adidahiya

Description

@adidahiya

Using v1.6.0-dev.20150805.

For the following code, LanguageServices.getDocumentHighlights reports only 1 highlight span for onChange, where it should really report 2:

test.tsx

import * as React from "react";

export class Foo extends React.Component<{}, {}> {
    public render() {
        return (
            <div>
                <input onChange={this.onChange.bind(this)} />
            </div>
        );
    }

    onChange() {
        console.log("changed");
    }
}

You can reproduce this error with the sample code from #3688 (copied below):

var ts = require('typescript');
var fs = require('fs');

var source = fs.readFileSync('test.tsx').toString();
var sourceFile = ts.createSourceFile('test.tsx', source, 1, false);

var host = {
  getCompilationSettings: function() {
      return {
          noResolve: true,
          target: ts.ScriptTarget.ES5
      };
  },
  getCurrentDirectory: function() {
    return '';
  },
  getDefaultLibFileName: function() {
    return 'lib.d.ts';
  },
  getScriptFileNames: function() {
    return ['test.tsx'];
  },
  getScriptIsOpen: function() {
    return true;
  },
  getScriptVersion: function() {
    return '1';
  },
  getScriptSnapshot: function() {
    return ts.ScriptSnapshot.fromString(source);
  }
};

var documentRegistry = ts.createDocumentRegistry();
var languageServices = ts.createLanguageService(host, documentRegistry);

var onChangeFn = sourceFile.statements[1].members[1];
var highlights = languageServices.getDocumentHighlights('test.tsx', onChangeFn.name.pos, ['test.tsx']);
console.log(highlights[0].highlightSpans.length);

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions