Skip to content

refactor: Remove ngcc from extension #1862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
v12_language_service/node_modules
dist/
integration/pre_apf_project/node_modules/
integration/project/node_modules/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
node-version: 14.x
- run: yarn install
- run: yarn install --cwd integration/project
- run: cd integration/project && yarn ngcc
- run: cd integration/project
- run: scripts/build.sh package.json
- run: xvfb-run -a yarn run test:e2e
if: runner.os == 'Linux'
Expand Down
1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ npm_package(
"//client:index.js",
"//server:npm_files",
"//syntaxes:npm_files",
"//v12_language_service:npm_files",
# Transitive closure of npm deps needed for vsce; this set was determined manually by
# running `bazel build //:vsix` and burning down missing packages. We do this so that we
# don't have to run an additional `npm install` action to create a node_modules within the
Expand Down
1 change: 0 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ npm_translate_lock(
npmrc = "//:.npmrc",
data = [
"//:pnpm-workspace.yaml",
"//v12_language_service:package.json",
# PLACE_HOLDER_FOR_angular/angular_packages/language-service/build.sh
],
verify_node_modules_ignored = "//:.bazelignore",
Expand Down
81 changes: 5 additions & 76 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as vscode from 'vscode';
import * as lsp from 'vscode-languageclient/node';

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

import {isInsideComponentDecorator, isInsideInlineTemplateRegion, isInsideStringLiteral} from './embedded_support';
Expand Down Expand Up @@ -281,16 +281,6 @@ export class AngularLanguageClient implements vscode.Disposable {
};
}

runNgcc(textEditor: vscode.TextEditor): void {
if (this.client === null) {
return;
}
this.client.sendRequest(RunNgccRequest, {
textDocument:
this.client.code2ProtocolConverter.asTextDocumentIdentifier(textEditor.document),
});
}

get initializeResult(): lsp.InitializeResult|undefined {
return this.client?.initializeResult;
}
Expand Down Expand Up @@ -412,8 +402,7 @@ function getProbeLocations(bundled: string): string[] {
* Construct the arguments that's used to spawn the server process.
* @param ctx vscode extension context
*/
function constructArgs(
ctx: vscode.ExtensionContext, viewEngine: boolean, isTrustedWorkspace: boolean): string[] {
function constructArgs(ctx: vscode.ExtensionContext, isTrustedWorkspace: boolean): string[] {
const config = vscode.workspace.getConfiguration();
const args: string[] = ['--logToConsole'];

Expand All @@ -426,15 +415,7 @@ function constructArgs(
}

const ngProbeLocations = getProbeLocations(ctx.extensionPath);
if (viewEngine) {
args.push('--viewEngine');
args.push('--ngProbeLocations', [
path.join(ctx.extensionPath, 'v12_language_service'),
...ngProbeLocations,
].join(','));
} else {
args.push('--ngProbeLocations', ngProbeLocations.join(','));
}
args.push('--ngProbeLocations', ngProbeLocations.join(','));

const includeAutomaticOptionalChainCompletions =
config.get<boolean>('angular.suggest.includeAutomaticOptionalChainCompletions');
Expand All @@ -448,20 +429,11 @@ function constructArgs(
args.push('--includeCompletionsWithSnippetText');
}

const disableAutomaticNgcc = config.get<boolean>('angular.disableAutomaticNgcc');
if (disableAutomaticNgcc) {
args.push('--disableAutomaticNgcc');
}

const forceStrictTemplates = config.get<boolean>('angular.forceStrictTemplates');
if (forceStrictTemplates) {
args.push('--forceStrictTemplates');
}

if (!isTrustedWorkspace) {
args.push('--untrustedWorkspace');
}

const tsdk: string|null = config.get('typescript.tsdk', null);
const tsProbeLocations = [tsdk, ...getProbeLocations(ctx.extensionPath)];
args.push('--tsProbeLocations', tsProbeLocations.join(','));
Expand All @@ -481,31 +453,14 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
// will return false even when the value is not set. If value is false, then
// we need to check if all projects support Ivy language service.
const config = vscode.workspace.getConfiguration();
let viewEngine: boolean = config.get('angular.view-engine') || !allProjectsSupportIvy();
if (viewEngine && !allProjectsSupportVE()) {
viewEngine = false;
if (config.get('angular.view-engine')) {
vscode.window.showErrorMessage(
`The legacy View Engine option is enabled but the workspace contains a version 13 Angular project.` +
` Legacy View Engine will be disabled since support for it was dropped in v13.`,
);
} else if (!allProjectsSupportIvy() && !allProjectsSupportVE()) {
vscode.window.showErrorMessage(
`The workspace contains a project that does not support legacy View Engine (Angular v13+) and a project that does not support the new current runtime (v8 and below).` +
`The extension will not work for the legacy project in this workspace.`);
}
}

// Node module for the language server
const args = constructArgs(ctx, viewEngine, vscode.workspace.isTrusted);
const args = constructArgs(ctx, vscode.workspace.isTrusted);
const prodBundle = ctx.asAbsolutePath('server');
const devBundle = ctx.asAbsolutePath(path.join('bazel-bin', 'server', 'src', 'server.js'));
// VS Code Insider launches extensions in debug mode by default but users
// install prod bundle so we have to check whether dev bundle exists.
const latestServerModule = debug && fs.existsSync(devBundle) ? devBundle : prodBundle;
const v12ServerModule = ctx.asAbsolutePath(
path.join('v12_language_service', 'node_modules', '@angular', 'language-server'));
const module = viewEngine ? v12ServerModule : latestServerModule;

// Argv options for Node.js
const prodExecArgv: string[] = [];
Expand All @@ -517,7 +472,7 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
];

return {
module,
module: latestServerModule,
transport: lsp.TransportKind.ipc,
args,
options: {
Expand All @@ -526,29 +481,3 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
},
};
}

/**
* Returns true if all projects in the workspace support Ivy LS, otherwise
* return false.
*/
function allProjectsSupportIvy() {
const workspaceFolders = vscode.workspace.workspaceFolders || [];
for (const workspaceFolder of workspaceFolders) {
const angularCore = resolve('@angular/core', workspaceFolder.uri.fsPath);
if (angularCore?.version.greaterThanOrEqual(new Version('9')) === false) {
return false;
}
}
return true;
}

function allProjectsSupportVE() {
const workspaceFolders = vscode.workspace.workspaceFolders || [];
for (const workspaceFolder of workspaceFolders) {
const angularCore = resolve('@angular/core', workspaceFolder.uri.fsPath);
if (angularCore?.version.greaterThanOrEqual(new Version('13')) === true) {
return false;
}
}
return true;
}
10 changes: 0 additions & 10 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ function getTemplateTcb(
}
};
}
function runNgcc(ngClient: AngularLanguageClient): Command {
return {
id: 'angular.runNgcc',
isTextEditorCommand: true,
async execute(textEditor: vscode.TextEditor) {
ngClient.runNgcc(textEditor);
}
};
}

/**
* Command goToComponentWithTemplateFile finds components which reference an external template in
Expand Down Expand Up @@ -189,7 +180,6 @@ export function registerCommands(
restartNgServer(client),
openLogFile(client),
getTemplateTcb(client, context),
runNgcc(client),
goToComponentWithTemplateFile(client),
goToTemplateForComponent(client),
];
Expand Down
4 changes: 0 additions & 4 deletions common/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ export interface SuggestStrictModeParams {
export const SuggestStrictMode =
new NotificationType<SuggestStrictModeParams>('angular/suggestStrictMode');

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

export const OpenOutputChannel = new NotificationType('angular/OpenOutputChannel');
7 changes: 0 additions & 7 deletions common/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,9 @@ export interface GetTcbParams {
position: lsp.Position;
}

export interface RunNgccParams {
textDocument: lsp.TextDocumentIdentifier;
}

export const GetTcbRequest =
new lsp.RequestType<GetTcbParams, GetTcbResponse|null, /* error */ void>('angular/getTcb');

export const RunNgccRequest =
new lsp.RequestType<RunNgccParams, void, /* error */ void>('angular/runNgcc');

export interface GetTcbResponse {
uri: lsp.DocumentUri;
content: string;
Expand Down
Loading