diff --git a/package.json b/package.json index 233ae02..376f46f 100644 --- a/package.json +++ b/package.json @@ -394,6 +394,7 @@ "@chemzqm/tsconfig": "^0.0.3", "@chemzqm/tslint-config": "^1.0.17", "@types/fast-diff": "^1.1.0", + "@types/find-up": "^2.1.1", "@types/node": "^10.12.1", "coc.nvim": "0.0.29", "rimraf": "^2.6.2", @@ -401,6 +402,7 @@ }, "dependencies": { "fast-diff": "^1.2.0", + "find-up": "^3.0.0", "semver": "^5.6.0", "tslib": "^1.9.3", "typescript": "^3.1.3", diff --git a/src/server/features/bufferSyncSupport.ts b/src/server/features/bufferSyncSupport.ts index 7fcaf73..7869084 100644 --- a/src/server/features/bufferSyncSupport.ts +++ b/src/server/features/bufferSyncSupport.ts @@ -100,6 +100,10 @@ export default class BufferSyncSupport { args.scriptKindName = scriptKind } } + if (this.client.apiVersion.gte(API.v230)) { + args.projectRootPath = this.client.getWorkspaceRootForResource(document.uri) + } + this.client.execute('open', args, false) // tslint:disable-line this.requestDiagnostic(uri) } diff --git a/src/server/typescriptService.ts b/src/server/typescriptService.ts index dc67151..88f8ff7 100644 --- a/src/server/typescriptService.ts +++ b/src/server/typescriptService.ts @@ -39,6 +39,7 @@ export interface ITypeScriptServiceClient { onTypesInstallerInitializationFailed: Event readonly logger: Logger + getWorkspaceRootForResource(uri: string): string normalizePath(resource: Uri): string | null asUrl(filepath: string): Uri toPath(uri: string): string diff --git a/src/server/typescriptServiceClient.ts b/src/server/typescriptServiceClient.ts index 28b4d64..9f0f8d9 100644 --- a/src/server/typescriptServiceClient.ts +++ b/src/server/typescriptServiceClient.ts @@ -3,6 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import cp from 'child_process' +import findUp from 'find-up' import fs from 'fs' import os from 'os' import path from 'path' @@ -379,8 +380,8 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient } ) resolve(handle) - this._onTsServerStarted.fire(currentVersion.version) this.serviceStarted(resendModels) + this._onTsServerStarted.fire(currentVersion.version) } ) } catch (e) { @@ -810,6 +811,13 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient return args } + + public getWorkspaceRootForResource(uri: string): string { + let u = Uri.parse(uri) + if (u.scheme != 'file') return workspace.root + let res = findUp.sync(['package.json', '.vim', '.git', '.hg'], { cwd: path.dirname(u.fsPath) }) + return res ? path.dirname(res) : null + } } function getDignosticsKind(event: Proto.Event): DiagnosticKind { diff --git a/yarn.lock b/yarn.lock index bf88492..99063c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -114,6 +114,11 @@ resolved "https://registry.yarnpkg.com/@types/fast-diff/-/fast-diff-1.1.0.tgz#68c7f476025740b0b6756e51e38b1188dd528b0e" integrity sha512-doBwHnPAGdE54EiIFc0/v1qHlRVtNTaxgCZOS9SdSGPq91vx3kUKi5fmz/yivW/RAXEOUJYVXtVFQ6IPpqKRWg== +"@types/find-up@^2.1.1": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@types/find-up/-/find-up-2.1.1.tgz#1cd2d240f1ad1f48d32346074724dc3107248a11" + integrity sha512-60LC501bQRN9/3yfVaEEMd7IndaufffL56PBRAejPpUrY304Ps1jfnjNqPw5jmM5R8JHWiKBAe5IHzNcPV41AA== + "@types/node@^10.12.1": version "10.12.1" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.1.tgz#da61b64a2930a80fa708e57c45cd5441eb379d5b"