mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
Handle delete document
This commit is contained in:
@@ -11,17 +11,21 @@ import MDDocumentSymbolProvider from './documentSymbolProvider';
|
||||
export interface WorkspaceMarkdownDocumentProvider {
|
||||
getAllMarkdownDocuments(): Thenable<vscode.TextDocument[]>;
|
||||
|
||||
onDidChangeMarkdownDocument: vscode.Event<vscode.TextDocument>;
|
||||
readonly onDidChangeMarkdownDocument: vscode.Event<vscode.TextDocument>;
|
||||
readonly onDidDeleteMarkdownDocument: vscode.Event<vscode.Uri>;
|
||||
}
|
||||
|
||||
class VSCodeWorkspaceMarkdownDocumentProvider implements WorkspaceMarkdownDocumentProvider {
|
||||
|
||||
private readonly _onDidChangeMarkdownDocumentEmitter = new vscode.EventEmitter<vscode.TextDocument>();
|
||||
private readonly _onDidDeleteMarkdownDocumentEmitter = new vscode.EventEmitter<vscode.Uri>();
|
||||
|
||||
private _watcher: vscode.FileSystemWatcher | undefined;
|
||||
private _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose() {
|
||||
this._onDidChangeMarkdownDocumentEmitter.dispose();
|
||||
this._onDidDeleteMarkdownDocumentEmitter.dispose();
|
||||
|
||||
if (this._watcher) {
|
||||
this._watcher.dispose();
|
||||
@@ -42,6 +46,11 @@ class VSCodeWorkspaceMarkdownDocumentProvider implements WorkspaceMarkdownDocume
|
||||
return this._onDidChangeMarkdownDocumentEmitter.event;
|
||||
}
|
||||
|
||||
public get onDidDeleteMarkdownDocument() {
|
||||
this.ensureWatcher();
|
||||
return this._onDidDeleteMarkdownDocumentEmitter.event;
|
||||
}
|
||||
|
||||
private ensureWatcher(): void {
|
||||
if (this._watcher) {
|
||||
return;
|
||||
@@ -55,6 +64,10 @@ class VSCodeWorkspaceMarkdownDocumentProvider implements WorkspaceMarkdownDocume
|
||||
this._onDidChangeMarkdownDocumentEmitter.fire(document);
|
||||
}
|
||||
}, this, this._disposables);
|
||||
|
||||
this._watcher.onDidDelete(async resource => {
|
||||
this._onDidDeleteMarkdownDocumentEmitter.fire(resource);
|
||||
}, this, this._disposables);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +87,8 @@ export default class MarkdownWorkspaceSymbolProvider implements vscode.Workspace
|
||||
await this.populateSymbolCache();
|
||||
this._symbolCachePopulated = true;
|
||||
|
||||
this._workspaceMarkdownDocumentProvider.onDidChangeMarkdownDocument(this.onDidChange, this, this._disposables);
|
||||
this._workspaceMarkdownDocumentProvider.onDidChangeMarkdownDocument(this.onDidChangeDocument, this, this._disposables);
|
||||
this._workspaceMarkdownDocumentProvider.onDidDeleteMarkdownDocument(this.onDidDeleteDocument, this, this._disposables);
|
||||
}
|
||||
|
||||
const allSymbolsSets = await Promise.all(Array.from(this._symbolCache.values()));
|
||||
@@ -97,7 +111,11 @@ export default class MarkdownWorkspaceSymbolProvider implements vscode.Workspace
|
||||
return this._symbolProvider.provideDocumentSymbols(document);
|
||||
}
|
||||
|
||||
private onDidChange(document: vscode.TextDocument) {
|
||||
private onDidChangeDocument(document: vscode.TextDocument) {
|
||||
this._symbolCache.set(document.fileName, this.getSymbols(document));
|
||||
}
|
||||
|
||||
private onDidDeleteDocument(resource: vscode.Uri) {
|
||||
this._symbolCache.delete(resource.fsPath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user