Skip to content

Commit fc03b58

Browse files
committed
refactor: Remove ngcc from extension
NGCC is being removed in Angular v16. The language service should not longer attempt to run it. angular/angular-cli#24720 As a result, we can now set the support for running in untrusted workspaces to "true" since we don't have to execute ngcc from the `node_modules` folder.
1 parent 86292ea commit fc03b58

File tree

13 files changed

+36
-400
lines changed

13 files changed

+36
-400
lines changed

.github/workflows/node.js.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
node-version: 14.x
2424
- run: yarn install
2525
- run: yarn install --cwd integration/project
26-
- run: cd integration/project && yarn ngcc
26+
- run: cd integration/project
2727
- run: scripts/build.sh package.json
2828
- run: xvfb-run -a yarn run test:e2e
2929
if: runner.os == 'Linux'

client/src/client.ts

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

1414
import {OpenOutputChannel, ProjectLoadingFinish, ProjectLoadingStart, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
15-
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject, RunNgccRequest} from '../../common/requests';
15+
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject} from '../../common/requests';
1616
import {resolve, Version} from '../../common/resolver';
1717

1818
import {isInsideComponentDecorator, isInsideInlineTemplateRegion, isInsideStringLiteral} from './embedded_support';
@@ -281,16 +281,6 @@ export class AngularLanguageClient implements vscode.Disposable {
281281
};
282282
}
283283

284-
runNgcc(textEditor: vscode.TextEditor): void {
285-
if (this.client === null) {
286-
return;
287-
}
288-
this.client.sendRequest(RunNgccRequest, {
289-
textDocument:
290-
this.client.code2ProtocolConverter.asTextDocumentIdentifier(textEditor.document),
291-
});
292-
}
293-
294284
get initializeResult(): lsp.InitializeResult|undefined {
295285
return this.client?.initializeResult;
296286
}
@@ -448,10 +438,6 @@ function constructArgs(
448438
args.push('--includeCompletionsWithSnippetText');
449439
}
450440

451-
const disableAutomaticNgcc = config.get<boolean>('angular.disableAutomaticNgcc');
452-
if (disableAutomaticNgcc) {
453-
args.push('--disableAutomaticNgcc');
454-
}
455441
const disableCodeActions = config.get<boolean>('angular.disableCodeActions');
456442
if (disableCodeActions) {
457443
args.push('--disableCodeActions');

client/src/commands.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ function getTemplateTcb(
115115
}
116116
};
117117
}
118-
function runNgcc(ngClient: AngularLanguageClient): Command {
119-
return {
120-
id: 'angular.runNgcc',
121-
isTextEditorCommand: true,
122-
async execute(textEditor: vscode.TextEditor) {
123-
ngClient.runNgcc(textEditor);
124-
}
125-
};
126-
}
127118

128119
/**
129120
* Command goToComponentWithTemplateFile finds components which reference an external template in
@@ -189,7 +180,6 @@ export function registerCommands(
189180
restartNgServer(client),
190181
openLogFile(client),
191182
getTemplateTcb(client, context),
192-
runNgcc(client),
193183
goToComponentWithTemplateFile(client),
194184
goToTemplateForComponent(client),
195185
];

common/notifications.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,4 @@ export interface SuggestStrictModeParams {
2727
export const SuggestStrictMode =
2828
new NotificationType<SuggestStrictModeParams>('angular/suggestStrictMode');
2929

30-
// Report the end of `NGCC` progress and Only used by the `ivy_spec.ts`.
31-
export const NgccProgressEnd =
32-
new NotificationType<{configFilePath: string}>('angular/NgccProgressEnd');
33-
3430
export const OpenOutputChannel = new NotificationType('angular/OpenOutputChannel');

common/requests.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,9 @@ export interface GetTcbParams {
3030
position: lsp.Position;
3131
}
3232

33-
export interface RunNgccParams {
34-
textDocument: lsp.TextDocumentIdentifier;
35-
}
36-
3733
export const GetTcbRequest =
3834
new lsp.RequestType<GetTcbParams, GetTcbResponse|null, /* error */ void>('angular/getTcb');
3935

40-
export const RunNgccRequest =
41-
new lsp.RequestType<RunNgccParams, void, /* error */ void>('angular/runNgcc');
42-
4336
export interface GetTcbResponse {
4437
uri: lsp.DocumentUri;
4538
content: string;

integration/lsp/ivy_spec.ts

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {MessageConnection} from 'vscode-jsonrpc';
1212
import * as lsp from 'vscode-languageserver-protocol';
1313
import {URI} from 'vscode-uri';
1414

15-
import {NgccProgressEnd, ProjectLanguageService, ProjectLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
15+
import {ProjectLanguageService, ProjectLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
1616
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject} from '../../common/requests';
1717
import {APP_COMPONENT, APP_COMPONENT_URI, FOO_COMPONENT, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, IS_BAZEL, PROJECT_PATH, TSCONFIG} from '../test_constants';
1818

@@ -41,27 +41,9 @@ describe('Angular Ivy language server', () => {
4141
client.dispose();
4242
});
4343

44-
it('should send ngcc progress after a project has finished loading', async () => {
45-
openTextDocument(client, APP_COMPONENT);
46-
const configFilePath = await onNgccProgress(client);
47-
expect(configFilePath.endsWith('integration/project/tsconfig.json')).toBeTrue();
48-
});
49-
50-
it('should disable language service until ngcc has completed', async () => {
51-
openTextDocument(client, APP_COMPONENT);
52-
const languageServiceEnabled = await onLanguageServiceStateNotification(client);
53-
expect(languageServiceEnabled).toBeFalse();
54-
});
55-
56-
it('should re-enable language service once ngcc has completed', async () => {
57-
openTextDocument(client, APP_COMPONENT);
58-
const languageServiceEnabled = await waitForNgcc(client);
59-
expect(languageServiceEnabled).toBeTrue();
60-
});
61-
6244
it('should handle hover on inline template', async () => {
6345
openTextDocument(client, APP_COMPONENT);
64-
const languageServiceEnabled = await waitForNgcc(client);
46+
const languageServiceEnabled = await waitForLanguageService(client);
6547
expect(languageServiceEnabled).toBeTrue();
6648
const response = await client.sendRequest(lsp.HoverRequest.type, {
6749
textDocument: {
@@ -77,7 +59,7 @@ describe('Angular Ivy language server', () => {
7759

7860
it('should show diagnostics for inline template on open', async () => {
7961
openTextDocument(client, APP_COMPONENT);
80-
const languageServiceEnabled = await waitForNgcc(client);
62+
const languageServiceEnabled = await waitForLanguageService(client);
8163
expect(languageServiceEnabled).toBeTrue();
8264
const diagnostics = await getDiagnosticsForFile(client, APP_COMPONENT);
8365
expect(diagnostics.length).toBe(0);
@@ -92,7 +74,7 @@ describe('Angular Ivy language server', () => {
9274
text: `{{ doesnotexist }}`,
9375
},
9476
});
95-
const languageServiceEnabled = await waitForNgcc(client);
77+
const languageServiceEnabled = await waitForLanguageService(client);
9678
expect(languageServiceEnabled).toBeTrue();
9779
const diagnostics = await getDiagnosticsForFile(client, FOO_TEMPLATE);
9880
expect(diagnostics.length).toBe(1);
@@ -107,7 +89,7 @@ describe('Angular Ivy language server', () => {
10789

10890
it('should support request cancellation', async () => {
10991
openTextDocument(client, APP_COMPONENT);
110-
const languageServiceEnabled = await waitForNgcc(client);
92+
const languageServiceEnabled = await waitForLanguageService(client);
11193
expect(languageServiceEnabled).toBeTrue();
11294
// Send a request and immediately cancel it
11395
const promise = client.sendRequest(lsp.HoverRequest.type, {
@@ -132,7 +114,7 @@ describe('Angular Ivy language server', () => {
132114
text: `<div *ngIf="false"></div>`,
133115
},
134116
});
135-
const languageServiceEnabled = await waitForNgcc(client);
117+
const languageServiceEnabled = await waitForLanguageService(client);
136118
expect(languageServiceEnabled).toBeTrue();
137119
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
138120
textDocument: {
@@ -168,7 +150,7 @@ describe('Angular Ivy language server', () => {
168150
text: `<lib-post></lib-post>`,
169151
},
170152
});
171-
const languageServiceEnabled = await waitForNgcc(client);
153+
const languageServiceEnabled = await waitForLanguageService(client);
172154
expect(languageServiceEnabled).toBeTrue();
173155
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
174156
textDocument: {
@@ -199,7 +181,7 @@ export class AppComponent {
199181
@Input() appInput = '';
200182
@Output() appOutput = new EventEmitter<string>();
201183
}`);
202-
const languageServiceEnabled = await waitForNgcc(client);
184+
const languageServiceEnabled = await waitForLanguageService(client);
203185
expect(languageServiceEnabled).toBeTrue();
204186
const response = await client.sendRequest(lsp.FoldingRangeRequest.type, {
205187
textDocument: {
@@ -223,7 +205,7 @@ export class AppComponent {
223205
text: `{{ title.toString() }}`,
224206
},
225207
});
226-
const languageServiceEnabled = await waitForNgcc(client);
208+
const languageServiceEnabled = await waitForLanguageService(client);
227209
expect(languageServiceEnabled).toBeTrue();
228210
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
229211
textDocument: {
@@ -245,7 +227,7 @@ export class AppComponent {
245227
text: `{{ title.substr(0, ) }}`,
246228
},
247229
});
248-
const languageServiceEnabled = await waitForNgcc(client);
230+
const languageServiceEnabled = await waitForLanguageService(client);
249231
expect(languageServiceEnabled).toBeTrue();
250232
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
251233
textDocument: {
@@ -278,7 +260,7 @@ export class AppComponent {
278260

279261
it('should retain typecheck files', async () => {
280262
openTextDocument(client, APP_COMPONENT);
281-
const languageServiceEnabled = await waitForNgcc(client);
263+
const languageServiceEnabled = await waitForLanguageService(client);
282264
expect(languageServiceEnabled).toBeTrue();
283265
// Create a file in node_modules, this will trigger a project reload via
284266
// the directory watcher
@@ -296,7 +278,7 @@ export class AppComponent {
296278
describe('completions', () => {
297279
it('for events', async () => {
298280
openTextDocument(client, FOO_TEMPLATE, `<my-app ()></my-app>`);
299-
const languageServiceEnabled = await waitForNgcc(client);
281+
const languageServiceEnabled = await waitForLanguageService(client);
300282
expect(languageServiceEnabled).toBeTrue();
301283
const response = await client.sendRequest(lsp.CompletionRequest.type, {
302284
textDocument: {
@@ -316,7 +298,7 @@ export class AppComponent {
316298
describe('from template files', () => {
317299
beforeEach(async () => {
318300
openTextDocument(client, FOO_TEMPLATE);
319-
const languageServiceEnabled = await waitForNgcc(client);
301+
const languageServiceEnabled = await waitForLanguageService(client);
320302
expect(languageServiceEnabled).toBeTrue();
321303
});
322304

@@ -368,7 +350,7 @@ export class AppComponent {
368350
describe('from typescript files', () => {
369351
beforeEach(async () => {
370352
openTextDocument(client, APP_COMPONENT);
371-
const languageServiceEnabled = await waitForNgcc(client);
353+
const languageServiceEnabled = await waitForLanguageService(client);
372354
expect(languageServiceEnabled).toBeTrue();
373355
});
374356

@@ -455,7 +437,7 @@ export class AppComponent {
455437
fs.writeFileSync(TSCONFIG, JSON.stringify(config, null, 2));
456438

457439
openTextDocument(client, APP_COMPONENT);
458-
const languageServiceEnabled = await waitForNgcc(client);
440+
const languageServiceEnabled = await waitForLanguageService(client);
459441
expect(languageServiceEnabled).toBeTrue();
460442
});
461443

@@ -489,7 +471,7 @@ export class AppComponent {
489471

490472
it('should handle getTcb request', async () => {
491473
openTextDocument(client, FOO_TEMPLATE);
492-
await waitForNgcc(client);
474+
await waitForLanguageService(client);
493475
const response = await client.sendRequest(GetTcbRequest, {
494476
textDocument: {
495477
uri: FOO_TEMPLATE_URI,
@@ -501,7 +483,7 @@ export class AppComponent {
501483

502484
it('should handle goToComponent request', async () => {
503485
openTextDocument(client, FOO_TEMPLATE);
504-
await waitForNgcc(client);
486+
await waitForLanguageService(client);
505487
const response = await client.sendRequest(GetComponentsWithTemplateFile, {
506488
textDocument: {
507489
uri: FOO_TEMPLATE_URI,
@@ -512,7 +494,7 @@ export class AppComponent {
512494

513495
it('should handle GetTemplateLocationForComponent request', async () => {
514496
openTextDocument(client, FOO_TEMPLATE);
515-
await waitForNgcc(client);
497+
await waitForLanguageService(client);
516498
const response = await client.sendRequest(GetTemplateLocationForComponent, {
517499
textDocument: {
518500
uri: FOO_COMPONENT_URI,
@@ -525,7 +507,7 @@ export class AppComponent {
525507

526508
it('should handle GetTemplateLocationForComponent request when not in component', async () => {
527509
openTextDocument(client, FOO_TEMPLATE);
528-
await waitForNgcc(client);
510+
await waitForLanguageService(client);
529511
const response = await client.sendRequest(GetTemplateLocationForComponent, {
530512
textDocument: {
531513
uri: FOO_COMPONENT_URI,
@@ -537,7 +519,7 @@ export class AppComponent {
537519

538520
it('should provide a "go to component" codelens', async () => {
539521
openTextDocument(client, FOO_TEMPLATE);
540-
await waitForNgcc(client);
522+
await waitForLanguageService(client);
541523
const codeLensResponse = await client.sendRequest(lsp.CodeLensRequest.type, {
542524
textDocument: {
543525
uri: FOO_TEMPLATE_URI,
@@ -555,7 +537,7 @@ export class AppComponent {
555537

556538
it('detects an Angular project', async () => {
557539
openTextDocument(client, FOO_TEMPLATE);
558-
await waitForNgcc(client);
540+
await waitForLanguageService(client);
559541
const templateResponse = await client.sendRequest(IsInAngularProject, {
560542
textDocument: {
561543
uri: FOO_TEMPLATE_URI,
@@ -603,7 +585,7 @@ describe('auto-apply optional chaining', () => {
603585
}
604586
`);
605587
openTextDocument(client, FOO_TEMPLATE, `{{ person.n }}`);
606-
const languageServiceEnabled = await waitForNgcc(client);
588+
const languageServiceEnabled = await waitForLanguageService(client);
607589
expect(languageServiceEnabled).toBeTrue();
608590
const response = await client.sendRequest(lsp.CompletionRequest.type, {
609591
textDocument: {
@@ -618,7 +600,7 @@ describe('auto-apply optional chaining', () => {
618600

619601
it('should work on NonNullable symbol', async () => {
620602
openTextDocument(client, FOO_TEMPLATE, `{{ title.substr }}`);
621-
const languageServiceEnabled = await waitForNgcc(client);
603+
const languageServiceEnabled = await waitForLanguageService(client);
622604
expect(languageServiceEnabled).toBeTrue();
623605
const response = await client.sendRequest(lsp.CompletionRequest.type, {
624606
textDocument: {
@@ -655,7 +637,7 @@ describe('insert snippet text', () => {
655637

656638
it('should be able to complete for an attribute with the value is empty', async () => {
657639
openTextDocument(client, FOO_TEMPLATE, `<my-app appOut></my-app>`);
658-
const languageServiceEnabled = await waitForNgcc(client);
640+
const languageServiceEnabled = await waitForLanguageService(client);
659641
expect(languageServiceEnabled).toBeTrue();
660642
const response = await client.sendRequest(lsp.CompletionRequest.type, {
661643
textDocument: {
@@ -671,7 +653,7 @@ describe('insert snippet text', () => {
671653

672654
it('should not be included in the completion for an attribute with a value', async () => {
673655
openTextDocument(client, FOO_TEMPLATE, `<my-app [appInput]="1"></my-app>`);
674-
const languageServiceEnabled = await waitForNgcc(client);
656+
const languageServiceEnabled = await waitForLanguageService(client);
675657
expect(languageServiceEnabled).toBeTrue();
676658
const response = await client.sendRequest(lsp.CompletionRequest.type, {
677659
textDocument: {
@@ -709,7 +691,7 @@ describe('code fixes', () => {
709691

710692
it('should fix error when property does not exist on type', async () => {
711693
openTextDocument(client, FOO_TEMPLATE, `{{titl}}`);
712-
const languageServiceEnabled = await waitForNgcc(client);
694+
const languageServiceEnabled = await waitForLanguageService(client);
713695
expect(languageServiceEnabled).toBeTrue();
714696
const diags = await getDiagnosticsForFile(client, FOO_TEMPLATE);
715697
const codeActions = await client.sendRequest(lsp.CodeActionRequest.type, {
@@ -735,7 +717,7 @@ describe('code fixes', () => {
735717
it('should fix error when the range the user selects is larger than the diagnostic', async () => {
736718
const template = `<span>{{titl}}</span>`;
737719
openTextDocument(client, FOO_TEMPLATE, template);
738-
const languageServiceEnabled = await waitForNgcc(client);
720+
const languageServiceEnabled = await waitForLanguageService(client);
739721
expect(languageServiceEnabled).toBeTrue();
740722
const diags = await getDiagnosticsForFile(client, FOO_TEMPLATE);
741723
const codeActions = await client.sendRequest(lsp.CodeActionRequest.type, {
@@ -771,7 +753,7 @@ describe('code fixes', () => {
771753
banner = '';
772754
}
773755
`);
774-
const languageServiceEnabled = await waitForNgcc(client);
756+
const languageServiceEnabled = await waitForLanguageService(client);
775757
expect(languageServiceEnabled).toBeTrue();
776758
});
777759

@@ -838,14 +820,6 @@ describe('code fixes', () => {
838820
});
839821
});
840822

841-
function onNgccProgress(client: MessageConnection): Promise<string> {
842-
return new Promise(resolve => {
843-
client.onNotification(NgccProgressEnd, (params) => {
844-
resolve(params.configFilePath);
845-
});
846-
});
847-
}
848-
849823
function onSuggestStrictMode(client: MessageConnection): Promise<string> {
850824
return new Promise(resolve => {
851825
client.onNotification(SuggestStrictMode, (params: SuggestStrictModeParams) => {
@@ -874,7 +848,6 @@ function getDiagnosticsForFile(
874848
});
875849
}
876850

877-
async function waitForNgcc(client: MessageConnection): Promise<boolean> {
878-
await onNgccProgress(client);
851+
async function waitForLanguageService(client: MessageConnection): Promise<boolean> {
879852
return onLanguageServiceStateNotification(client);
880853
}

0 commit comments

Comments
 (0)