{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4560","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4560/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4560/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4560/events","html_url":"https://github.com/Microsoft/TypeScript/issues/4560","id":104099863,"number":4560,"title":"Possible incorrect getDocumentHighlights behavior with global lexically scoped variables","user":{"login":"JKillian","id":1400151,"avatar_url":"https://avatars.githubusercontent.com/u/1400151?v=3","gravatar_id":"","url":"https://api.github.com/users/JKillian","html_url":"https://github.com/JKillian","followers_url":"https://api.github.com/users/JKillian/followers","following_url":"https://api.github.com/users/JKillian/following{/other_user}","gists_url":"https://api.github.com/users/JKillian/gists{/gist_id}","starred_url":"https://api.github.com/users/JKillian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JKillian/subscriptions","organizations_url":"https://api.github.com/users/JKillian/orgs","repos_url":"https://api.github.com/users/JKillian/repos","events_url":"https://api.github.com/users/JKillian/events{/privacy}","received_events_url":"https://api.github.com/users/JKillian/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/API","name":"API","color":"bfe5bf"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Bug","name":"Bug","color":"e11d21"}],"state":"open","locked":false,"assignee":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/11","html_url":"https://github.com/Microsoft/TypeScript/milestones/TypeScript%201.7","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/11/labels","id":1189604,"number":11,"title":"TypeScript 1.7","description":"","creator":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"open_issues":110,"closed_issues":9,"state":"open","created_at":"2015-07-01T19:21:45Z","updated_at":"2015-09-11T16:12:45Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2015-08-31T17:51:13Z","updated_at":"2015-09-11T18:39:43Z","closed_at":null,"body":"There seem to be some related funny issues going on. When calling `getDocumentHighlights` on the position of the `hello` variable declaration in the following code snippet:\r\n\r\n```typescript\r\n// Incorrect case:\r\n\r\nclass HelloWorld {\r\n    constructor(public name: string) { }\r\n    sayHello() {\r\n        return `Hello, ${this.name}!`;\r\n    }\r\n};\r\n\r\nlet hello = new HelloWorld(\"TSLint\");\r\nhello.sayHello();\r\n```\r\n only the declaration is returned and not the usage on the next line. However, in the following code snippet, both uses are returned, correctly: \r\n\r\n```typescript\r\n// Correct case:\r\n\r\nclass HelloWorld {\r\n    constructor(public name: string) { }\r\n    sayHello() {\r\n        return `Hello, ${this.name}!`;\r\n    }\r\n};\r\n\r\nif (true) {\r\n    let hello = new HelloWorld(\"TSLint\");\r\n    hello.sayHello();\r\n}\r\n```\r\n\r\n```typescript\r\n// Correct case (var vs. let):\r\n\r\nclass HelloWorld {\r\n    constructor(public name: string) { }\r\n    sayHello() {\r\n        return `Hello, ${this.name}!`;\r\n    }\r\n};\r\n\r\nvar hello = new HelloWorld(\"TSLint\");\r\nhello.sayHello();\r\n```\r\n\r\nAlso strangely, Sublime will correctly show both references in all three cases. \r\n\r\nI've been trying to figure out the root cause but haven't been able to yet. It seems that the failure occurs specifically for lexically scoped variables declared at global scope, such as `let` declarations at global scope. \r\n\r\nIn case it helps, I did notice that in the `getReferencesInNode` function the array of possible positions contains exactly the two actual positions in both the incorrect and correct case. However, there is a difference when finding the `relatedSymbol`:\r\n\r\n```typescript\r\nvar referenceSymbol = typeChecker.getSymbolAtLocation(referenceLocation);\r\nif (referenceSymbol) {\r\n    var referenceSymbolDeclaration = referenceSymbol.valueDeclaration;\r\n    var shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);\r\n    var relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation);\r\n    // NOTE (added for the Github issue):\r\n    // relatedSymbol is undefined here in incorrect case, defined in the correct case\r\n    if (relatedSymbol) {\r\n        var referencedSymbol = getReferencedSymbol(relatedSymbol);\r\n        referencedSymbol.references.push(getReferenceEntryFromNode(referenceLocation));\r\n    }\r\n    else if (!(referenceSymbol.flags & 67108864 /* Transient */) && searchSymbols.indexOf(shorthandValueSymbol) >= 0) {\r\n        var referencedSymbol = getReferencedSymbol(shorthandValueSymbol);\r\n        referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name));\r\n    }\r\n}\r\n```\r\n\r\n\r\n(Related to https://github.com/palantir/tslint/issues/570)"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/139623139","html_url":"https://github.com/Microsoft/TypeScript/issues/4560#issuecomment-139623139","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4560","id":139623139,"user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"created_at":"2015-09-11T18:39:43Z","updated_at":"2015-09-11T18:39:43Z","body":"this looks good to me. an empty lib file should do the trick."}}