fix getProjectRootPath, fix #15

This commit is contained in:
chemzqm 2019-03-23 18:38:17 +08:00
parent 395828b23e
commit d6ebd2b613
2 changed files with 11 additions and 2 deletions

View file

@ -148,6 +148,7 @@ export default class FileConfigurationManager {
disableSuggestions: !config.get<boolean>('suggest.enabled', true),
importModuleSpecifierPreference: getImportModuleSpecifier(config) as any,
quotePreference: config.get<'single' | 'double'>('preferences.quoteStyle', 'single'),
allowRenameOfImportPath: true,
allowTextChangesInNewFiles: true,
}
}

View file

@ -793,8 +793,16 @@ export default class TypeScriptServiceClient implements ITypeScriptServiceClient
public getProjectRootPath(uri: string): string {
let u = Uri.parse(uri)
if (u.scheme != 'file') return workspace.cwd
if (u.fsPath.startsWith(workspace.root) && workspace.root != os.homedir()) return workspace.root
let { cwd } = workspace
if (u.scheme != 'file') return cwd
if (u.fsPath.startsWith(cwd) && cwd != os.homedir()) {
let files = fs.readdirSync(cwd)
if (files.indexOf('tsconfig.json') !== -1
|| files.indexOf('jsconfig.json') !== -1
|| files.indexOf('package.json') !== -1) {
return cwd
}
}
let res = findUp.sync(['tsconfig.json', 'jsconfig.json'], { cwd: path.dirname(u.fsPath) })
return res ? path.dirname(res) : workspace.cwd
}