-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Inconsistency in getDocumentHighlights for import aliases #3688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I assume this also means find-references and rename is also not working in this scenario. |
There seem to be some related funny issues going on. When calling // Incorrect case:
class HelloWorld {
constructor(public name: string) { }
sayHello() {
return `Hello, ${this.name}!`;
}
};
let hello = new HelloWorld("TSLint");
hello.sayHello(); only the declaration is returned and not the usage on the next line. However, in the following code snippet, both uses are returned, correctly: // Correct case:
class HelloWorld {
constructor(public name: string) { }
sayHello() {
return `Hello, ${this.name}!`;
}
};
if (true) {
let hello = new HelloWorld("TSLint");
hello.sayHello();
} Also strangely, Sublime will correctly show both references in both cases. I've been trying to figure out the root cause but haven't been able to yet. I did notice that in the var referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation);
if (referenceSymbol) {
var referenceSymbolDeclaration = referenceSymbol.valueDeclaration;
var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);
var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation);
// NOTE (added for the Github issue):
// relatedSymbol is undefined here in incorrect case, defined in the correct case
if (relatedSymbol) {
var referencedSymbol = getReferencedSymbol(relatedSymbol);
referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation));
}
else if (!(referenceSymbol.flags & 67108864 /* Transient */) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) {
var referencedSymbol = getReferencedSymbol(shorthandValueSymbol);
referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name));
}
} (Related to palantir/tslint#570) |
@jkillian I'm not able to reproduce the error: it's likely unrelated to the issue filed here, so if you're still seeing it, can you file a separate bug? |
@DanielRosenwasser Created a new issue from my previous comment with a few details added: #4560 |
@leeavital The issue comes from this code: getScriptSnapshot: function() {
return {
getLength: function() {
return source.length;
},
getLineStartPositions: function () {
return ts.computeLineStarts(source);
},
getText: function(start, end) {
return source.substring(start, end);
}
};
}
|
My apologies, I think this is still a bug. I had assumed that our incorrect usage of the language services was the issue, but it doesn't seem like that's the case. FindReferences in Sublime doesn't mark both references. In addition, this fourslash test fails: /// <reference path='fourslash.ts' />
////import [|fs|] = require('fs');
////import ws = [|fs|].writeStream;
let ranges = test.ranges()
for (let range of ranges) {
goTo.position(range.start);
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
} (related palantir/tslint#325) |
@DanielRosenwasser Any updates on this? Is the fix fairly involved? |
I'm honestly not sure, I'll try to find some time to work on this soon. |
@jkillian is this still an issue? i believe it has been fixed in latest. |
Verified that this is fixed in the latest nightly, thanks! (palantir/tslint#1294) Feel free to close this issue |
thanks! |
For the file:
getDocumentHighlights will not find that the fs on line 1 is the same as the one on line 2.
But for the file:
I wrote a small program to demonstrate the problem.
When
test.ts
contains the first example, it outputs 1. Whentest.ts
contains the second example, it outputs 2.The text was updated successfully, but these errors were encountered: