-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
fix(language-service): return all typecheck files via getExternalFiles #40162
Conversation
a909851
to
cfe3ca0
Compare
export function getExternalFiles(project: ts.server.Project): string[] { | ||
const typecheckFiles: string[] = []; | ||
for (const scriptInfo of project.getScriptInfos()) { | ||
if (scriptInfo.scriptKind === ts.ScriptKind.External) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I tried to get tcfs via source files in the program, but it's just way too complex and not worth the effort. The isShim()
method does not work, because according to Andrew, the source file tagged by the compiler is not the same as the source file contained in the latest program. The other method, templateTypeChecker. isTrackedTypeCheckFile()
involves instantiating the Ivy compiler and the ttc, so it's also quite involved.
We have three different methods to detect typecheck files now, so we should probably do a cleanup in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if we'll have issues with this check if other plugins also register external files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in the way this package (@angular/language-service
) is used, because we control the server, and we know for sure the Angular language service is the only plugin installed.
'', // fileContent | ||
// script info added by plugins should be marked as external, see | ||
// https://github.com/microsoft/TypeScript/blob/b217f22e798c781f55d17da72ed099a9dee5c650/src/compiler/program.ts#L1897-L1899 | ||
ts.ScriptKind.External, // scriptKind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I wonder if this has implications for "find references". Have you tried building the plugin with this change and running it in the extension host?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I did, and I can confirm that "find references" still works. From TS language service point of view, the script info kind doesn't really matter, whether they are TS
or External
, they all end up in the ts.Program
(see code in the link above), so I doubt it'll affect "find references".
export function getExternalFiles(project: ts.server.Project): string[] { | ||
const typecheckFiles: string[] = []; | ||
for (const scriptInfo of project.getScriptInfos()) { | ||
if (scriptInfo.scriptKind === ts.ScriptKind.External) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if we'll have issues with this check if other plugins also register external files?
// Now that global analysis is run, we should have all the typecheck files | ||
externalFiles = getExternalFiles(project); | ||
expect(externalFiles.length).toBe(1); | ||
expect(externalFiles[0].endsWith('app.component.ngtypecheck.ts')).toBeTrue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more e2e way that we can test this? Like triggering a reload on the project, either with a direct call to updateGraph
or doing some other action that would trigger it organically and then asserting that our stuff still works?
Maybe a test like that is dependent on this PR being submitted first (since the e2e tests in the client depend on the published version of the plugin).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some integration tests for the VE-based language service in this repo. I think a test to make sure that the typeck files are kept after a project reload are a good idea, but should be done in angular/angular
if we're going to do them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// Now that global analysis is run, we should have all the typecheck files | ||
externalFiles = getExternalFiles(project); | ||
expect(externalFiles.length).toBe(1); | ||
expect(externalFiles[0].endsWith('app.component.ngtypecheck.ts')).toBeTrue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some integration tests for the VE-based language service in this repo. I think a test to make sure that the typeck files are kept after a project reload are a good idea, but should be done in angular/angular
if we're going to do them.
This is a follow-up to angular/angular#40162. In View Engine, `getExternalFiles()` returns a list of external templates (HTML files), but we should not have marked them as `ScriptKind.External`. As noted in https://github.com/microsoft/TypeScript/blob/b217f22e798c781f55d17da72ed099a9dee5c650/src/compiler/program.ts#L1897-L1899 `ScriptKind.External` should be used for external TypeScript files added by plugins. External templates should be marked as `ScriptKind.Unknown` instead.
This is a follow-up to angular/angular#40162. In View Engine, `getExternalFiles()` returns a list of external templates (HTML files), but we should not have marked them as `ScriptKind.External`. As noted in https://github.com/microsoft/TypeScript/blob/b217f22e798c781f55d17da72ed099a9dee5c650/src/compiler/program.ts#L1897-L1899 `ScriptKind.External` should be used for external TypeScript files added by plugins. External templates should be marked as `ScriptKind.Unknown` instead.
This is a follow-up to angular/angular#40162. In View Engine, `getExternalFiles()` returns a list of external templates (HTML files), but we should not have marked them as `ScriptKind.External`. As noted in https://github.com/microsoft/TypeScript/blob/b217f22e798c781f55d17da72ed099a9dee5c650/src/compiler/program.ts#L1897-L1899 `ScriptKind.External` should be used for external TypeScript files added by plugins. External templates should be marked as `ScriptKind.Unknown` instead.
cfe3ca0
to
ff7260c
Compare
This is a follow-up to angular/angular#40162. In View Engine, `getExternalFiles()` returns a list of external templates (HTML files), but we should not have marked them as `ScriptKind.External`. As noted in https://github.com/microsoft/TypeScript/blob/b217f22e798c781f55d17da72ed099a9dee5c650/src/compiler/program.ts#L1897-L1899 `ScriptKind.External` should be used for external TypeScript files added by plugins. External templates should be marked as `ScriptKind.Unknown` instead.
ff7260c
to
106ef3e
Compare
We need a means to preserve typecheck files when a project is reloaded, otherwise the Ivy compiler will throw an error when it's unable to find them. This commit implements `getExternalFiles()` called by the langauge server to achieve this goal. For more info see angular/vscode-ng-language-service#1030
106ef3e
to
3883a0c
Compare
I'll merge this for now. Created https://github.com/orgs/angular/projects/1#card-52319541 to keep track of the integration test for project reload. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
We need a means to preserve typecheck files when a project is reloaded,
otherwise the Ivy compiler will throw an error when it fails to find them in the program.
(The compiler is told by the IncrementalDriver that the tcfs exist.)
This commit implements
getExternalFiles()
called by the languageserver to achieve this goal.
For more info see angular/vscode-ng-language-service#1030
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information