Skip to content

Commit

Permalink
Handle the case where the FAR results map is empty (#49254)
Browse files Browse the repository at this point in the history
* Handle the case where the FAR results map is empty

Searching exactly one project does not imply the presence of exactly one references list.

Fixes #49217

* Use emptyArray

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
  • Loading branch information
amcasey and sheetalkamat committed May 26, 2022
1 parent 77ffb96 commit 8497483
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ namespace ts.server {
// it easier for the caller to skip post-processing.
if (searchedProjects.size === 1) {
const it = resultsMap.values().next();
Debug.assert(!it.done);
return it.value;
return it.done ? emptyArray : it.value; // There may not be any results at all
}

return resultsMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/tests/cases/fourslash/server/referencesToStringLiteralValue.ts",
"kind": "var",
"name": "some string",
"textSpan": {
"start": 19,
"length": 12
},
"displayParts": [
{
"text": "\"some string\"",
"kind": "stringLiteral"
}
]
},
"references": []
}
]
5 changes: 5 additions & 0 deletions tests/cases/fourslash/server/referenceToEmptyObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path='fourslash.ts'/>

////const obj = {}/*1*/;

verify.baselineFindAllReferences('1');
5 changes: 5 additions & 0 deletions tests/cases/fourslash/server/referencesInEmptyFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path='fourslash.ts'/>

/////*1*/

verify.baselineFindAllReferences('1');
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path='fourslash.ts'/>

////const s: string = "some /*1*/ string";

verify.baselineFindAllReferences('1');

0 comments on commit 8497483

Please sign in to comment.