From 98429edc6db6bf38d68c0b0389b2ee600f373a6d Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Tue, 23 Feb 2021 10:42:35 -0800 Subject: [PATCH] fix: use single entry point for @angular/language-service Starting from `@angular/language-service` v12.0.0-next.3, the package will dynamically load View Engine or Ivy LS based on the config passed to the plugin. This reverts https://github.com/angular/vscode-ng-language-service/pull/1111 --- server/src/server.ts | 7 ++++--- server/src/server_host.ts | 9 ++------- server/src/session.ts | 1 + server/src/tests/version_provider_spec.ts | 6 ++++-- server/src/version_provider.ts | 5 ++--- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 31d4e7f007..5f40115184 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -10,7 +10,7 @@ import {generateHelpMessage, parseCommandLine} from './cmdline_utils'; import {createLogger} from './logger'; import {ServerHost} from './server_host'; import {Session} from './session'; -import {NGLANGSVC, resolveNgLangSvc, resolveTsServer} from './version_provider'; +import {resolveNgLangSvc, resolveTsServer} from './version_provider'; // Parse command line arguments const options = parseCommandLine(process.argv); @@ -30,13 +30,14 @@ const ts = resolveTsServer(options.tsProbeLocations); const ng = resolveNgLangSvc(options.ngProbeLocations, options.ivy); // ServerHost provides native OS functionality -const host = new ServerHost(options.ivy); +const host = new ServerHost(); // Establish a new server session that encapsulates lsp connection. const session = new Session({ host, logger, - ngPlugin: NGLANGSVC, // TypeScript allows only package names as plugin names. + // TypeScript allows only package names as plugin names. + ngPlugin: '@angular/language-service', resolvedNgLsPath: ng.resolvedPath, ivy: options.ivy, logToConsole: options.logToConsole, diff --git a/server/src/server_host.ts b/server/src/server_host.ts index f546ea4931..698227718c 100644 --- a/server/src/server_host.ts +++ b/server/src/server_host.ts @@ -7,7 +7,6 @@ */ import * as ts from 'typescript/lib/tsserverlibrary'; -import {NGLANGSVC} from './version_provider'; /** * `ServerHost` is a wrapper around `ts.sys` for the Node system. In Node, all @@ -20,7 +19,7 @@ export class ServerHost implements ts.server.ServerHost { readonly newLine: string; readonly useCaseSensitiveFileNames: boolean; - constructor(private ivy: boolean) { + constructor() { this.args = ts.sys.args; this.newLine = ts.sys.newLine; this.useCaseSensitiveFileNames = ts.sys.useCaseSensitiveFileNames; @@ -172,13 +171,9 @@ export class ServerHost implements ts.server.ServerHost { require(initialPath: string, moduleName: string) { try { - let modulePath = require.resolve(moduleName, { + const modulePath = require.resolve(moduleName, { paths: [initialPath], }); - // TypeScript allows only package names as plugin names. - if (this.ivy && moduleName === NGLANGSVC) { - modulePath = this.resolvePath(modulePath + '/../ivy.js'); - } return { module: require(modulePath), error: undefined, diff --git a/server/src/session.ts b/server/src/session.ts index fda48586e3..dd7e57837b 100644 --- a/server/src/session.ts +++ b/server/src/session.ts @@ -114,6 +114,7 @@ export class Session { pluginName: options.ngPlugin, configuration: { angularOnly: true, + ivy: options.ivy, }, }); diff --git a/server/src/tests/version_provider_spec.ts b/server/src/tests/version_provider_spec.ts index f5c195c1b7..b442d318bc 100644 --- a/server/src/tests/version_provider_spec.ts +++ b/server/src/tests/version_provider_spec.ts @@ -30,13 +30,15 @@ describe('Node Module Resolver', () => { it('should be able to resolve Angular language service', () => { const result = resolveNgLangSvc(probeLocations, false /* ivy */); expect(result).toBeDefined(); - expect(result.resolvedPath).toMatch(/language-service.js$/); + expect(result.resolvedPath.endsWith('@angular/language-service/index.js')).toBeTrue(); }); it('should be able to resolve Ivy version of Angular language service', () => { const result = resolveNgLangSvc(probeLocations, true /* ivy */); expect(result).toBeDefined(); - expect(result.resolvedPath).toMatch(/ivy.js$/); + // Starting from v12.0.0-next.3 @angular/language-service provides a single + // entry point + expect(result.resolvedPath.endsWith('@angular/language-service/index.js')).toBeTrue(); }); }); diff --git a/server/src/version_provider.ts b/server/src/version_provider.ts index 2bd4759408..ae9a73f21f 100644 --- a/server/src/version_provider.ts +++ b/server/src/version_provider.ts @@ -11,7 +11,6 @@ import * as path from 'path'; const MIN_TS_VERSION = '4.1'; const MIN_NG_VERSION = '12.0'; -export const NGLANGSVC = '@angular/language-service'; const TSSERVERLIB = 'typescript/lib/tsserverlibrary'; /** @@ -120,8 +119,8 @@ function resolveTsServerFromTsdk(tsdk: string): NodeModule|undefined { * @param ivy true if Ivy language service is requested */ export function resolveNgLangSvc(probeLocations: string[], ivy: boolean): NodeModule { - const packageName = ivy ? `${NGLANGSVC}/bundles/ivy` : NGLANGSVC; - return resolveWithMinVersion(packageName, MIN_NG_VERSION, probeLocations, NGLANGSVC); + const ngls = '@angular/language-service'; + return resolveWithMinVersion(ngls, MIN_NG_VERSION, probeLocations, ngls); } /**