Skip to content

Commit 0084697

Browse files
authored
Catch failure to open script when language service is disabled (#699)
This commit supresses diagnostic events sent by a project service regarding changes to a project. Today, not supressing such events can cause a type error to be thrown when the language server session begins handling events for a file that is outside the project managed by the project service, and for which a program does not exist in the corresponding project's language service. This commit also wraps blocks that terminate in setting a notification status to always complete their notification. Closes #693 Closes #696
1 parent 2bae69c commit 0084697

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

server/src/session.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export class Session {
5252
useSingleInferredProject: true,
5353
useInferredProjectPerProjectRoot: true,
5454
typingsInstaller: ts.server.nullTypingsInstaller,
55-
suppressDiagnosticEvents: false,
55+
// Not supressing diagnostic events can cause a type error to be thrown when the
56+
// language server session gets an event for a file that is outside the project
57+
// managed by the project service, and for which a program does not exist in the
58+
// corresponding project's language service.
59+
// See https://github.com/angular/vscode-ng-language-service/issues/693
60+
suppressDiagnosticEvents: true,
5661
eventHandler: (e) => this.handleProjectServiceEvent(e),
5762
globalPlugins: ['@angular/language-service'],
5863
pluginProbeLocations: [options.ngProbeLocation],
@@ -85,11 +90,14 @@ export class Session {
8590
break;
8691
case ts.server.ProjectLoadingFinishEvent: {
8792
const {project} = event.data;
88-
// Disable language service if project is not Angular
89-
this.checkIsAngularProject(project);
90-
if (this.isProjectLoading) {
91-
this.isProjectLoading = false;
92-
this.connection.sendNotification(projectLoadingNotification.finish);
93+
try {
94+
// Disable language service if project is not Angular
95+
this.checkIsAngularProject(project);
96+
} finally {
97+
if (this.isProjectLoading) {
98+
this.isProjectLoading = false;
99+
this.connection.sendNotification(projectLoadingNotification.finish);
100+
}
93101
}
94102
break;
95103
}

0 commit comments

Comments
 (0)