Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove comments when a comment provider is unregistered #180502

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/workbench/api/browser/mainThreadComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
) {
super();
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
this._commentService.unregisterCommentController();

this._register(this._commentService.onDidChangeActiveCommentThread(async thread => {
const handle = (thread as MainThreadCommentThread<IRange | ICellRange>).controllerHandle;
Expand Down
7 changes: 2 additions & 5 deletions src/vs/workbench/api/common/extHostComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { asPromise } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { debounce } from 'vs/base/common/decorators';
import { Emitter } from 'vs/base/common/event';
import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
import { MarshalledId } from 'vs/base/common/marshallingIds';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IRange } from 'vs/editor/common/core/range';
Expand All @@ -31,7 +31,7 @@ interface ExtHostComments {
export function createExtHostComments(mainContext: IMainContext, commands: ExtHostCommands, documents: ExtHostDocuments): ExtHostCommentsShape & ExtHostComments {
const proxy = mainContext.getProxy(MainContext.MainThreadComments);

class ExtHostCommentsImpl implements ExtHostCommentsShape, ExtHostComments, IDisposable {
class ExtHostCommentsImpl implements ExtHostCommentsShape, ExtHostComments {

private static handlePool = 0;

Expand Down Expand Up @@ -244,9 +244,6 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
return Promise.resolve(undefined);
});
}
dispose() {

}
}
type CommentThreadModification = Partial<{
range: vscode.Range;
Expand Down
16 changes: 10 additions & 6 deletions src/vs/workbench/contrib/comments/browser/commentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ export interface ICommentService {
readonly onDidUpdateCommentingRanges: Event<{ owner: string }>;
readonly onDidChangeActiveCommentingRange: Event<{ range: Range; commentingRangesInfo: CommentingRanges }>;
readonly onDidSetDataProvider: Event<void>;
readonly onDidDeleteDataProvider: Event<string>;
readonly onDidDeleteDataProvider: Event<string | undefined>;
readonly onDidChangeCommentingEnabled: Event<boolean>;
readonly isCommentingEnabled: boolean;
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void;
setWorkspaceComments(owner: string, commentsByResource: CommentThread<IRange | ICellRange>[]): void;
removeWorkspaceComments(owner: string): void;
registerCommentController(owner: string, commentControl: ICommentController): void;
unregisterCommentController(owner: string): void;
unregisterCommentController(owner?: string): void;
getCommentController(owner: string): ICommentController | undefined;
createCommentThreadTemplate(owner: string, resource: URI, range: Range | undefined): void;
updateCommentThreadTemplate(owner: string, threadHandle: number, range: Range): Promise<void>;
Expand All @@ -111,8 +111,8 @@ export class CommentService extends Disposable implements ICommentService {
private readonly _onDidSetDataProvider: Emitter<void> = this._register(new Emitter<void>());
readonly onDidSetDataProvider: Event<void> = this._onDidSetDataProvider.event;

private readonly _onDidDeleteDataProvider: Emitter<string> = this._register(new Emitter<string>());
readonly onDidDeleteDataProvider: Event<string> = this._onDidDeleteDataProvider.event;
private readonly _onDidDeleteDataProvider: Emitter<string | undefined> = this._register(new Emitter<string | undefined>());
readonly onDidDeleteDataProvider: Event<string | undefined> = this._onDidDeleteDataProvider.event;

private readonly _onDidSetResourceCommentInfos: Emitter<IResourceCommentThreadEvent> = this._register(new Emitter<IResourceCommentThreadEvent>());
readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent> = this._onDidSetResourceCommentInfos.event;
Expand Down Expand Up @@ -239,8 +239,12 @@ export class CommentService extends Disposable implements ICommentService {
this._onDidSetDataProvider.fire();
}

unregisterCommentController(owner: string): void {
this._commentControls.delete(owner);
unregisterCommentController(owner?: string): void {
if (owner) {
this._commentControls.delete(owner);
} else {
this._commentControls.clear();
}
this._onDidDeleteDataProvider.fire(owner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,13 @@ export class CommentController implements IEditorContribution {
this.globalToDispose.add(this._commentThreadRangeDecorator = new CommentThreadRangeDecorator(this.commentService));

this.globalToDispose.add(this.commentService.onDidDeleteDataProvider(ownerId => {
delete this._pendingNewCommentCache[ownerId];
delete this._pendingEditsCache[ownerId];
if (ownerId) {
delete this._pendingNewCommentCache[ownerId];
delete this._pendingEditsCache[ownerId];
} else {
this._pendingNewCommentCache = {};
this._pendingEditsCache = {};
}
this.beginCompute();
}));
this.globalToDispose.add(this.commentService.onDidSetDataProvider(_ => this.beginCompute()));
Expand Down
9 changes: 9 additions & 0 deletions src/vs/workbench/contrib/comments/browser/commentsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {

this._register(this.commentService.onDidSetAllCommentThreads(this.onAllCommentsChanged, this));
this._register(this.commentService.onDidUpdateCommentThreads(this.onCommentsUpdated, this));
this._register(this.commentService.onDidDeleteDataProvider(this.onDataProviderDeleted, this));

const styleElement = dom.createStyleSheet(container);
this.applyStyles(styleElement);
Expand Down Expand Up @@ -470,6 +471,14 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
}
}

private onDataProviderDeleted(owner: string | undefined): void {
this.cachedFilterStats = undefined;
this.commentsModel.deleteCommentsByOwner(owner);

this.totalComments = 0;
this.refresh();
}

private updateSomeCommentsExpanded() {
this.someCommentsExpandedContextKey.set(this.isSomeCommentsExpanded());
}
Expand Down
9 changes: 9 additions & 0 deletions src/vs/workbench/contrib/comments/common/commentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export class CommentsModel {
this.updateResourceCommentThreads();
}

public deleteCommentsByOwner(owner?: string): void {
if (owner) {
this.commentThreadsMap.set(owner, []);
} else {
this.commentThreadsMap.clear();
}
this.updateResourceCommentThreads();
}

public updateCommentThreads(event: ICommentThreadChangedEvent): boolean {
const { owner, removed, changed, added } = event;

Expand Down