Skip to content

Commit

Permalink
perf: add root scripts on demand for inferred project
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 22, 2022
1 parent 7ba4930 commit 07d204f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/language-server/src/utils/project.ts
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/language-server/src/utils/workspaces.ts
Expand Up @@ -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,
};
}
}
Expand Down

0 comments on commit 07d204f

Please sign in to comment.