Skip to content

Commit 7b360f0

Browse files
authored
fix(language-server): Ensure diagnostics are refreshed when language service gets enabled (#1669)
There is currently some amount magic that triggers diagnostics after the language service is enabled. The mechanism that causes this to happen is ngcc. ngcc generates a lockfile named `__ngcc_lock_file__` in the node_modules directory, this triggers the directory watcher, and [ProjectsUpdatedInBackgroundEvent](https://github.com/angular/vscode-ng-language-service/blob/8c809a2982ccad19997caef7ffeaa899e9d8ddb5/server/src/session.ts#L491) event is send by the method [delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles](https://github.com/microsoft/TypeScript/blob/56a4a93718ce016f038bcbce425bd3f47c3bec78/src/server/editorServices.ts#L1356). But this [PR](angular/angular#44228) broke this. Because the `.ngcc_lock_file` is [ignored by tsserver](https://github.com/microsoft/TypeScript/blob/ab2523bbe0352d4486f67b73473d2143ad64d03d/src/compiler/sys.ts#L500) and the tsserver will [skip updating the project](https://github.com/microsoft/TypeScript/blob/56a4a93718ce016f038bcbce425bd3f47c3bec78/src/server/editorServices.ts#L1316). When updating the integration project to use v14, the tests begin to fail: https://app.circleci.com/pipelines/github/angular/vscode-ng-language-service/3585/workflows/40f00184-ea1e-441a-8af3-0fe5f017883f/jobs/3512 Instead of relying on magic/automatic triggering, this commit explictly requests that the project refresh diagnostics after enabling the language service. In fact, this change would have eventually been necessary when `ngcc` is no longer run at all. Special thanks to @ivanwonder for pinpointing the exact reasons for this breakage: #1659 (comment)
1 parent 8c809a2 commit 7b360f0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

server/src/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ export class Session {
404404
// (because language service was disabled while waiting for ngcc).
405405
// First, make sure the Angular project is complete.
406406
this.runGlobalAnalysisForNewlyLoadedProject(project);
407+
project.refreshDiagnostics();
407408
}
408409

409410
private disableLanguageServiceForProject(project: ts.server.Project, reason: string): void {

0 commit comments

Comments
 (0)