fix(tsserver): fix project root path resolve

This commit is contained in:
chemzqm 2019-01-22 14:17:18 +08:00
parent d1d341b2a8
commit 931a0046d9
3 changed files with 5 additions and 6 deletions

View file

@ -101,7 +101,7 @@ export default class BufferSyncSupport {
}
}
if (this.client.apiVersion.gte(API.v230)) {
args.projectRootPath = this.client.getWorkspaceRootForResource(document.uri)
args.projectRootPath = this.client.getProjectRootPath(document.uri)
}
this.client.execute('open', args, false) // tslint:disable-line

View file

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

View file

@ -318,7 +318,6 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
workspace.showMessage(`Can not find tsserver, run ':CocInstall coc-tsserver' to fix it!`, 'error')
return
}
workspace.showMessage(`Using tsserver from: ${currentVersion.path}`) // tslint:disable-line
this._apiVersion = currentVersion.version
this.versionStatus.onDidChangeTypeScriptVersion(currentVersion)
this.requestQueue = new RequestQueue()
@ -813,11 +812,11 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
return args
}
public getWorkspaceRootForResource(uri: string): string {
public getProjectRootPath(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
let res = findUp.sync(['tsconfig.json', 'jsconfig.json', 'package.json'], { cwd: path.dirname(u.fsPath) })
return res ? path.dirname(res) : workspace.rootPath
}
}