Skip to content

Commit

Permalink
Add workDoneProgress and perf problem
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Dec 9, 2020
1 parent 1ab3bf9 commit 97f24d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/src/services/vls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -83,6 +84,7 @@ export class VLS {
private nodeModulesMap: Map<string, string[]>;
private documentService: DocumentService;
private globalSnippetDir: string;
private projectLoading: string[];
private projects: Map<string, ProjectService>;
private pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
private cancellationTokenValidationRequests: { [uri: string]: VCancellationTokenSource } = {};
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -332,6 +345,7 @@ export class VLS {
dependencyService
);
this.projects.set(projectConfig.rootFsPath, project);
workDoneProgress.done();
return project;
}

Expand Down
5 changes: 5 additions & 0 deletions server/src/utils/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function sleep(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}

0 comments on commit 97f24d0

Please sign in to comment.