support projectRootPath for document

This commit is contained in:
chemzqm 2018-11-07 11:49:32 +08:00
parent a3504c8f1e
commit e759b156b4
5 changed files with 21 additions and 1 deletions

View file

@ -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",

View file

@ -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)
}

View file

@ -39,6 +39,7 @@ export interface ITypeScriptServiceClient {
onTypesInstallerInitializationFailed: Event<Proto.TypesInstallerInitializationFailedEventBody>
readonly logger: Logger
getWorkspaceRootForResource(uri: string): string
normalizePath(resource: Uri): string | null
asUrl(filepath: string): Uri
toPath(uri: string): string

View file

@ -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 {

View file

@ -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"