From a034d1b0a72ac2ca3684c95bd6fbcad9d53e2b73 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sat, 27 Aug 2022 22:57:05 +0800 Subject: [PATCH] fix: path resolve incorrect in multiple workspaces close #1679 --- packages/vue-language-server/src/projects.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/vue-language-server/src/projects.ts b/packages/vue-language-server/src/projects.ts index 8893edc40..6c965eb90 100644 --- a/packages/vue-language-server/src/projects.ts +++ b/packages/vue-language-server/src/projects.ts @@ -270,6 +270,8 @@ export function createProjects( } } +let currentCwd = ''; + function createWorkspace( runtimeEnv: RuntimeEnvironment, languageConfigs: LanguageConfigs, @@ -288,18 +290,17 @@ function createWorkspace( const projects = shared.createPathMap(); let inferredProject: Project | undefined; - const getRootPath = () => rootPath; - const _workspaceSys = ts.sys.getCurrentDirectory() === rootPath ? ts.sys : new Proxy(ts.sys, { + const _workspaceSys = new Proxy(ts.sys, { get(target, prop) { const fn = target[prop as keyof typeof target]; if (typeof fn === 'function') { return new Proxy(fn, { apply(target, thisArg, args) { - const cwd = process.cwd; - process.cwd = getRootPath; - const result = (target as any).apply(thisArg, args); - process.cwd = cwd; - return result; + if (currentCwd !== rootPath) { + process.chdir(rootPath); + currentCwd = rootPath; + } + return (target as any).apply(thisArg, args); } }); }