Port #48978 forward to the revised FAR code (#49267)

* Port #48978 forward to the revised FAR code

The old regression test didn't catch the corresponding bug in the new code because it hit the fast path where there's only a single project.

* Drop spurious non-null assertion
This commit is contained in:
Andrew Casey 2022-05-27 09:52:20 -07:00 committed by GitHub
parent 46e53016e4
commit 757a3acbde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 3 deletions

View File

@ -379,8 +379,8 @@ namespace ts.server {
// have started the other project searches from related symbols. Propagate the
// correct results to all other projects.
const defaultProjectResults = perProjectResults.get(defaultProject)!;
if (defaultProjectResults[0].references[0].isDefinition === undefined) {
const defaultProjectResults = perProjectResults.get(defaultProject);
if (defaultProjectResults?.[0].references[0]?.isDefinition === undefined) {
// Clear all isDefinition properties
perProjectResults.forEach(projectResults => {
for (const referencedSymbol of projectResults) {
@ -580,7 +580,6 @@ namespace ts.server {
return resultsMap;
// May enqueue to otherPositionQueue
function searchPosition(project: Project, location: DocumentPosition): readonly TResult[] | undefined {
const projectResults = getResultsForPosition(project, location);
if (!projectResults) return undefined;

View File

@ -0,0 +1,24 @@
[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/a/a.ts",
"kind": "var",
"name": "hello",
"textSpan": {
"start": 56,
"length": 5
},
"displayParts": [
{
"text": "\"hello\"",
"kind": "stringLiteral"
}
]
},
"references": []
}
]
[]

View File

@ -0,0 +1,16 @@
/// <reference path="../fourslash.ts"/>
// @Filename: /a/tsconfig.json
////{ "files": ["a.ts"] }
// @Filename: /a/a.ts
/////// <reference path="../b/b.ts" />
/////*1*/;
// @Filename: /b/tsconfig.json
////{ "files": ["b.ts"] }
// @Filename: /b/b.ts
/////*2*/;
verify.baselineFindAllReferences('1', '2')

View File

@ -0,0 +1,16 @@
/// <reference path="../fourslash.ts"/>
// @Filename: /a/tsconfig.json
////{ "files": ["a.ts"] }
// @Filename: /a/a.ts
/////// <reference path="../b/b.ts" />
////const str: string = "hello/*1*/";
// @Filename: /b/tsconfig.json
////{ "files": ["b.ts"] }
// @Filename: /b/b.ts
////const str2: string = "hello/*2*/";
verify.baselineFindAllReferences('1', '2')