mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
dispo debt
This commit is contained in:
parent
9a4e70e081
commit
57a405fa50
|
@ -13,7 +13,7 @@ import { registerEditorCommand, EditorCommand } from 'vs/editor/browser/editorEx
|
|||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Disposable, dispose, IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
|
||||
import { dispose, IDisposable, combinedDisposable, DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { localize } from 'vs/nls';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
|
@ -38,8 +38,8 @@ class SymbolNavigationService implements ISymbolNavigationService {
|
|||
|
||||
private _currentModel?: ReferencesModel = undefined;
|
||||
private _currentIdx: number = -1;
|
||||
private _currentDisposables: IDisposable[] = [];
|
||||
private _currentMessage?: IDisposable = undefined;
|
||||
private _currentState?: IDisposable;
|
||||
private _currentMessage?: IDisposable;
|
||||
private _ignoreEditorChange: boolean = false;
|
||||
|
||||
constructor(
|
||||
|
@ -53,7 +53,7 @@ class SymbolNavigationService implements ISymbolNavigationService {
|
|||
|
||||
reset(): void {
|
||||
this._ctxHasSymbols.reset();
|
||||
dispose(this._currentDisposables);
|
||||
dispose(this._currentState);
|
||||
dispose(this._currentMessage);
|
||||
this._currentModel = undefined;
|
||||
this._currentIdx = -1;
|
||||
|
@ -72,8 +72,8 @@ class SymbolNavigationService implements ISymbolNavigationService {
|
|||
this._ctxHasSymbols.set(true);
|
||||
this._showMessage();
|
||||
|
||||
const editorStatus = new EditorStatus(this._editorService);
|
||||
const listener = editorStatus.onDidChange(_ => {
|
||||
const editorState = new EditorState(this._editorService);
|
||||
const listener = editorState.onDidChange(_ => {
|
||||
|
||||
if (this._ignoreEditorChange) {
|
||||
return;
|
||||
|
@ -104,7 +104,7 @@ class SymbolNavigationService implements ISymbolNavigationService {
|
|||
}
|
||||
});
|
||||
|
||||
this._currentDisposables = [editorStatus, listener];
|
||||
this._currentState = combinedDisposable(editorState, listener);
|
||||
}
|
||||
|
||||
revealNext(source: ICodeEditor): Promise<any> {
|
||||
|
@ -182,21 +182,26 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
|
|||
|
||||
//
|
||||
|
||||
class EditorStatus extends Disposable {
|
||||
class EditorState {
|
||||
|
||||
private readonly _listener = new Map<ICodeEditor, IDisposable>();
|
||||
private readonly _disposables = new DisposableStore();
|
||||
|
||||
private readonly _onDidChange = new Emitter<{ editor: ICodeEditor }>();
|
||||
readonly onDidChange: Event<{ editor: ICodeEditor }> = this._onDidChange.event;
|
||||
|
||||
constructor(@ICodeEditorService editorService: ICodeEditorService) {
|
||||
super();
|
||||
this._register(this._onDidChange);
|
||||
this._register(editorService.onCodeEditorRemove(this._onDidRemoveEditor, this));
|
||||
this._register(editorService.onCodeEditorAdd(this._onDidAddEditor, this));
|
||||
this._disposables.add(editorService.onCodeEditorRemove(this._onDidRemoveEditor, this));
|
||||
this._disposables.add(editorService.onCodeEditorAdd(this._onDidAddEditor, this));
|
||||
editorService.listCodeEditors().forEach(this._onDidAddEditor, this);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._disposables.dispose();
|
||||
this._onDidChange.dispose();
|
||||
this._listener.forEach(dispose);
|
||||
}
|
||||
|
||||
private _onDidAddEditor(editor: ICodeEditor): void {
|
||||
this._listener.set(editor, combinedDisposable(
|
||||
editor.onDidChangeCursorPosition(_ => this._onDidChange.fire({ editor })),
|
||||
|
|
Loading…
Reference in a new issue