Skip to content

Commit fbc9e2b

Browse files
authored
feat: Add option to disable ngcc (#1620)
Running ngcc is required for gathering metadata information of libraries not published with Ivy instructions. However, ngcc can also be run manually _outside_ of the extension. Developers may often be running a dev server which does this step so doing it in the extension as well is redundant. In addition, there have been issues with running it in VSCode (#1353, #1444, and potentially other Nx related issues). This option gives developers the ability to manually opt out of running ngcc from the extension if it is proving to be problematic for their setup. Fixes #1353
1 parent 5157872 commit fbc9e2b

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

client/src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ function constructArgs(ctx: vscode.ExtensionContext, viewEngine: boolean): strin
410410
args.push('--includeCompletionsWithSnippetText');
411411
}
412412

413+
const disableNgcc = config.get<boolean>('angular.disableNgcc');
414+
if (disableNgcc) {
415+
args.push('--disableNgcc');
416+
}
417+
413418
const tsdk: string|null = config.get('typescript.tsdk', null);
414419
const tsProbeLocations = [tsdk, ...getProbeLocations(ctx.extensionPath)];
415420
args.push('--tsProbeLocations', tsProbeLocations.join(','));

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
"type": "boolean",
124124
"default": true,
125125
"markdownDescription": "Enable/disable snippet completions from Angular language server. Requires using TypeScript 4.3+ in the workspace and the `legacy View Engine` option to be disabled."
126+
},
127+
"angular.disableNgcc": {
128+
"type": "boolean",
129+
"default": false,
130+
"markdownDescription": "Manually disable the step to run ngcc. [ngcc](https://github.com/angular/angular/blob/master/packages/compiler/design/architecture.md#high-level-proposal) is required to run and gather metadata from libraries not published with Ivy instructions. This can be run outside of VSCode instead (for example, as part of the build/rebuild in the CLI). Note that ngcc needs to run not only at startup, but also whenever the dependencies change. Failing to run ngcc when required can result in incomplete information and spurious errors reported by the language service."
126131
}
127132
}
128133
},
@@ -223,4 +228,4 @@
223228
"type": "git",
224229
"url": "https://github.com/angular/vscode-ng-language-service"
225230
}
226-
}
231+
}

server/src/cmdline_utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ interface CommandLineOptions {
3232
* If true, use Ivy LS, otherwise use legacy View Engine LS.
3333
*/
3434
ivy: boolean;
35+
/**
36+
* If true, skips the running ngcc when using Ivy LS.
37+
*/
38+
disableNgcc: boolean;
3539
logFile?: string;
3640
logVerbosity?: string;
3741
logToConsole: boolean;
@@ -45,6 +49,7 @@ export function parseCommandLine(argv: string[]): CommandLineOptions {
4549
return {
4650
help: hasArgument(argv, '--help'),
4751
ivy: !hasArgument(argv, '--viewEngine'),
52+
disableNgcc: hasArgument(argv, '--disableNgcc'),
4853
logFile: findArgument(argv, '--logFile'),
4954
logVerbosity: findArgument(argv, '--logVerbosity'),
5055
logToConsole: hasArgument(argv, '--logToConsole'),

server/src/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function main() {
4343
ngPlugin: '@angular/language-service',
4444
resolvedNgLsPath: ng.resolvedPath,
4545
ivy: isG3 ? true : options.ivy,
46+
disableNgcc: options.disableNgcc,
4647
logToConsole: options.logToConsole,
4748
includeAutomaticOptionalChainCompletions: options.includeAutomaticOptionalChainCompletions,
4849
includeCompletionsWithSnippetText: options.includeCompletionsWithSnippetText,

server/src/session.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface SessionOptions {
2727
ngPlugin: string;
2828
resolvedNgLsPath: string;
2929
ivy: boolean;
30+
disableNgcc: boolean;
3031
logToConsole: boolean;
3132
includeAutomaticOptionalChainCompletions: boolean;
3233
includeCompletionsWithSnippetText: boolean;
@@ -54,6 +55,7 @@ export class Session {
5455
private readonly projectService: ts.server.ProjectService;
5556
private readonly logger: ts.server.Logger;
5657
private readonly ivy: boolean;
58+
private readonly disableNgcc: boolean;
5759
private readonly configuredProjToExternalProj = new Map<string, string>();
5860
private readonly logToConsole: boolean;
5961
private readonly openFiles = new MruTracker();
@@ -80,6 +82,7 @@ export class Session {
8082
this.includeCompletionsWithSnippetText = options.includeCompletionsWithSnippetText;
8183
this.logger = options.logger;
8284
this.ivy = options.ivy;
85+
this.disableNgcc = options.disableNgcc;
8386
this.logToConsole = options.logToConsole;
8487
// Create a connection for the server. The connection uses Node's IPC as a transport.
8588
this.connection = lsp.createConnection({
@@ -457,7 +460,7 @@ export class Session {
457460
const {project} = event.data;
458461
const angularCore = this.findAngularCore(project);
459462
if (angularCore) {
460-
if (this.ivy && isExternalAngularCore(angularCore)) {
463+
if (this.ivy && isExternalAngularCore(angularCore) && !this.disableNgcc) {
461464
// Do not wait on this promise otherwise we'll be blocking other requests
462465
this.runNgcc(project);
463466
} else {

0 commit comments

Comments
 (0)