From c08e52f97e072cb1ac31c48d4858738f68291e09 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Tue, 24 Nov 2020 11:36:50 +0800 Subject: [PATCH] use workspace.expand for npm path --- src/server/typescriptServiceClient.ts | 25 +++++++++++-------------- src/server/utils/configuration.ts | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index e893ffe..62770a4 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -3,29 +3,28 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import cp from 'child_process' +import { disposeAll, ServiceStat, Uri, workspace } from 'coc.nvim' import fs from 'fs' import os from 'os' import path from 'path' import { CancellationToken, Disposable, Emitter, Event } from 'vscode-languageserver-protocol' -import which from 'which' -import { Uri, ServiceStat, workspace, disposeAll } from 'coc.nvim' +import { PluginManager } from '../utils/plugins' +import { CallbackMap } from './callbackMap' +import BufferSyncSupport from './features/bufferSyncSupport' +import { DiagnosticKind, DiagnosticsManager } from './features/diagnostics' import FileConfigurationManager from './features/fileConfigurationManager' import * as Proto from './protocol' +import { RequestItem, RequestQueue, RequestQueueingType } from './requestQueue' import { ITypeScriptServiceClient, ServerResponse } from './typescriptService' import API from './utils/api' import { TsServerLogLevel, TypeScriptServiceConfiguration } from './utils/configuration' import Logger from './utils/logger' -import { fork, getTempFile, getTempDirectory, IForkOptions, makeRandomHexString } from './utils/process' +import { fork, getTempDirectory, getTempFile, IForkOptions, makeRandomHexString } from './utils/process' import Tracer from './utils/tracer' import { inferredProjectConfig } from './utils/tsconfig' import { TypeScriptVersion, TypeScriptVersionProvider } from './utils/versionProvider' import VersionStatus from './utils/versionStatus' -import { PluginManager } from '../utils/plugins' import { ICallback, Reader } from './utils/wireProtocol' -import { CallbackMap } from './callbackMap' -import { RequestItem, RequestQueue, RequestQueueingType } from './requestQueue' -import BufferSyncSupport from './features/bufferSyncSupport' -import { DiagnosticKind, DiagnosticsManager } from './features/diagnostics' class ForkedTsServerProcess { constructor(private childProcess: cp.ChildProcess) { } @@ -844,12 +843,10 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient } if (this.apiVersion.gte(API.v234)) { - if (this._configuration.npmLocation) { - args.push('--npmLocation', `"${this._configuration.npmLocation}"`) - } else { - try { - args.push('--npmLocation', `"${which.sync('npm')}"`) - } catch (e) { } // tslint:disable-line + let { npmLocation } = this._configuration + if (npmLocation) { + this.logger.info(`using npm from ${npmLocation}`) + args.push('--npmLocation', `"${npmLocation}"`) } } diff --git a/src/server/utils/configuration.ts b/src/server/utils/configuration.ts index 36e3112..7ee4c21 100644 --- a/src/server/utils/configuration.ts +++ b/src/server/utils/configuration.ts @@ -103,7 +103,7 @@ export class TypeScriptServiceConfiguration { public get npmLocation(): string | null { let path = this._configuration.get('npm', '') - if (path) return path + if (path) return workspace.expand(path) try { path = which.sync('npm') } catch (e) {