Skip to content

Commit d4034da

Browse files
kyliauKeen Yee Liau
authored andcommitted
refactor: remove suggest Ivy LS notification
Now that Ivy LS is the default, `SuggestIvyLanguageService` notification is no longer needed.
1 parent ea3a739 commit d4034da

File tree

4 files changed

+25
-59
lines changed

4 files changed

+25
-59
lines changed

client/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as path from 'path';
1111
import * as vscode from 'vscode';
1212
import * as lsp from 'vscode-languageclient/node';
1313

14-
import {ProjectLoadingFinish, ProjectLoadingStart, SuggestIvyLanguageService, SuggestIvyLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../common/notifications';
14+
import {ProjectLoadingFinish, ProjectLoadingStart, SuggestStrictMode, SuggestStrictModeParams} from '../common/notifications';
1515
import {NgccProgress, NgccProgressToken, NgccProgressType} from '../common/progress';
1616
import {GetComponentsWithTemplateFile, GetTcbRequest, IsInAngularProject} from '../common/requests';
1717

common/notifications.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,3 @@ export interface SuggestStrictModeParams {
2626

2727
export const SuggestStrictMode =
2828
new NotificationType<SuggestStrictModeParams>('angular/suggestStrictMode');
29-
30-
export interface SuggestIvyLanguageServiceParams {
31-
message: string;
32-
}
33-
34-
export const SuggestIvyLanguageService =
35-
new NotificationType<SuggestIvyLanguageServiceParams>('angular/suggestIvyLanguageServiceMode');

integration/lsp/viewengine_spec.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import {MessageConnection} from 'vscode-jsonrpc';
1010
import * as lsp from 'vscode-languageserver-protocol';
1111

12-
import {SuggestIvyLanguageService, SuggestIvyLanguageServiceParams} from '../../common/notifications';
1312
import {APP_COMPONENT, FOO_TEMPLATE} from '../test_constants';
1413

1514
import {createConnection, initializeServer, openTextDocument} from './test_utils';
@@ -111,12 +110,6 @@ describe('Angular language server', () => {
111110
expect(diagnostics.length).toBe(1);
112111
expect(diagnostics[0].message).toContain(`Identifier 'doesnotexist' is not defined.`);
113112
});
114-
115-
it('should prompt to enable Ivy Language Service', async () => {
116-
openTextDocument(client, APP_COMPONENT);
117-
const message = await onSuggestIvyLanguageService(client);
118-
expect(message).toContain('Would you like to enable the new Ivy-native language service');
119-
});
120113
});
121114

122115
describe('initialization', () => {
@@ -148,11 +141,3 @@ describe('initialization', () => {
148141
client.dispose();
149142
});
150143
});
151-
152-
function onSuggestIvyLanguageService(client: MessageConnection): Promise<string> {
153-
return new Promise(resolve => {
154-
client.onNotification(SuggestIvyLanguageService, (params: SuggestIvyLanguageServiceParams) => {
155-
resolve(params.message);
156-
});
157-
});
158-
}

server/src/session.ts

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {promisify} from 'util';
1313
import * as lsp from 'vscode-languageserver/node';
1414

1515
import {ServerOptions} from '../common/initialize';
16-
import {ProjectLanguageService, ProjectLoadingFinish, ProjectLoadingStart, SuggestIvyLanguageService, SuggestStrictMode} from '../common/notifications';
16+
import {ProjectLanguageService, ProjectLoadingFinish, ProjectLoadingStart, SuggestStrictMode} from '../common/notifications';
1717
import {NgccProgressToken, NgccProgressType} from '../common/progress';
1818
import {GetComponentsWithTemplateFile, GetTcbParams, GetTcbRequest, GetTcbResponse, IsInAngularProject, IsInAngularProjectParams} from '../common/requests';
1919

@@ -22,7 +22,6 @@ import {tsDiagnosticToLspDiagnostic} from './diagnostic';
2222
import {resolveAndRunNgcc} from './ngcc';
2323
import {ServerHost} from './server_host';
2424
import {filePathToUri, isConfiguredProject, isDebugMode, lspPositionToTsPosition, lspRangeToTsPositions, MruTracker, tsDisplayPartsToText, tsTextSpanToLspRange, uriToFilePath} from './utils';
25-
import {resolve, Version} from './version_provider';
2625

2726
export interface SessionOptions {
2827
host: ServerHost;
@@ -50,7 +49,6 @@ export class Session {
5049
private readonly connection: lsp.Connection;
5150
private readonly projectService: ts.server.ProjectService;
5251
private readonly logger: ts.server.Logger;
53-
private readonly angularCoreVersionMap = new WeakMap<ts.server.Project, Version>();
5452
private readonly ivy: boolean;
5553
private readonly configuredProjToExternalProj = new Map<string, string>();
5654
private readonly logToConsole: boolean;
@@ -322,7 +320,7 @@ export class Session {
322320
return params;
323321
}
324322

325-
private enableLanguageServiceForProject(project: ts.server.Project, angularCore: string) {
323+
private enableLanguageServiceForProject(project: ts.server.Project) {
326324
const {projectName} = project;
327325
if (!project.languageServiceEnabled) {
328326
project.enableLanguageService();
@@ -335,7 +333,6 @@ export class Session {
335333
if (!this.ivy) {
336334
// Immediately enable Legacy / View Engine language service
337335
this.info(`Enabling View Engine language service for ${projectName}.`);
338-
this.promptToEnableIvyIfAvailable(project, angularCore);
339336
return;
340337
}
341338
this.info(`Enabling Ivy language service for ${projectName}.`);
@@ -346,6 +343,15 @@ export class Session {
346343
this.runGlobalAnalysisForNewlyLoadedProject(project);
347344
}
348345

346+
private disableLanguageServiceForProject(project: ts.server.Project, reason: string) {
347+
if (!project.languageServiceEnabled) {
348+
return;
349+
}
350+
project.disableLanguageService(
351+
`Disabling language service for ${project.projectName} because ${reason}.`);
352+
}
353+
354+
349355
/**
350356
* Invoke the compiler for the first time so that external templates get
351357
* matched to the project they belong to.
@@ -405,14 +411,17 @@ export class Session {
405411
this.connection.sendNotification(ProjectLoadingFinish);
406412
}
407413
const {project} = event.data;
408-
const angularCore = this.findAngularCoreOrDisableLanguageService(project);
414+
const angularCore = this.findAngularCore(project);
409415
if (angularCore) {
410416
if (this.ivy && isExternalAngularCore(angularCore)) {
411417
// Do not wait on this promise otherwise we'll be blocking other requests
412-
this.runNgcc(project, angularCore);
418+
this.runNgcc(project);
413419
} else {
414-
this.enableLanguageServiceForProject(project, angularCore);
420+
this.enableLanguageServiceForProject(project);
415421
}
422+
} else {
423+
this.disableLanguageServiceForProject(
424+
project, `project is not an Angular project ('@angular/core' could not be found)`);
416425
}
417426
break;
418427
}
@@ -1051,12 +1060,11 @@ export class Session {
10511060

10521061
/**
10531062
* Find the main declaration file for `@angular/core` in the specified
1054-
* `project`. If found, return the declaration file. Otherwise, disable the
1055-
* language service and return undefined.
1063+
* `project`.
10561064
*
10571065
* @returns main declaration file in `@angular/core`.
10581066
*/
1059-
private findAngularCoreOrDisableLanguageService(project: ts.server.Project): string|undefined {
1067+
private findAngularCore(project: ts.server.Project): string|undefined {
10601068
const {projectName} = project;
10611069
if (!project.languageServiceEnabled) {
10621070
this.info(
@@ -1070,28 +1078,22 @@ export class Session {
10701078
return undefined;
10711079
}
10721080
const angularCore = project.getFileNames().find(isAngularCore);
1073-
if (angularCore === undefined) {
1074-
project.disableLanguageService();
1081+
if (angularCore === undefined && project.getExcludedFiles().some(isAngularCore)) {
10751082
this.info(
1076-
`Disabling language service for ${projectName} because it is not an Angular project ` +
1077-
`('@angular/core' could not be found).`);
1078-
if (project.getExcludedFiles().some(isAngularCore)) {
1079-
this.info(
1080-
`Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.`);
1081-
}
1083+
`Please check your tsconfig.json to make sure 'node_modules' directory is not excluded.`);
10821084
}
10831085
return angularCore;
10841086
}
10851087

10861088
/**
10871089
* Disable the language service, run ngcc, then re-enable language service.
10881090
*/
1089-
private async runNgcc(project: ts.server.Project, angularCore: string): Promise<void> {
1091+
private async runNgcc(project: ts.server.Project): Promise<void> {
10901092
if (!isConfiguredProject(project)) {
10911093
return;
10921094
}
10931095
// Disable language service until ngcc is completed.
1094-
project.disableLanguageService();
1096+
this.disableLanguageServiceForProject(project, 'ngcc is running');
10951097
const configFilePath = project.getConfigFilePath();
10961098

10971099
this.connection.sendProgress(NgccProgressType, NgccProgressToken, {
@@ -1131,21 +1133,7 @@ export class Session {
11311133
// disabled, there's no way users could use the extension even after
11321134
// resolving ngcc issues. On the client side, we will warn users about
11331135
// potentially degraded experience.
1134-
this.enableLanguageServiceForProject(project, angularCore);
1135-
}
1136-
1137-
private promptToEnableIvyIfAvailable(project: ts.server.Project, coreDts: string): void {
1138-
let angularCoreVersion = this.angularCoreVersionMap.get(project);
1139-
if (angularCoreVersion === undefined) {
1140-
angularCoreVersion = resolve('@angular/core', coreDts)?.version;
1141-
}
1142-
1143-
if (angularCoreVersion !== undefined && !this.ivy && angularCoreVersion.major >= 9) {
1144-
this.connection.sendNotification(SuggestIvyLanguageService, {
1145-
message:
1146-
'Would you like to enable the new Ivy-native language service to get the latest features and bug fixes?',
1147-
});
1148-
}
1136+
this.enableLanguageServiceForProject(project);
11491137
}
11501138
}
11511139

0 commit comments

Comments
 (0)