From 8ce808efdad962f5ab4ef78db1027b5ae65494df 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 | 3 ++- server/src/version_provider.ts | 5 ++--- 4 files changed, 10 insertions(+), 14 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 351695e204..ecd565107d 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; @@ -164,13 +163,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 57e00d221a..0d9aa26309 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, }, }); @@ -964,4 +965,4 @@ function toArray(it: ts.Iterator): T[] { function isNgLs(ls: ts.LanguageService|NgLanguageService): ls is NgLanguageService { return 'getTcb' in ls; -} \ No newline at end of file +} 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); } /**