Skip to content

Commit 9f6d76c

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 406dac9 commit 9f6d76c

File tree

13 files changed

+8
-436
lines changed

13 files changed

+8
-436
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 & 20 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,20 +438,11 @@ function constructArgs(
448438
args.push('--includeCompletionsWithSnippetText');
449439
}
450440

451-
const disableAutomaticNgcc = config.get<boolean>('angular.disableAutomaticNgcc');
452-
if (disableAutomaticNgcc) {
453-
args.push('--disableAutomaticNgcc');
454-
}
455-
456441
const forceStrictTemplates = config.get<boolean>('angular.forceStrictTemplates');
457442
if (forceStrictTemplates) {
458443
args.push('--forceStrictTemplates');
459444
}
460445

461-
if (!isTrustedWorkspace) {
462-
args.push('--untrustedWorkspace');
463-
}
464-
465446
const tsdk: string|null = config.get('typescript.tsdk', null);
466447
const tsProbeLocations = [tsdk, ...getProbeLocations(ctx.extensionPath)];
467448
args.push('--tsProbeLocations', tsProbeLocations.join(','));

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: 1 addition & 80 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,28 +41,8 @@ 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);
65-
expect(languageServiceEnabled).toBeTrue();
6646
const response = await client.sendRequest(lsp.HoverRequest.type, {
6747
textDocument: {
6848
uri: APP_COMPONENT_URI,
@@ -77,8 +57,6 @@ describe('Angular Ivy language server', () => {
7757

7858
it('should show diagnostics for inline template on open', async () => {
7959
openTextDocument(client, APP_COMPONENT);
80-
const languageServiceEnabled = await waitForNgcc(client);
81-
expect(languageServiceEnabled).toBeTrue();
8260
const diagnostics = await getDiagnosticsForFile(client, APP_COMPONENT);
8361
expect(diagnostics.length).toBe(0);
8462
});
@@ -92,8 +70,6 @@ describe('Angular Ivy language server', () => {
9270
text: `{{ doesnotexist }}`,
9371
},
9472
});
95-
const languageServiceEnabled = await waitForNgcc(client);
96-
expect(languageServiceEnabled).toBeTrue();
9773
const diagnostics = await getDiagnosticsForFile(client, FOO_TEMPLATE);
9874
expect(diagnostics.length).toBe(1);
9975
expect(diagnostics[0].message)
@@ -107,8 +83,6 @@ describe('Angular Ivy language server', () => {
10783

10884
it('should support request cancellation', async () => {
10985
openTextDocument(client, APP_COMPONENT);
110-
const languageServiceEnabled = await waitForNgcc(client);
111-
expect(languageServiceEnabled).toBeTrue();
11286
// Send a request and immediately cancel it
11387
const promise = client.sendRequest(lsp.HoverRequest.type, {
11488
textDocument: {
@@ -132,8 +106,6 @@ describe('Angular Ivy language server', () => {
132106
text: `<div *ngIf="false"></div>`,
133107
},
134108
});
135-
const languageServiceEnabled = await waitForNgcc(client);
136-
expect(languageServiceEnabled).toBeTrue();
137109
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
138110
textDocument: {
139111
uri: FOO_TEMPLATE_URI,
@@ -168,8 +140,6 @@ describe('Angular Ivy language server', () => {
168140
text: `<lib-post></lib-post>`,
169141
},
170142
});
171-
const languageServiceEnabled = await waitForNgcc(client);
172-
expect(languageServiceEnabled).toBeTrue();
173143
const response = await client.sendRequest(lsp.DefinitionRequest.type, {
174144
textDocument: {
175145
uri: FOO_TEMPLATE_URI,
@@ -199,8 +169,6 @@ export class AppComponent {
199169
@Input() appInput = '';
200170
@Output() appOutput = new EventEmitter<string>();
201171
}`);
202-
const languageServiceEnabled = await waitForNgcc(client);
203-
expect(languageServiceEnabled).toBeTrue();
204172
const response = await client.sendRequest(lsp.FoldingRangeRequest.type, {
205173
textDocument: {
206174
uri: APP_COMPONENT_URI,
@@ -223,8 +191,6 @@ export class AppComponent {
223191
text: `{{ title.toString() }}`,
224192
},
225193
});
226-
const languageServiceEnabled = await waitForNgcc(client);
227-
expect(languageServiceEnabled).toBeTrue();
228194
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
229195
textDocument: {
230196
uri: FOO_TEMPLATE_URI,
@@ -245,8 +211,6 @@ export class AppComponent {
245211
text: `{{ title.substr(0, ) }}`,
246212
},
247213
});
248-
const languageServiceEnabled = await waitForNgcc(client);
249-
expect(languageServiceEnabled).toBeTrue();
250214
const response = (await client.sendRequest(lsp.SignatureHelpRequest.type, {
251215
textDocument: {
252216
uri: FOO_TEMPLATE_URI,
@@ -278,8 +242,6 @@ export class AppComponent {
278242

279243
it('should retain typecheck files', async () => {
280244
openTextDocument(client, APP_COMPONENT);
281-
const languageServiceEnabled = await waitForNgcc(client);
282-
expect(languageServiceEnabled).toBeTrue();
283245
// Create a file in node_modules, this will trigger a project reload via
284246
// the directory watcher
285247
fs.writeFileSync(dummy, '');
@@ -296,8 +258,6 @@ export class AppComponent {
296258
describe('completions', () => {
297259
it('for events', async () => {
298260
openTextDocument(client, FOO_TEMPLATE, `<my-app ()></my-app>`);
299-
const languageServiceEnabled = await waitForNgcc(client);
300-
expect(languageServiceEnabled).toBeTrue();
301261
const response = await client.sendRequest(lsp.CompletionRequest.type, {
302262
textDocument: {
303263
uri: FOO_TEMPLATE_URI,
@@ -316,8 +276,6 @@ export class AppComponent {
316276
describe('from template files', () => {
317277
beforeEach(async () => {
318278
openTextDocument(client, FOO_TEMPLATE);
319-
const languageServiceEnabled = await waitForNgcc(client);
320-
expect(languageServiceEnabled).toBeTrue();
321279
});
322280

323281
it('should handle prepare rename request for property read', async () => {
@@ -368,8 +326,6 @@ export class AppComponent {
368326
describe('from typescript files', () => {
369327
beforeEach(async () => {
370328
openTextDocument(client, APP_COMPONENT);
371-
const languageServiceEnabled = await waitForNgcc(client);
372-
expect(languageServiceEnabled).toBeTrue();
373329
});
374330

375331
it('should handle prepare rename request for inline template property read', async () => {
@@ -455,8 +411,6 @@ export class AppComponent {
455411
fs.writeFileSync(TSCONFIG, JSON.stringify(config, null, 2));
456412

457413
openTextDocument(client, APP_COMPONENT);
458-
const languageServiceEnabled = await waitForNgcc(client);
459-
expect(languageServiceEnabled).toBeTrue();
460414
});
461415

462416
it('should suggest strict mode', async () => {
@@ -489,7 +443,6 @@ export class AppComponent {
489443

490444
it('should handle getTcb request', async () => {
491445
openTextDocument(client, FOO_TEMPLATE);
492-
await waitForNgcc(client);
493446
const response = await client.sendRequest(GetTcbRequest, {
494447
textDocument: {
495448
uri: FOO_TEMPLATE_URI,
@@ -501,7 +454,6 @@ export class AppComponent {
501454

502455
it('should handle goToComponent request', async () => {
503456
openTextDocument(client, FOO_TEMPLATE);
504-
await waitForNgcc(client);
505457
const response = await client.sendRequest(GetComponentsWithTemplateFile, {
506458
textDocument: {
507459
uri: FOO_TEMPLATE_URI,
@@ -512,7 +464,6 @@ export class AppComponent {
512464

513465
it('should handle GetTemplateLocationForComponent request', async () => {
514466
openTextDocument(client, FOO_TEMPLATE);
515-
await waitForNgcc(client);
516467
const response = await client.sendRequest(GetTemplateLocationForComponent, {
517468
textDocument: {
518469
uri: FOO_COMPONENT_URI,
@@ -525,7 +476,6 @@ export class AppComponent {
525476

526477
it('should handle GetTemplateLocationForComponent request when not in component', async () => {
527478
openTextDocument(client, FOO_TEMPLATE);
528-
await waitForNgcc(client);
529479
const response = await client.sendRequest(GetTemplateLocationForComponent, {
530480
textDocument: {
531481
uri: FOO_COMPONENT_URI,
@@ -537,7 +487,6 @@ export class AppComponent {
537487

538488
it('should provide a "go to component" codelens', async () => {
539489
openTextDocument(client, FOO_TEMPLATE);
540-
await waitForNgcc(client);
541490
const codeLensResponse = await client.sendRequest(lsp.CodeLensRequest.type, {
542491
textDocument: {
543492
uri: FOO_TEMPLATE_URI,
@@ -555,7 +504,6 @@ export class AppComponent {
555504

556505
it('detects an Angular project', async () => {
557506
openTextDocument(client, FOO_TEMPLATE);
558-
await waitForNgcc(client);
559507
const templateResponse = await client.sendRequest(IsInAngularProject, {
560508
textDocument: {
561509
uri: FOO_TEMPLATE_URI,
@@ -603,8 +551,6 @@ describe('auto-apply optional chaining', () => {
603551
}
604552
`);
605553
openTextDocument(client, FOO_TEMPLATE, `{{ person.n }}`);
606-
const languageServiceEnabled = await waitForNgcc(client);
607-
expect(languageServiceEnabled).toBeTrue();
608554
const response = await client.sendRequest(lsp.CompletionRequest.type, {
609555
textDocument: {
610556
uri: FOO_TEMPLATE_URI,
@@ -618,8 +564,6 @@ describe('auto-apply optional chaining', () => {
618564

619565
it('should work on NonNullable symbol', async () => {
620566
openTextDocument(client, FOO_TEMPLATE, `{{ title.substr }}`);
621-
const languageServiceEnabled = await waitForNgcc(client);
622-
expect(languageServiceEnabled).toBeTrue();
623567
const response = await client.sendRequest(lsp.CompletionRequest.type, {
624568
textDocument: {
625569
uri: FOO_TEMPLATE_URI,
@@ -655,8 +599,6 @@ describe('insert snippet text', () => {
655599

656600
it('should be able to complete for an attribute with the value is empty', async () => {
657601
openTextDocument(client, FOO_TEMPLATE, `<my-app appOut></my-app>`);
658-
const languageServiceEnabled = await waitForNgcc(client);
659-
expect(languageServiceEnabled).toBeTrue();
660602
const response = await client.sendRequest(lsp.CompletionRequest.type, {
661603
textDocument: {
662604
uri: FOO_TEMPLATE_URI,
@@ -671,8 +613,6 @@ describe('insert snippet text', () => {
671613

672614
it('should not be included in the completion for an attribute with a value', async () => {
673615
openTextDocument(client, FOO_TEMPLATE, `<my-app [appInput]="1"></my-app>`);
674-
const languageServiceEnabled = await waitForNgcc(client);
675-
expect(languageServiceEnabled).toBeTrue();
676616
const response = await client.sendRequest(lsp.CompletionRequest.type, {
677617
textDocument: {
678618
uri: FOO_TEMPLATE_URI,
@@ -709,8 +649,6 @@ describe('code fixes', () => {
709649

710650
it('should fix error when property does not exist on type', async () => {
711651
openTextDocument(client, FOO_TEMPLATE, `{{titl}}`);
712-
const languageServiceEnabled = await waitForNgcc(client);
713-
expect(languageServiceEnabled).toBeTrue();
714652
const diags = await getDiagnosticsForFile(client, FOO_TEMPLATE);
715653
const codeActions = await client.sendRequest(lsp.CodeActionRequest.type, {
716654
textDocument: {
@@ -735,8 +673,6 @@ describe('code fixes', () => {
735673
it('should fix error when the range the user selects is larger than the diagnostic', async () => {
736674
const template = `<span>{{titl}}</span>`;
737675
openTextDocument(client, FOO_TEMPLATE, template);
738-
const languageServiceEnabled = await waitForNgcc(client);
739-
expect(languageServiceEnabled).toBeTrue();
740676
const diags = await getDiagnosticsForFile(client, FOO_TEMPLATE);
741677
const codeActions = await client.sendRequest(lsp.CodeActionRequest.type, {
742678
textDocument: {
@@ -771,8 +707,6 @@ describe('code fixes', () => {
771707
banner = '';
772708
}
773709
`);
774-
const languageServiceEnabled = await waitForNgcc(client);
775-
expect(languageServiceEnabled).toBeTrue();
776710
});
777711

778712
it('for "fixSpelling"', async () => {
@@ -838,14 +772,6 @@ describe('code fixes', () => {
838772
});
839773
});
840774

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-
849775
function onSuggestStrictMode(client: MessageConnection): Promise<string> {
850776
return new Promise(resolve => {
851777
client.onNotification(SuggestStrictMode, (params: SuggestStrictModeParams) => {
@@ -873,8 +799,3 @@ function getDiagnosticsForFile(
873799
});
874800
});
875801
}
876-
877-
async function waitForNgcc(client: MessageConnection): Promise<boolean> {
878-
await onNgccProgress(client);
879-
return onLanguageServiceStateNotification(client);
880-
}

0 commit comments

Comments
 (0)