mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 06:21:50 +01:00
comments contribution takes care of comment fetching itself
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { ICodeEditor, isCodeEditor, isDiffEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
|
||||
import * as modes from 'vs/editor/common/modes';
|
||||
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
|
||||
import { keys } from 'vs/base/common/map';
|
||||
@@ -16,7 +15,6 @@ import { ICommentService } from 'vs/workbench/parts/comments/electron-browser/co
|
||||
import { COMMENTS_PANEL_ID } from 'vs/workbench/parts/comments/electron-browser/commentsPanel';
|
||||
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { ReviewController } from 'vs/workbench/parts/comments/electron-browser/commentsEditorContribution';
|
||||
|
||||
@extHostNamedCustomer(MainContext.MainThreadComments)
|
||||
export class MainThreadComments extends Disposable implements MainThreadCommentsShape {
|
||||
@@ -26,70 +24,16 @@ 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,
|
||||
@ICommentService private _commentService: ICommentService,
|
||||
@IPanelService private _panelService: IPanelService,
|
||||
@ICodeEditorService private _codeEditorService: ICodeEditorService
|
||||
@IPanelService private _panelService: IPanelService
|
||||
) {
|
||||
super();
|
||||
this._disposables = [];
|
||||
this._firstSessionStart = true;
|
||||
this._visibleModels = {};
|
||||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
|
||||
this._disposables.push(this._editorService.onDidVisibleEditorsChange(e => {
|
||||
const editors = this.getFocusedEditors();
|
||||
const visibleEditors = this.getVisibleEditors();
|
||||
|
||||
const _visibleEditors = {};
|
||||
visibleEditors.forEach(editor => {
|
||||
if (!editor.hasModel()) {
|
||||
return; // we need a model
|
||||
}
|
||||
const id = editor.getId();
|
||||
const model = editor.getModel();
|
||||
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 = model.getModeId();
|
||||
if (modelId !== this._visibleModels[id]) {
|
||||
editors.push(editor);
|
||||
}
|
||||
} else {
|
||||
// update
|
||||
editors.push(editor);
|
||||
}
|
||||
}
|
||||
|
||||
_visibleEditors[id] = model.getModeId();
|
||||
});
|
||||
|
||||
this._visibleModels = _visibleEditors;
|
||||
|
||||
if (!editors || !editors.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
editors.forEach(editor => {
|
||||
const controller = ReviewController.get(editor);
|
||||
if (!controller) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!editor.getModel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const outerEditorURI = editor.getModel().uri;
|
||||
this.provideDocumentComments(outerEditorURI).then(commentInfos => {
|
||||
this._commentService.setDocumentComments(outerEditorURI, commentInfos.filter(info => info !== null));
|
||||
});
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
$registerDocumentCommentProvider(handle: number): void {
|
||||
@@ -167,27 +111,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
return ret;
|
||||
}
|
||||
|
||||
getFocusedEditors(): ICodeEditor[] {
|
||||
let activeControl = this._editorService.activeControl;
|
||||
if (activeControl) {
|
||||
if (isCodeEditor(activeControl.getControl())) {
|
||||
return [this._editorService.activeControl.getControl() as ICodeEditor];
|
||||
}
|
||||
|
||||
if (isDiffEditor(activeControl.getControl())) {
|
||||
let diffEditor = activeControl.getControl() as IDiffEditor;
|
||||
return [diffEditor.getOriginalEditor(), diffEditor.getModifiedEditor()];
|
||||
}
|
||||
}
|
||||
|
||||
let editor = this._codeEditorService.getFocusedCodeEditor();
|
||||
|
||||
if (editor) {
|
||||
return [editor];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
async provideWorkspaceComments(): Promise<modes.CommentThread[]> {
|
||||
const result: modes.CommentThread[] = [];
|
||||
for (const handle of keys(this._workspaceProviders)) {
|
||||
@@ -210,6 +133,5 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
this._workspaceProviders.clear();
|
||||
this._documentProviders.forEach(value => dispose(value));
|
||||
this._documentProviders.clear();
|
||||
this._visibleModels = {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user