forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle changes to inferred projects during FAR
In some scenarios (see the new test for an example), FAR may search an inferred project and then subsequently trigger the loading of a configured project containing (some of) the same files. When the configured project is loaded, the files are removed from the inferred project and added to the configured project, potentially _invalidating the results already computed for the inferred project_. This change introduces a cleanup pass that removes results from `dirty` projects if the corresponding files are no longer in the project. Caught by microsoft#50679
- Loading branch information
Showing
3 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
tests/baselines/reference/referencesInInferredProject.baseline.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// === /proj/__test__/a.test.ts === | ||
// import { [|x|] } from "../a"; | ||
// [|x|].toString(); | ||
|
||
// === /proj/a.ts === | ||
// export const /*FIND ALL REFS*/[|x|] = 1; | ||
|
||
[ | ||
{ | ||
"definition": { | ||
"containerKind": "", | ||
"containerName": "", | ||
"fileName": "/proj/a.ts", | ||
"kind": "const", | ||
"name": "const x: 1", | ||
"textSpan": { | ||
"start": 13, | ||
"length": 1 | ||
}, | ||
"displayParts": [ | ||
{ | ||
"text": "const", | ||
"kind": "keyword" | ||
}, | ||
{ | ||
"text": " ", | ||
"kind": "space" | ||
}, | ||
{ | ||
"text": "x", | ||
"kind": "localName" | ||
}, | ||
{ | ||
"text": ":", | ||
"kind": "punctuation" | ||
}, | ||
{ | ||
"text": " ", | ||
"kind": "space" | ||
}, | ||
{ | ||
"text": "1", | ||
"kind": "stringLiteral" | ||
} | ||
], | ||
"contextSpan": { | ||
"start": 0, | ||
"length": 19 | ||
} | ||
}, | ||
"references": [ | ||
{ | ||
"textSpan": { | ||
"start": 13, | ||
"length": 1 | ||
}, | ||
"fileName": "/proj/a.ts", | ||
"contextSpan": { | ||
"start": 0, | ||
"length": 19 | ||
}, | ||
"isWriteAccess": true, | ||
"isDefinition": true | ||
} | ||
] | ||
}, | ||
{ | ||
"definition": { | ||
"containerKind": "", | ||
"containerName": "", | ||
"fileName": "/proj/__test__/a.test.ts", | ||
"kind": "alias", | ||
"name": "(alias) const x: 1\nimport x", | ||
"textSpan": { | ||
"start": 9, | ||
"length": 1 | ||
}, | ||
"displayParts": [ | ||
{ | ||
"text": "(", | ||
"kind": "punctuation" | ||
}, | ||
{ | ||
"text": "alias", | ||
"kind": "text" | ||
}, | ||
{ | ||
"text": ")", | ||
"kind": "punctuation" | ||
}, | ||
{ | ||
"text": " ", | ||
"kind": "space" | ||
}, | ||
{ | ||
"text": "const", | ||
"kind": "keyword" | ||
}, | ||
{ | ||
"text": " ", | ||
"kind": "space" | ||
}, | ||
{ | ||
"text": "x", | ||
"kind": "aliasName" | ||
}, | ||
{ | ||
"text": ":", | ||
"kind": "punctuation" | ||
}, | ||
{ | ||
"text": " ", | ||
"kind": "space" | ||
}, | ||
{ | ||
"text": "1", | ||
"kind": "stringLiteral" | ||
}, | ||
{ | ||
"text": "\n", | ||
"kind": "lineBreak" | ||
}, | ||
{ | ||
"text": "import", | ||
"kind": "keyword" | ||
}, | ||
{ | ||
"text": " ", | ||
"kind": "space" | ||
}, | ||
{ | ||
"text": "x", | ||
"kind": "aliasName" | ||
} | ||
], | ||
"contextSpan": { | ||
"start": 0, | ||
"length": 25 | ||
} | ||
}, | ||
"references": [ | ||
{ | ||
"textSpan": { | ||
"start": 9, | ||
"length": 1 | ||
}, | ||
"fileName": "/proj/__test__/a.test.ts", | ||
"contextSpan": { | ||
"start": 0, | ||
"length": 25 | ||
}, | ||
"isWriteAccess": true, | ||
"isDefinition": false | ||
}, | ||
{ | ||
"textSpan": { | ||
"start": 26, | ||
"length": 1 | ||
}, | ||
"fileName": "/proj/__test__/a.test.ts", | ||
"isWriteAccess": false, | ||
"isDefinition": false | ||
} | ||
] | ||
} | ||
] |
28 changes: 28 additions & 0 deletions
28
tests/cases/fourslash/server/referencesInInferredProject.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/// <reference path="../fourslash.ts"/> | ||
|
||
// @Filename: /tsconfig.json | ||
////{ } | ||
|
||
// @Filename: /proj/tsconfig.json | ||
////{ | ||
//// "compilerOptions": { | ||
//// "composite": true, | ||
//// }, | ||
//// "exclude": ["**/__test__/"] | ||
////} | ||
|
||
// @Filename: /proj/a.ts | ||
////export const /*1*/x = 1; | ||
|
||
// @Filename: /proj/__test__/a.test.ts | ||
////import { x } from "../a"; | ||
////x.toString(); | ||
|
||
// Open both source files | ||
// The test file will be in an inferred project, since its default project excludes it | ||
// The product file will be in both its default configured project and the inferred project for the test file | ||
goTo.file("/proj/a.ts"); | ||
goTo.file("/proj/__test__/a.test.ts"); | ||
// FAR will cause the root tsconfig to be loaded (since the LS happens to know about it and it could contain references), | ||
// which will *remove* both files from the inferred project, invalidating any references attributed to that project | ||
verify.baselineFindAllReferences('1') |