From 07d204f8c90c4778b4037ef5db35edf312397446 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sat, 22 Oct 2022 22:25:07 +0800 Subject: [PATCH] perf: add root scripts on demand for inferred project --- packages/language-server/src/utils/project.ts | 8 +++++++- packages/language-server/src/utils/workspaces.ts | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/language-server/src/utils/project.ts b/packages/language-server/src/utils/project.ts index ac9edba78..23982a8a7 100644 --- a/packages/language-server/src/utils/project.ts +++ b/packages/language-server/src/utils/project.ts @@ -60,6 +60,12 @@ export async function createProject( getLanguageService, getLanguageServiceDontCreate: () => vueLs, getParsedCommandLine: () => parsedCommandLine, + tryAddFile: (fileName: string) => { + if (!parsedCommandLine.fileNames.includes(fileName)) { + parsedCommandLine.fileNames.push(fileName); + projectVersion++; + } + }, dispose, }; @@ -253,7 +259,7 @@ function createParsedCommandLine( content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions); } else { - content = ts.parseJsonConfigFileContent({}, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json' as path.PosixPath), undefined, extraFileExtensions); + content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json' as path.PosixPath), undefined, extraFileExtensions); } // fix https://github.com/johnsoncodehk/volar/issues/1786 // https://github.com/microsoft/TypeScript/issues/30457 diff --git a/packages/language-server/src/utils/workspaces.ts b/packages/language-server/src/utils/workspaces.ts index 4dce9951c..606ae7d8c 100644 --- a/packages/language-server/src/utils/workspaces.ts +++ b/packages/language-server/src/utils/workspaces.ts @@ -180,9 +180,11 @@ export function createWorkspaces( } if (rootUris.length) { + const project = await (await workspaces.get(rootUris[0]))?.getInferredProject(); + project?.tryAddFile(shared.getPathOfUri(uri)); return { tsconfig: undefined, - project: await (await workspaces.get(rootUris[0]))?.getInferredProject(), + project, }; } }