Re #261. Update comments only when visible editor changes.

This commit is contained in:
rebornix
2018-10-11 17:05:04 -07:00
parent 8476cae78a
commit e05b33163c

View File

@@ -26,6 +26,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
private _workspaceProviders = new Map<number, IDisposable>();
private _firstSessionStart: boolean;
private _visibleModels: { [key /** editor widget id */: string]: string /** model id */ };
constructor(
extHostContext: IExtHostContext,
@IEditorService private _editorService: IEditorService,
@@ -36,14 +37,41 @@ export class MainThreadComments extends Disposable implements MainThreadComments
super();
this._disposables = [];
this._firstSessionStart = true;
this._visibleModels = {};
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
this._disposables.push(this._editorService.onDidActiveEditorChange(e => {
this._disposables.push(this._editorService.onDidVisibleEditorsChange(e => {
const editors = this.getFocusedEditors();
const visibleEditors = this.getVisibleEditors();
const _visibleEditors = {};
visibleEditors.forEach(editor => {
const id = editor.getId();
if (editors.filter(ed => ed.getId() === id).length > 0) {
// it's an active editor, we are going to update this editor's comments anyways
} else {
if (this._visibleModels[id]) {
// it's the same active editor, but we may want to check if the model is still the same
let modelId = editor.getModel().getModeId();
if (modelId !== this._visibleModels[id]) {
editors.push(editor);
}
} else {
// update
editors.push(editor);
}
}
_visibleEditors[id] = editor.getModel().getModeId();
});
this._visibleModels = _visibleEditors;
if (!editors || !editors.length) {
return;
}
editors.forEach(editor => {
console.log(editor.getId());
const controller = ReviewController.get(editor);
if (!controller) {
return;
@@ -119,12 +147,21 @@ export class MainThreadComments extends Disposable implements MainThreadComments
this._commentService.updateComments(event);
}
dispose(): void {
this._disposables = dispose(this._disposables);
this._workspaceProviders.forEach(value => dispose(value));
this._workspaceProviders.clear();
this._documentProviders.forEach(value => dispose(value));
this._documentProviders.clear();
getVisibleEditors(): ICodeEditor[] {
let ret = [];
this._editorService.visibleControls.forEach(control => {
if (isCodeEditor(control.getControl())) {
ret.push(control.getControl() as ICodeEditor);
}
if (isDiffEditor(control.getControl())) {
let diffEditor = control.getControl() as IDiffEditor;
ret.push(diffEditor.getOriginalEditor(), diffEditor.getModifiedEditor());
}
});
return ret;
}
getFocusedEditors(): ICodeEditor[] {
@@ -163,4 +200,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments
}
return result;
}
dispose(): void {
this._disposables = dispose(this._disposables);
this._workspaceProviders.forEach(value => dispose(value));
this._workspaceProviders.clear();
this._documentProviders.forEach(value => dispose(value));
this._documentProviders.clear();
this._visibleModels = {};
}
}