Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #1837

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import * as path from 'path';
import {
workspace as Workspace, window as Window, languages as Languages, Uri, TextDocument, CodeActionContext, Diagnostic,
Command, CodeAction, MessageItem, ConfigurationTarget, env as Env, CodeActionKind, WorkspaceConfiguration, NotebookCell, commands,
ExtensionContext, LanguageStatusItem, LanguageStatusSeverity, DocumentFilter as VDocumentFilter
ExtensionContext, LanguageStatusItem, LanguageStatusSeverity, DocumentFilter as VDocumentFilter,
WorkspaceFolder,
workspace
} from 'vscode';

import {
Expand All @@ -27,17 +29,40 @@ import { pickFolder } from './vscode-utils';
export class Validator {

private readonly probeFailed: Set<string> = new Set();

private configurationPerWorkspace = new WeakMap<WorkspaceFolder, WorkspaceConfiguration>();
private readonly cachedChecks = new WeakMap<TextDocument, Validate>();
private globalConfig ?: WorkspaceConfiguration;
public clear(): void {
this.probeFailed.clear();
}
workspace.workspaceFolders?.forEach(folder => this.configurationPerWorkspace.delete(folder));
this.globalConfig = undefined;
}

public add(uri: Uri): void {
this.probeFailed.add(uri.toString());
}

private getConfiguration(uri: Uri): WorkspaceConfiguration {
const workspaceFolder = Workspace.getWorkspaceFolder(uri);
if (workspaceFolder){
const config = this.configurationPerWorkspace.get(workspaceFolder) || Workspace.getConfiguration('eslint', workspaceFolder.uri);
this.configurationPerWorkspace.set(workspaceFolder, config);
return config;
}
return this.globalConfig ??= Workspace.getConfiguration('eslint');
}

public check(textDocument: TextDocument): Validate {
const config = Workspace.getConfiguration('eslint', textDocument.uri);
const cached = this.cachedChecks.get(textDocument);
if (cached !== undefined) {
return cached;
}
const result = this.docheck(textDocument);
this.cachedChecks.set(textDocument, result);
return result;
}
public docheck(textDocument: TextDocument): Validate {
const config = this.getConfiguration(textDocument.uri);

if (!config.get<boolean>('enable', true)) {
return Validate.off;
Expand Down