mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
less verbose comment controller api
This commit is contained in:
@@ -130,6 +130,19 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
|
||||
private _onDidChangeRange = new Emitter<IRange>();
|
||||
public onDidChangeRange = this._onDidChangeRange.event;
|
||||
|
||||
get collapsibleState() {
|
||||
return this._collapsibleState;
|
||||
}
|
||||
|
||||
set collapsibleState(newState: modes.CommentThreadCollapsibleState) {
|
||||
this._collapsibleState = newState;
|
||||
|
||||
}
|
||||
|
||||
private _onDidChangeCollasibleState = new Emitter<modes.CommentThreadCollapsibleState>();
|
||||
public onDidChangeCollasibleState = this._onDidChangeCollasibleState.event;
|
||||
|
||||
|
||||
constructor(
|
||||
public commentThreadHandle: number,
|
||||
public controller: MainThreadCommentController,
|
||||
@@ -139,7 +152,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
|
||||
private _range: IRange,
|
||||
private _comments: modes.Comment[],
|
||||
private _acceptInputCommands: modes.Command[],
|
||||
public collapsibleState?: modes.CommentThreadCollapsibleState,
|
||||
private _collapsibleState: modes.CommentThreadCollapsibleState
|
||||
) {
|
||||
|
||||
}
|
||||
@@ -210,6 +223,7 @@ export class MainThreadCommentController {
|
||||
}
|
||||
|
||||
private _threads: Map<number, MainThreadCommentThread> = new Map<number, MainThreadCommentThread>();
|
||||
private _activeCommentThread?: MainThreadCommentThread;
|
||||
private _commentingRanges: Map<number, MainThreadCommentingRanges> = new Map<number, MainThreadCommentingRanges>();
|
||||
constructor(
|
||||
private _proxy: ExtHostCommentsShape,
|
||||
@@ -299,15 +313,21 @@ export class MainThreadCommentController {
|
||||
thread.acceptInputCommands = acceptInputCommands;
|
||||
}
|
||||
|
||||
updateCollapsibleState(commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState) {
|
||||
let thread = this._threads.get(commentThreadHandle);
|
||||
thread.collapsibleState = collapseState;
|
||||
}
|
||||
|
||||
updateCommentThreadRange(commentThreadHandle: number, range: IRange) {
|
||||
let thread = this._threads.get(commentThreadHandle);
|
||||
thread.range = range;
|
||||
}
|
||||
|
||||
updateInput(commentThreadHandle: number, input: string) {
|
||||
let thread = this._threads.get(commentThreadHandle);
|
||||
let commentInput = thread.input;
|
||||
if (commentInput) {
|
||||
updateInput(input: string) {
|
||||
let thread = this._activeCommentThread;
|
||||
|
||||
if (thread && thread.input) {
|
||||
let commentInput = thread.input;
|
||||
commentInput.value = input;
|
||||
thread.input = commentInput;
|
||||
}
|
||||
@@ -355,7 +375,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
private _commentControllers = new Map<number, MainThreadCommentController>();
|
||||
|
||||
private _activeCommentThread?: MainThreadCommentThread;
|
||||
private _activeComment?: modes.Comment;
|
||||
private _input?: modes.CommentInput;
|
||||
private _openPanelListener: IDisposable | null;
|
||||
|
||||
@@ -383,10 +402,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
|
||||
this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose
|
||||
this._input = input;
|
||||
this._proxy.$onActiveCommentWidgetChange(controller.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined);
|
||||
this._proxy.$onCommentWidgetInputChange(controller.handle, this._input ? this._input.value : undefined);
|
||||
}));
|
||||
|
||||
await this._proxy.$onActiveCommentWidgetChange(controller.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined);
|
||||
await this._proxy.$onCommentWidgetInputChange(controller.handle, this._input ? this._input.value : undefined);
|
||||
}));
|
||||
|
||||
this._disposables.push(this._commentService.onDidChangeActiveCommentingRange(value => {
|
||||
@@ -481,15 +500,14 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
provider.updateComments(commentThreadHandle, comments);
|
||||
}
|
||||
|
||||
$setInputValue(handle: number, commentThreadHandle: number, input: string) {
|
||||
$setInputValue(handle: number, input: string) {
|
||||
let provider = this._commentControllers.get(handle);
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.updateInput(commentThreadHandle, input);
|
||||
|
||||
provider.updateInput(input);
|
||||
}
|
||||
|
||||
$updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]) {
|
||||
@@ -502,6 +520,16 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
provider.updateAcceptInputCommands(commentThreadHandle, acceptInputCommands);
|
||||
}
|
||||
|
||||
$updateCommentThreadCollapsibleState(handle: number, commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState): void {
|
||||
let provider = this._commentControllers.get(handle);
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.updateCollapsibleState(commentThreadHandle, collapseState);
|
||||
}
|
||||
|
||||
$updateCommentThreadRange(handle: number, commentThreadHandle: number, range: any): void {
|
||||
let provider = this._commentControllers.get(handle);
|
||||
|
||||
|
||||
@@ -127,8 +127,9 @@ export interface MainThreadCommentsShape extends IDisposable {
|
||||
$deleteCommentingRanges(handle: number, commentingRangesHandle: number): void;
|
||||
$updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void;
|
||||
$updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, command: modes.Command): void;
|
||||
$setInputValue(handle: number, commentThreadHandle: number, input: string): void;
|
||||
$setInputValue(handle: number, input: string): void;
|
||||
$updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]): void;
|
||||
$updateCommentThreadCollapsibleState(handle: number, commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState): void;
|
||||
$updateCommentThreadRange(handle: number, commentThreadHandle: number, range: IRange): void;
|
||||
$registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void;
|
||||
$unregisterDocumentCommentProvider(handle: number): void;
|
||||
@@ -1105,7 +1106,7 @@ export interface ExtHostProgressShape {
|
||||
export interface ExtHostCommentsShape {
|
||||
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo>;
|
||||
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread>;
|
||||
$onActiveCommentWidgetChange(commentControllerHandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise<number | undefined>;
|
||||
$onCommentWidgetInputChange(commentControllerHandle: number, input: string): Promise<number | undefined>;
|
||||
$onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange): void;
|
||||
$replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise<modes.CommentThread>;
|
||||
$editComment(handle: number, document: UriComponents, comment: modes.Comment, text: string): Promise<void>;
|
||||
|
||||
@@ -87,28 +87,17 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
return commentController;
|
||||
}
|
||||
|
||||
$onActiveCommentWidgetChange(commentControllerHandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise<number | undefined> {
|
||||
$onCommentWidgetInputChange(commentControllerHandle: number, input: string): Promise<number | undefined> {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
commentController.$onActiveCommentWidgetChange(commentThread, comment, input);
|
||||
commentController.$onCommentWidgetInputChange(input);
|
||||
return Promise.resolve(commentControllerHandle);
|
||||
}
|
||||
|
||||
$onCommentWidgetInputChange(commentControllerHandle: number, value: string): Promise<void> {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController || !commentController.widget) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
commentController.widget.input = value;
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
$onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange) {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
@@ -304,6 +293,8 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
return this._range;
|
||||
}
|
||||
|
||||
private _comments: vscode.Comment[] = [];
|
||||
|
||||
get comments(): vscode.Comment[] {
|
||||
return this._comments;
|
||||
}
|
||||
@@ -313,6 +304,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
this._comments = newComments;
|
||||
}
|
||||
|
||||
private _acceptInputCommands: vscode.Command[] = [];
|
||||
get acceptInputCommands(): vscode.Command[] {
|
||||
return this._acceptInputCommands;
|
||||
}
|
||||
@@ -324,17 +316,25 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
this._proxy.$updateCommentThreadCommands(this._commentControlHandle, this.handle, internals);
|
||||
}
|
||||
|
||||
collapsibleState?: vscode.CommentThreadCollapsibleState;
|
||||
private _collapseState?: vscode.CommentThreadCollapsibleState = vscode.CommentThreadCollapsibleState.Collapsed;
|
||||
|
||||
get collapsibleState(): vscode.CommentThreadCollapsibleState {
|
||||
return this._collapseState;
|
||||
}
|
||||
|
||||
set collapsibleState(newState: vscode.CommentThreadCollapsibleState) {
|
||||
this._collapseState = newState;
|
||||
this._proxy.$updateCommentThreadCollapsibleState(this._commentControlHandle, this.handle, newState);
|
||||
|
||||
}
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadCommentsShape,
|
||||
private readonly _commandsConverter: CommandsConverter,
|
||||
private _commentControlHandle: number,
|
||||
private _threadId: string,
|
||||
private _resource: vscode.Uri,
|
||||
private _range: vscode.Range,
|
||||
private _comments: vscode.Comment[],
|
||||
private _acceptInputCommands: vscode.Command[],
|
||||
private _collapseState?: vscode.CommentThreadCollapsibleState
|
||||
private _range: vscode.Range
|
||||
) {
|
||||
this._proxy.$createCommentThread(
|
||||
this._commentControlHandle,
|
||||
@@ -366,35 +366,35 @@ export class ExtHostCommentThread implements vscode.CommentThread {
|
||||
}
|
||||
|
||||
}
|
||||
export class ExtHostCommentWidget implements vscode.CommentWidget {
|
||||
|
||||
private _onDidChangeInput = new Emitter<string>();
|
||||
export class ExtHostCommentInputBox implements vscode.CommentInputBox {
|
||||
private _onDidChangeValue = new Emitter<string>();
|
||||
|
||||
get onDidChangeInput(): Event<string> {
|
||||
return this._onDidChangeInput.event;
|
||||
get onDidChangeValue(): Event<string> {
|
||||
return this._onDidChangeValue.event;
|
||||
}
|
||||
private _value: string = '';
|
||||
get value(): string {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
private _input: string = '';
|
||||
get input(): string {
|
||||
return this._input;
|
||||
}
|
||||
|
||||
set input(newInput: string) {
|
||||
this._input = newInput;
|
||||
this._onDidChangeInput.fire(this._input);
|
||||
this._proxy.$setInputValue(this.commentControlHandle, this.commentThread.handle, newInput);
|
||||
set value(newInput: string) {
|
||||
this._value = newInput;
|
||||
this._onDidChangeValue.fire(this._value);
|
||||
this._proxy.$setInputValue(this.commentControllerHandle, newInput);
|
||||
}
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadCommentsShape,
|
||||
|
||||
public commentControlHandle: number,
|
||||
|
||||
public commentThread: ExtHostCommentThread,
|
||||
public comment: vscode.Comment | undefined,
|
||||
public commentControllerHandle: number,
|
||||
input: string
|
||||
) {
|
||||
this._input = input;
|
||||
this._value = input;
|
||||
}
|
||||
|
||||
setInput(input: string) {
|
||||
this._value = input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +457,7 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
return this._label;
|
||||
}
|
||||
|
||||
public widget?: ExtHostCommentWidget;
|
||||
public inputBox?: ExtHostCommentInputBox;
|
||||
public activeCommentingRange?: vscode.Range;
|
||||
|
||||
public get handle(): number {
|
||||
@@ -478,24 +478,18 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
this._proxy.$registerCommentController(this.handle, _id, _label);
|
||||
}
|
||||
|
||||
createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[], acceptInputCommands: vscode.Command[], collapsibleState?: vscode.CommentThreadCollapsibleState): vscode.CommentThread {
|
||||
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this.handle, id, resource, range, comments, acceptInputCommands, collapsibleState);
|
||||
createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range): vscode.CommentThread {
|
||||
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this.handle, id, resource, range);
|
||||
this._threads.set(commentThread.handle, commentThread);
|
||||
return commentThread;
|
||||
}
|
||||
|
||||
$onActiveCommentWidgetChange(commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string) {
|
||||
let extHostCommentThread = this._threads.get(commentThread.commentThreadHandle);
|
||||
|
||||
const extHostCommentWidget = new ExtHostCommentWidget(
|
||||
this._proxy,
|
||||
this.handle,
|
||||
extHostCommentThread,
|
||||
comment ? extHostCommentThread.getComment(comment.commentId) : undefined,
|
||||
input || ''
|
||||
);
|
||||
|
||||
this.widget = extHostCommentWidget;
|
||||
$onCommentWidgetInputChange(input: string) {
|
||||
if (!this.inputBox) {
|
||||
this.inputBox = new ExtHostCommentInputBox(this._proxy, this.handle, input);
|
||||
} else {
|
||||
this.inputBox.setInput(input);
|
||||
}
|
||||
}
|
||||
|
||||
createCommentingRanges(resource: vscode.Uri, ranges: vscode.Range[], newCommentThreadCommand: vscode.Command): vscode.CommentingRanges {
|
||||
|
||||
Reference in New Issue
Block a user