File level comments API proposal (#177342)

This commit is contained in:
Alex Ross
2023-03-17 10:18:01 +01:00
committed by GitHub
parent bab66d4b77
commit 62e74ad047
14 changed files with 189 additions and 96 deletions

View File

@@ -19,6 +19,7 @@ import * as types from 'vs/workbench/api/common/extHostTypes';
import type * as vscode from 'vscode';
import { ExtHostCommentsShape, IMainContext, MainContext, CommentThreadChanges, CommentChanges } from './extHost.protocol';
import { ExtHostCommands } from './extHostCommands';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
type ProviderHandle = number;
@@ -233,7 +234,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
isTemplate: boolean;
}>;
class ExtHostCommentThread implements vscode.CommentThread {
class ExtHostCommentThread implements vscode.CommentThread2 {
private static _handlePool: number = 0;
readonly handle = ExtHostCommentThread._handlePool++;
public commentHandle: number = 0;
@@ -263,15 +264,15 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
private readonly _onDidUpdateCommentThread = new Emitter<void>();
readonly onDidUpdateCommentThread = this._onDidUpdateCommentThread.event;
set range(range: vscode.Range) {
if (!range.isEqual(this._range)) {
set range(range: vscode.Range | undefined) {
if (((range === undefined) !== (this._range === undefined)) || (!range || !this._range || !range.isEqual(this._range))) {
this._range = range;
this.modifications.range = range;
this._onDidUpdateCommentThread.fire();
}
}
get range(): vscode.Range {
get range(): vscode.Range | undefined {
return this._range;
}
@@ -358,14 +359,14 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
private _acceptInputDisposables = new MutableDisposable<DisposableStore>();
readonly value: vscode.CommentThread;
readonly value: vscode.CommentThread2;
constructor(
commentControllerId: string,
private _commentControllerHandle: number,
private _id: string | undefined,
private _uri: vscode.Uri,
private _range: vscode.Range,
private _range: vscode.Range | undefined,
private _comments: vscode.Comment[],
public readonly extensionDescription: IExtensionDescription,
private _isTemplate: boolean
@@ -409,7 +410,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
this.value = {
get uri() { return that.uri; },
get range() { return that.range; },
set range(value: vscode.Range) { that.range = value; },
set range(value: vscode.Range | undefined) { that.range = value; },
get comments() { return that.comments; },
set comments(value: vscode.Comment[]) { that.comments = value; },
get collapsibleState() { return that.collapsibleState; },
@@ -582,11 +583,11 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
set commentingRangeProvider(commentingRangeProvider: vscode.CommentingRangeProvider | undefined) { that.commentingRangeProvider = commentingRangeProvider; },
get reactionHandler(): ReactionHandler | undefined { return that.reactionHandler; },
set reactionHandler(handler: ReactionHandler | undefined) { that.reactionHandler = handler; },
createCommentThread(uri: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread {
createCommentThread(uri: vscode.Uri, range: vscode.Range | undefined, comments: vscode.Comment[]): vscode.CommentThread | vscode.CommentThread2 {
return that.createCommentThread(uri, range, comments).value;
},
dispose: () => { that.dispose(); },
});
}) as any; // TODO @alexr00 remove this cast when the proposed API is stable
this._localDisposables = [];
this._localDisposables.push({
@@ -596,17 +597,13 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
});
}
createCommentThread(resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): ExtHostCommentThread;
createCommentThread(arg0: vscode.Uri | string, arg1: vscode.Uri | vscode.Range, arg2: vscode.Range | vscode.Comment[], arg3?: vscode.Comment[]): vscode.CommentThread {
if (typeof arg0 === 'string') {
const commentThread = new ExtHostCommentThread(this.id, this.handle, arg0, arg1 as vscode.Uri, arg2 as vscode.Range, arg3 as vscode.Comment[], this._extension, false);
this._threads.set(commentThread.handle, commentThread);
return commentThread;
} else {
const commentThread = new ExtHostCommentThread(this.id, this.handle, undefined, arg0 as vscode.Uri, arg1 as vscode.Range, arg2 as vscode.Comment[], this._extension, false);
this._threads.set(commentThread.handle, commentThread);
return commentThread;
createCommentThread(resource: vscode.Uri, range: vscode.Range | undefined, comments: vscode.Comment[]): ExtHostCommentThread {
if (range === undefined) {
checkProposedApiEnabled(this._extension, 'fileComments');
}
const commentThread = new ExtHostCommentThread(this.id, this.handle, undefined, resource, range, comments, this._extension, false);
this._threads.set(commentThread.handle, commentThread);
return commentThread;
}
$createCommentThreadTemplate(uriComponents: UriComponents, range: IRange): ExtHostCommentThread {