From 8f7bf42a363993624cc0b80eb89193e38c952573 Mon Sep 17 00:00:00 2001 From: chemzqm Date: Fri, 19 Apr 2019 18:27:37 +0800 Subject: [PATCH] resolve tsc from workspaceFolder --- src/server/features/watchBuild.ts | 20 +++++++------------ src/server/utils/fs.ts | 30 ----------------------------- src/server/utils/versionProvider.ts | 1 - 3 files changed, 7 insertions(+), 44 deletions(-) delete mode 100644 src/server/utils/fs.ts diff --git a/src/server/features/watchBuild.ts b/src/server/features/watchBuild.ts index a1663c2..5e8ddc3 100644 --- a/src/server/features/watchBuild.ts +++ b/src/server/features/watchBuild.ts @@ -7,9 +7,7 @@ import path from 'path' import { Disposable, Location } from 'vscode-languageserver-protocol' import Uri from 'vscode-uri' import which from 'which' -import { resolveRoot } from '../utils/fs' -const TSC = './node_modules/.bin/tsc' const countRegex = /Found\s+(\d+)\s+error/ const errorRegex = /^(.+)\((\d+),(\d+)\):\s(\w+)\sTS(\d+):\s*(.+)$/ @@ -31,7 +29,6 @@ export default class WatchProject implements Disposable { public static readonly id: string = 'tsserver.watchBuild' public static readonly startTexts: string[] = ['Starting compilation in watch mode', 'Starting incremental compilation'] private statusItem: StatusBarItem - private isRunning = false private task: Task private options: TaskOptions @@ -69,6 +66,7 @@ export default class WatchProject implements Disposable { private async check(): Promise { let running = await this.task.running if (running) { + this.options = this.getOptions() this.statusItem.isProgress = false this.statusItem.text = '?' this.statusItem.show() @@ -82,8 +80,6 @@ export default class WatchProject implements Disposable { } private onStop(): void { - let { nvim } = workspace - this.isRunning = false this.statusItem.hide() } @@ -121,13 +117,10 @@ export default class WatchProject implements Disposable { } public getOptions(): TaskOptions { - let docs = workspace.documents - let idx = docs.findIndex(doc => doc.uri.indexOf(TSC) !== -1) - if (idx !== -1) return - let cwd = workspace.cwd - let res = findUp.sync(['node_modules'], { cwd }) - let cmd: string + let res = findUp.sync(['node_modules'], { cwd: workspace.root }) let root: string + let cmd: string + // let root: string if (!res) { if (executable('tsc')) { cmd = 'tsc' @@ -144,11 +137,12 @@ export default class WatchProject implements Disposable { workspace.showMessage(`Local & global tsc not found`, 'error') return } - let configRoot = resolveRoot(cwd, ['tsconfig.json']) - if (!configRoot) { + let find = findUp.sync(['tsconfig.json'], { cwd: root }) + if (!find) { workspace.showMessage('tsconfig.json not found!', 'error') return } + let configRoot = path.dirname(find) let configPath = path.relative(root, path.join(configRoot, 'tsconfig.json')) return { cmd, diff --git a/src/server/utils/fs.ts b/src/server/utils/fs.ts deleted file mode 100644 index 18cf37f..0000000 --- a/src/server/utils/fs.ts +++ /dev/null @@ -1,30 +0,0 @@ -import path from 'path' -import os from 'os' -import fs from 'fs' - -export function getParentDirs(fullpath: string): string[] { - let obj = path.parse(fullpath) - if (!obj || !obj.root) return [] - let res = [] - let p = path.dirname(fullpath) - while (p && p !== obj.root) { - res.push(p) - p = path.dirname(p) - } - return res -} - -export function resolveRoot(cwd: string, subs: string[], home?: string): string | null { - home = home || os.homedir() - let { root } = path.parse(cwd) - let paths = getParentDirs(cwd) - paths.unshift(cwd) - for (let p of paths) { - if (p == home || p == root) return null - for (let sub of subs) { - let d = path.join(p, sub) - if (fs.existsSync(d)) return path.dirname(d) - } - } - return root -} diff --git a/src/server/utils/versionProvider.ts b/src/server/utils/versionProvider.ts index 9f234f6..3aeed55 100644 --- a/src/server/utils/versionProvider.ts +++ b/src/server/utils/versionProvider.ts @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import fs from 'fs' import path from 'path' -import { getParentDirs } from './fs' import { workspace, Uri } from 'coc.nvim' import API from './api' import { TypeScriptServiceConfiguration } from './configuration'