Skip to content

Commit b9d8bc7

Browse files
authored
refactor(client): Support VE by using the v12 version of the language server/service (#1527)
Support for View Engine is dropped in the compiler in the v13 release. We still want to support VE for the language service while people upgrade projects. To do this, we launch the v12 server and use the v12 language service with the VE flag flipped on.
1 parent 3e4b0a6 commit b9d8bc7

File tree

7 files changed

+88
-23
lines changed

7 files changed

+88
-23
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ orbs:
44
jobs:
55
build-and-test:
66
docker:
7-
- image: cimg/node:16.10.0-browsers@sha256:83ff2dcad3043c4b3f7f58513805a0c8757ba5541a1f3c213f80bd242a3c77ac
7+
- image: cimg/node:14.17.6@sha256:589b5e494173bfb48923fa8d29b010b4d17079ac98d08de95dd4a78e57f5aa0b
88
steps:
99
- checkout
1010
- node/install-packages:

client/src/client.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,8 @@ function registerProgressHandlers(client: lsp.LanguageClient) {
405405
* @param configName
406406
* @param bundled
407407
*/
408-
function getProbeLocations(configValue: string|null, bundled: string): string[] {
408+
function getProbeLocations(bundled: string): string[] {
409409
const locations = [];
410-
// Always use config value if it's specified
411-
if (configValue) {
412-
locations.push(configValue);
413-
}
414410
// Prioritize the bundled version
415411
locations.push(bundled);
416412
// Look in workspaces currently open
@@ -425,7 +421,7 @@ function getProbeLocations(configValue: string|null, bundled: string): string[]
425421
* Construct the arguments that's used to spawn the server process.
426422
* @param ctx vscode extension context
427423
*/
428-
function constructArgs(ctx: vscode.ExtensionContext): string[] {
424+
function constructArgs(ctx: vscode.ExtensionContext, viewEngine: boolean): string[] {
429425
const config = vscode.workspace.getConfiguration();
430426
const args: string[] = ['--logToConsole'];
431427

@@ -437,15 +433,15 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {
437433
args.push('--logVerbosity', ngLog);
438434
}
439435

440-
const ngProbeLocations = getProbeLocations(null, ctx.extensionPath);
441-
args.push('--ngProbeLocations', ngProbeLocations.join(','));
442-
443-
// Because the configuration is typed as "boolean" in package.json, vscode
444-
// will return false even when the value is not set. If value is false, then
445-
// we need to check if all projects support Ivy language service.
446-
const viewEngine: boolean = config.get('angular.view-engine') || !allProjectsSupportIvy();
436+
const ngProbeLocations = getProbeLocations(ctx.extensionPath);
447437
if (viewEngine) {
448438
args.push('--viewEngine');
439+
args.push('--ngProbeLocations', [
440+
path.join(ctx.extensionPath, 'v12_language_service'),
441+
...ngProbeLocations,
442+
].join(','));
443+
} else {
444+
args.push('--ngProbeLocations', ngProbeLocations.join(','));
449445
}
450446

451447
const includeAutomaticOptionalChainCompletions =
@@ -461,7 +457,7 @@ function constructArgs(ctx: vscode.ExtensionContext): string[] {
461457
}
462458

463459
const tsdk: string|null = config.get('typescript.tsdk', null);
464-
const tsProbeLocations = getProbeLocations(tsdk, ctx.extensionPath);
460+
const tsProbeLocations = [tsdk, ...getProbeLocations(ctx.extensionPath)];
465461
args.push('--tsProbeLocations', tsProbeLocations.join(','));
466462

467463
return args;
@@ -475,9 +471,22 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
475471
NG_DEBUG: true,
476472
};
477473

474+
// Because the configuration is typed as "boolean" in package.json, vscode
475+
// will return false even when the value is not set. If value is false, then
476+
// we need to check if all projects support Ivy language service.
477+
const config = vscode.workspace.getConfiguration();
478+
const viewEngine: boolean = config.get('angular.view-engine') || !allProjectsSupportIvy();
479+
478480
// Node module for the language server
481+
const args = constructArgs(ctx, viewEngine);
479482
const prodBundle = ctx.asAbsolutePath('server');
480483
const devBundle = ctx.asAbsolutePath(path.join('dist', 'server', 'server.js'));
484+
// VS Code Insider launches extensions in debug mode by default but users
485+
// install prod bundle so we have to check whether dev bundle exists.
486+
const latestServerModule = debug && fs.existsSync(devBundle) ? devBundle : prodBundle;
487+
const v12ServerModule = ctx.asAbsolutePath(
488+
path.join('v12_language_service', 'node_modules', '@angular', 'language-server'));
489+
const module = viewEngine ? v12ServerModule : latestServerModule;
481490

482491
// Argv options for Node.js
483492
const prodExecArgv: string[] = [];
@@ -489,11 +498,9 @@ function getServerOptions(ctx: vscode.ExtensionContext, debug: boolean): lsp.Nod
489498
];
490499

491500
return {
492-
// VS Code Insider launches extensions in debug mode by default but users
493-
// install prod bundle so we have to check whether dev bundle exists.
494-
module: debug && fs.existsSync(devBundle) ? devBundle : prodBundle,
501+
module,
495502
transport: lsp.TransportKind.ipc,
496-
args: constructArgs(ctx),
503+
args,
497504
options: {
498505
env: debug ? devEnv : prodEnv,
499506
execArgv: debug ? devExecArgv : prodExecArgv,
@@ -514,4 +521,4 @@ function allProjectsSupportIvy() {
514521
}
515522
}
516523
return true;
517-
}
524+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,4 @@
216216
"type": "git",
217217
"url": "https://github.com/angular/vscode-ng-language-service"
218218
}
219-
}
219+
}

scripts/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ rm -rf **/*.tsbuildinfo
1212
# Build the client and server
1313
yarn run compile
1414

15+
# install npm packages in the pinned v12
16+
pushd v12_language_service
17+
yarn install
18+
popd
19+
1520
# Copy files to package root
1621
cp package.json angular.png CHANGELOG.md README.md dist/npm
1722
# Copy files to server directory
1823
cp -r server/package.json server/README.md server/bin dist/npm/server
24+
cp -r v12_language_service dist/npm/v12_language_service
1925
# Build and copy files to syntaxes directory
2026
yarn run build:syntaxes
2127
mkdir dist/npm/syntaxes

server/src/session.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ export class Session {
149149
}
150150
});
151151

152-
// TODO(atscott): The Ivy flag was removed in v13. We need to include a legacy version (some
153-
// v12) of the language service in order to continue supporting view engine.
154152
const pluginConfig: PluginConfig = {
155153
angularOnly: true,
156154
};

v12_language_service/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@angular/language-service": "12.2.9",
4+
"@angular/language-server": "12.2.1"
5+
}
6+
}

v12_language_service/yarn.lock

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@angular/[email protected]":
6+
version "12.2.1"
7+
resolved "https://registry.yarnpkg.com/@angular/language-server/-/language-server-12.2.1.tgz#9e0d3cf87da975ea05c1950a55d9159a7eac1ec1"
8+
integrity sha512-xra6ep0I4500NzE2kL435J757hTFwpretUzSUgKa2pSGOZXDoBU78Equb6qnmEgM4O/CJHFlmeBZFxmoxhzREQ==
9+
dependencies:
10+
"@angular/language-service" "12.2.9"
11+
vscode-jsonrpc "6.0.0"
12+
vscode-languageserver "7.0.0"
13+
vscode-uri "3.0.2"
14+
15+
"@angular/[email protected]":
16+
version "12.2.9"
17+
resolved "https://registry.yarnpkg.com/@angular/language-service/-/language-service-12.2.9.tgz#6732c2dae7c25760cfe22f65c714096aa4f0a387"
18+
integrity sha512-q6WH8CxS4nXKnIR/imQbRYTdP0PW63tDogzlol6gnB/jEmGgmQJphYRVeDqr5owIxuzCB06JkWXPVsyHY3yHvA==
19+
20+
21+
version "6.0.0"
22+
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz#108bdb09b4400705176b957ceca9e0880e9b6d4e"
23+
integrity sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==
24+
25+
26+
version "3.16.0"
27+
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz#34135b61a9091db972188a07d337406a3cdbe821"
28+
integrity sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==
29+
dependencies:
30+
vscode-jsonrpc "6.0.0"
31+
vscode-languageserver-types "3.16.0"
32+
33+
34+
version "3.16.0"
35+
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz#ecf393fc121ec6974b2da3efb3155644c514e247"
36+
integrity sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==
37+
38+
39+
version "7.0.0"
40+
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-7.0.0.tgz#49b068c87cfcca93a356969d20f5d9bdd501c6b0"
41+
integrity sha512-60HTx5ID+fLRcgdHfmz0LDZAXYEV68fzwG0JWwEPBode9NuMYTIxuYXPg4ngO8i8+Ou0lM7y6GzaYWbiDL0drw==
42+
dependencies:
43+
vscode-languageserver-protocol "3.16.0"
44+
45+
46+
version "3.0.2"
47+
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-3.0.2.tgz#ecfd1d066cb8ef4c3a208decdbab9a8c23d055d0"
48+
integrity sha512-jkjy6pjU1fxUvI51P+gCsxg1u2n8LSt0W6KrCNQceaziKzff74GoWmjVG46KieVzybO1sttPQmYfrwSHey7GUA==

0 commit comments

Comments
 (0)