mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 05:19:39 +00:00
Skip diagnostics for non-open md files (#152687)
Currently we only show diagnostics for opened tabs. This means we shouldn't waste time computing diagnostics for these non open files
This commit is contained in:
parent
963c961b59
commit
369252a027
|
@ -241,6 +241,8 @@ export abstract class DiagnosticReporter extends Disposable {
|
|||
|
||||
public abstract delete(uri: vscode.Uri): void;
|
||||
|
||||
public abstract areDiagnosticsEnabled(uri: vscode.Uri): boolean;
|
||||
|
||||
public addWorkItem(promise: Promise<any>): Promise<any> {
|
||||
this.pending.add(promise);
|
||||
promise.finally(() => this.pending.delete(promise));
|
||||
|
@ -253,7 +255,6 @@ export abstract class DiagnosticReporter extends Disposable {
|
|||
}
|
||||
|
||||
export class DiagnosticCollectionReporter extends DiagnosticReporter {
|
||||
|
||||
private readonly collection: vscode.DiagnosticCollection;
|
||||
|
||||
constructor() {
|
||||
|
@ -267,8 +268,12 @@ export class DiagnosticCollectionReporter extends DiagnosticReporter {
|
|||
}
|
||||
|
||||
public set(uri: vscode.Uri, diagnostics: readonly vscode.Diagnostic[]): void {
|
||||
this.collection.set(uri, this.areDiagnosticsEnabled(uri) ? diagnostics : []);
|
||||
}
|
||||
|
||||
public areDiagnosticsEnabled(uri: vscode.Uri): boolean {
|
||||
const tabs = this.getAllTabResources();
|
||||
this.collection.set(uri, tabs.has(uri) ? diagnostics : []);
|
||||
return tabs.has(uri);
|
||||
}
|
||||
|
||||
public delete(uri: vscode.Uri): void {
|
||||
|
@ -331,6 +336,7 @@ export class DiagnosticManager extends Disposable {
|
|||
this.reporter.delete(uri);
|
||||
}));
|
||||
|
||||
|
||||
this._register(this.linkWatcher.onDidChangeLinkedToFile(changedDocuments => {
|
||||
for (const resource of changedDocuments) {
|
||||
const doc = vscode.workspace.textDocuments.find(doc => doc.uri.toString() === resource.toString());
|
||||
|
@ -377,9 +383,14 @@ export class DiagnosticManager extends Disposable {
|
|||
const doc = await this.workspaceContents.getOrLoadMarkdownDocument(resource);
|
||||
if (doc) {
|
||||
await this.inFlightDiagnostics.trigger(doc.uri, async (token) => {
|
||||
const state = await this.recomputeDiagnosticState(doc, token);
|
||||
this.linkWatcher.updateLinksForDocument(doc.uri, state.config.enabled && state.config.validateFileLinks ? state.links : []);
|
||||
this.reporter.set(doc.uri, state.diagnostics);
|
||||
if (this.reporter.areDiagnosticsEnabled(doc.uri)) {
|
||||
const state = await this.recomputeDiagnosticState(doc, token);
|
||||
this.linkWatcher.updateLinksForDocument(doc.uri, state.config.enabled && state.config.validateFileLinks ? state.links : []);
|
||||
this.reporter.set(doc.uri, state.diagnostics);
|
||||
} else {
|
||||
this.linkWatcher.deleteDocument(doc.uri);
|
||||
this.reporter.delete(doc.uri);
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
@ -392,6 +403,8 @@ export class DiagnosticManager extends Disposable {
|
|||
|
||||
return this.reporter.addWorkItem(
|
||||
(async () => {
|
||||
// TODO: This pulls in all md files in the workspace. Instead we only care about opened text documents.
|
||||
// Need a new way to handle that.
|
||||
const allDocs = await this.workspaceContents.getAllMarkdownDocuments();
|
||||
await Promise.all(Array.from(allDocs, doc => this.triggerDiagnostics(doc.uri)));
|
||||
})()
|
||||
|
|
|
@ -75,6 +75,7 @@ class MemoryDiagnosticConfiguration implements DiagnosticConfiguration {
|
|||
}
|
||||
|
||||
class MemoryDiagnosticReporter extends DiagnosticReporter {
|
||||
|
||||
private readonly diagnostics = new ResourceMap<readonly vscode.Diagnostic[]>();
|
||||
|
||||
override dispose(): void {
|
||||
|
@ -91,6 +92,10 @@ class MemoryDiagnosticReporter extends DiagnosticReporter {
|
|||
this.diagnostics.set(uri, diagnostics);
|
||||
}
|
||||
|
||||
areDiagnosticsEnabled(_uri: vscode.Uri): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
delete(uri: vscode.Uri): void {
|
||||
this.diagnostics.delete(uri);
|
||||
}
|
||||
|
|
|
@ -147,6 +147,9 @@ export class VsCodeMdWorkspaceContents extends Disposable implements MdWorkspace
|
|||
|
||||
this._register(vscode.workspace.onDidOpenTextDocument(e => {
|
||||
this._documentCache.delete(e.uri);
|
||||
if (this.isRelevantMarkdownDocument(e)) {
|
||||
this._onDidCreateMarkdownDocumentEmitter.fire(e);
|
||||
}
|
||||
}));
|
||||
|
||||
this._register(vscode.workspace.onDidChangeTextDocument(e => {
|
||||
|
|
Loading…
Reference in a new issue