From 97f24d0f035f583aaa2345d1efce5bab80f36db6 Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Wed, 9 Dec 2020 20:27:53 +0800 Subject: [PATCH] Add workDoneProgress and perf problem --- server/src/services/vls.ts | 14 ++++++++++++++ server/src/utils/sleep.ts | 5 +++++ 2 files changed, 19 insertions(+) create mode 100644 server/src/utils/sleep.ts diff --git a/server/src/services/vls.ts b/server/src/services/vls.ts index 548cb5b232..90394e3727 100644 --- a/server/src/services/vls.ts +++ b/server/src/services/vls.ts @@ -62,6 +62,7 @@ import { createProjectService, ProjectService } from './projectService'; import { createEnvironmentService } from './EnvironmentService'; import { getVueVersionKey } from '../utils/vueVersion'; import { accessSync, constants, existsSync } from 'fs'; +import { sleep } from '../utils/sleep'; interface ProjectConfig { vlsFullConfig: VLSFullConfig; @@ -83,6 +84,7 @@ export class VLS { private nodeModulesMap: Map; private documentService: DocumentService; private globalSnippetDir: string; + private projectLoading: string[]; private projects: Map; private pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {}; private cancellationTokenValidationRequests: { [uri: string]: VCancellationTokenSource } = {}; @@ -97,6 +99,7 @@ export class VLS { this.workspaces = new Map(); this.projects = new Map(); this.nodeModulesMap = new Map(); + this.projectLoading = []; } async init(params: InitializeParams) { @@ -299,9 +302,19 @@ export class VLS { if (this.projects.has(projectConfig.rootFsPath)) { return this.projects.get(projectConfig.rootFsPath); } + // Load project once + if (this.projectLoading.includes(projectConfig.rootFsPath)) { + while (!this.projects.has(projectConfig.rootFsPath)) { + await sleep(500); + } + return this.projects.get(projectConfig.rootFsPath); + } // init project // Yarn Pnp don't need this. https://yarnpkg.com/features/pnp + this.projectLoading.push(projectConfig.rootFsPath); + const workDoneProgress = await this.lspConnection.window.createWorkDoneProgress(); + workDoneProgress.begin(`Load project: ${projectConfig.rootFsPath}`, undefined); const nodeModulePaths = !process.versions.pnp ? this.nodeModulesMap.get(projectConfig.rootPathForConfig) ?? createNodeModulesPaths(projectConfig.rootPathForConfig) @@ -332,6 +345,7 @@ export class VLS { dependencyService ); this.projects.set(projectConfig.rootFsPath, project); + workDoneProgress.done(); return project; } diff --git a/server/src/utils/sleep.ts b/server/src/utils/sleep.ts new file mode 100644 index 0000000000..fbf26b8688 --- /dev/null +++ b/server/src/utils/sleep.ts @@ -0,0 +1,5 @@ +export function sleep(ms: number) { + return new Promise(resolve => { + setTimeout(resolve, ms); + }); +}