mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 12:04:04 +01:00
menu items
This commit is contained in:
@@ -25,6 +25,8 @@ import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'v
|
||||
import { IRange, Range } from 'vs/editor/common/core/range';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys';
|
||||
|
||||
export class MainThreadDocumentCommentProvider implements modes.DocumentCommentProvider {
|
||||
private readonly _proxy: ExtHostCommentsShape;
|
||||
@@ -247,6 +249,10 @@ export class MainThreadCommentController {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get contextValue(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get proxy(): ExtHostCommentsShape {
|
||||
return this._proxy;
|
||||
}
|
||||
@@ -377,31 +383,26 @@ export class MainThreadCommentController {
|
||||
}
|
||||
|
||||
let commentingRanges = await this._proxy.$provideCommentingRanges(this.handle, resource, token);
|
||||
let staticContribution = await this._proxy.$checkStaticContribution(this.handle);
|
||||
|
||||
return <ICommentInfo>{
|
||||
owner: this._uniqueId,
|
||||
label: this.label,
|
||||
threads: ret,
|
||||
commentingRanges: commentingRanges ?
|
||||
{
|
||||
resource: resource, ranges: commentingRanges, newCommentThreadCallback: async (uri: UriComponents, range: IRange) => {
|
||||
let threadHandle = await this._proxy.$createNewCommentWidgetCallback(this.handle, uri, range, token);
|
||||
commentingRanges: commentingRanges ? {
|
||||
resource: resource,
|
||||
ranges: commentingRanges,
|
||||
newCommentThreadCallback: staticContribution ? undefined : async (uri: UriComponents, range: IRange) => {
|
||||
let threadHandle = await this._proxy.$createNewCommentWidgetCallback(this.handle, uri, range, token);
|
||||
|
||||
if (threadHandle !== undefined) {
|
||||
return this.getKnownThread(threadHandle);
|
||||
}
|
||||
|
||||
return;
|
||||
if (threadHandle !== undefined) {
|
||||
return this.getKnownThread(threadHandle);
|
||||
}
|
||||
} : [],
|
||||
draftMode: modes.DraftMode.NotSupported,
|
||||
template: this._features.commentThreadTemplate ? {
|
||||
controllerHandle: this.handle,
|
||||
label: this._features.commentThreadTemplate.label,
|
||||
acceptInputCommand: this._features.commentThreadTemplate.acceptInputCommand,
|
||||
additionalCommands: this._features.commentThreadTemplate.additionalCommands,
|
||||
deleteCommand: this._features.commentThreadTemplate.deleteCommand
|
||||
} : undefined
|
||||
|
||||
return;
|
||||
}
|
||||
} : [],
|
||||
draftMode: modes.DraftMode.NotSupported
|
||||
};
|
||||
}
|
||||
|
||||
@@ -427,26 +428,8 @@ export class MainThreadCommentController {
|
||||
return ret;
|
||||
}
|
||||
|
||||
getCommentThreadFromTemplate(resource: UriComponents, range: IRange): MainThreadCommentThread {
|
||||
let thread = new MainThreadCommentThread(
|
||||
-1,
|
||||
this.handle,
|
||||
'',
|
||||
'',
|
||||
URI.revive(resource).toString(),
|
||||
range
|
||||
);
|
||||
|
||||
let template = this._features.commentThreadTemplate;
|
||||
|
||||
if (template) {
|
||||
thread.acceptInputCommand = template.acceptInputCommand;
|
||||
thread.additionalCommands = template.additionalCommands;
|
||||
thread.deleteCommand = template.deleteCommand;
|
||||
thread.label = template.label;
|
||||
}
|
||||
|
||||
return thread;
|
||||
createCommentThreadTemplate(resource: UriComponents, range: IRange): void {
|
||||
this._proxy.$createCommentThreadTemplate(this.handle, resource, range);
|
||||
}
|
||||
|
||||
toJSON(): any {
|
||||
@@ -471,18 +454,27 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
private _input?: modes.CommentInput;
|
||||
private _openPanelListener: IDisposable | null;
|
||||
|
||||
private _commentThreadEmpty: IContextKey<boolean>;
|
||||
private _commentEmpty: IContextKey<boolean>;
|
||||
|
||||
constructor(
|
||||
extHostContext: IExtHostContext,
|
||||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@ICommentService private readonly _commentService: ICommentService,
|
||||
@IPanelService private readonly _panelService: IPanelService,
|
||||
@ITelemetryService private readonly _telemetryService: ITelemetryService,
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService
|
||||
@IConfigurationService private readonly _configurationService: IConfigurationService,
|
||||
) {
|
||||
super();
|
||||
this._disposables = [];
|
||||
this._activeCommentThreadDisposables = [];
|
||||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments);
|
||||
|
||||
this._commentThreadEmpty = CommentContextKeys.commentThreadIsEmpty.bindTo(_commentService.contextKeyService);
|
||||
this._commentEmpty = CommentContextKeys.commentIsEmpty.bindTo(_commentService.contextKeyService);
|
||||
this._commentThreadEmpty.set(true);
|
||||
this._commentEmpty.set(true);
|
||||
|
||||
this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => {
|
||||
let handle = (thread as MainThreadCommentThread).controllerHandle;
|
||||
let controller = this._commentControllers.get(handle);
|
||||
@@ -495,9 +487,12 @@ export class MainThreadComments extends Disposable implements MainThreadComments
|
||||
this._activeCommentThread = thread as MainThreadCommentThread;
|
||||
controller.activeCommentThread = this._activeCommentThread;
|
||||
|
||||
this._commentThreadEmpty.set(controller.activeCommentThread.comments!.length === 0);
|
||||
|
||||
this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose
|
||||
this._input = input;
|
||||
this._proxy.$onCommentWidgetInputChange(handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread!.range, this._input ? this._input.value : undefined);
|
||||
this._commentEmpty.set(this._input ? true : this._input!.value.length === 0);
|
||||
}));
|
||||
|
||||
await this._proxy.$onActiveCommentThreadChange(controller.handle, controller.activeCommentThread.commentThreadHandle);
|
||||
|
||||
@@ -1210,9 +1210,11 @@ export interface ExtHostProgressShape {
|
||||
export interface ExtHostCommentsShape {
|
||||
$provideDocumentComments(handle: number, document: UriComponents): Promise<modes.CommentInfo | null>;
|
||||
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread | null>;
|
||||
$createCommentThreadTemplate(commentControllerHandle: number, uriComponents: UriComponents, range: IRange): void;
|
||||
$onCommentWidgetInputChange(commentControllerHandle: number, document: UriComponents, range: IRange, input: string | undefined): Promise<number | undefined>;
|
||||
$onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number | undefined): Promise<number | undefined>;
|
||||
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
|
||||
$checkStaticContribution(commentControllerHandle: number): Promise<boolean>;
|
||||
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>;
|
||||
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>;
|
||||
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): Promise<void>;
|
||||
|
||||
@@ -88,6 +88,16 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
return commentController;
|
||||
}
|
||||
|
||||
$createCommentThreadTemplate(commentControllerHandle: number, uriComponents: UriComponents, range: IRange): void {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController) {
|
||||
return;
|
||||
}
|
||||
|
||||
commentController.$createCommentThreadTemplate(uriComponents, range);
|
||||
}
|
||||
|
||||
$onCommentWidgetInputChange(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, input: string): Promise<number | undefined> {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
@@ -164,7 +174,7 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread)) {
|
||||
if (!(commentController as any).emptyCommentThreadFactory) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -173,13 +183,23 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
if ((commentController as any).emptyCommentThreadFactory) {
|
||||
return (commentController as any).emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
|
||||
}
|
||||
|
||||
if (commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread) {
|
||||
return commentController.commentingRangeProvider.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
|
||||
}
|
||||
}).then(() => Promise.resolve());
|
||||
}
|
||||
|
||||
$checkStaticContribution(commentControllerHandle: number): Promise<boolean> {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (!(commentController as any).emptyCommentThreadFactory) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
registerWorkspaceCommentProvider(
|
||||
extensionId: ExtensionIdentifier,
|
||||
provider: vscode.WorkspaceCommentProvider
|
||||
@@ -618,30 +638,6 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
|
||||
commentingRangeProvider?: vscode.CommentingRangeProvider & { createEmptyCommentThread: (document: vscode.TextDocument, range: types.Range) => Promise<vscode.CommentThread>; };
|
||||
|
||||
private _template: vscode.CommentThreadTemplate | undefined;
|
||||
|
||||
get template(): vscode.CommentThreadTemplate | undefined {
|
||||
return this._template;
|
||||
}
|
||||
|
||||
set template(newTemplate: vscode.CommentThreadTemplate | undefined) {
|
||||
this._template = newTemplate;
|
||||
|
||||
if (newTemplate) {
|
||||
const acceptInputCommand = newTemplate.acceptInputCommand ? this._commandsConverter.toInternal(newTemplate.acceptInputCommand) : undefined;
|
||||
const additionalCommands = newTemplate.additionalCommands ? newTemplate.additionalCommands.map(x => this._commandsConverter.toInternal(x)) : [];
|
||||
const deleteCommand = newTemplate.deleteCommand ? this._commandsConverter.toInternal(newTemplate.deleteCommand) : undefined;
|
||||
this._proxy.$updateCommentControllerFeatures(this.handle, {
|
||||
commentThreadTemplate: {
|
||||
label: newTemplate.label,
|
||||
acceptInputCommand,
|
||||
additionalCommands,
|
||||
deleteCommand
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private _commentReactionProvider?: vscode.CommentReactionProvider;
|
||||
|
||||
get reactionProvider(): vscode.CommentReactionProvider | undefined {
|
||||
@@ -666,8 +662,23 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
this._proxy.$registerCommentController(this.handle, _id, _label);
|
||||
}
|
||||
|
||||
createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread {
|
||||
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, id, resource, range, comments);
|
||||
createCommentThread(resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread;
|
||||
createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[]): vscode.CommentThread;
|
||||
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._proxy, this._commandsConverter, this, arg0, arg1 as vscode.Uri, arg2 as vscode.Range, arg3 as vscode.Comment[]);
|
||||
this._threads.set(commentThread.handle, commentThread);
|
||||
return commentThread;
|
||||
} else {
|
||||
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, '', arg0 as vscode.Uri, arg1 as vscode.Range, arg2 as vscode.Comment[]);
|
||||
this._threads.set(commentThread.handle, commentThread);
|
||||
return commentThread;
|
||||
}
|
||||
}
|
||||
|
||||
$createCommentThreadTemplate(uriComponents: UriComponents, range: IRange) {
|
||||
const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this, '', URI.revive(uriComponents), extHostTypeConverter.Range.to(range), []);
|
||||
commentThread.collapsibleState = modes.CommentThreadCollapsibleState.Expanded;
|
||||
this._threads.set(commentThread.handle, commentThread);
|
||||
return commentThread;
|
||||
}
|
||||
@@ -759,7 +770,8 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
|
||||
count: reaction.count,
|
||||
hasReacted: reaction.hasReacted
|
||||
};
|
||||
}) : undefined
|
||||
}) : undefined,
|
||||
mode: comment.mode ? comment.mode : modes.CommentMode.Preview
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2297,6 +2297,12 @@ export enum CommentThreadCollapsibleState {
|
||||
*/
|
||||
Expanded = 1
|
||||
}
|
||||
|
||||
export enum CommentMode {
|
||||
Editing = 0,
|
||||
Preview = 1
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@es5ClassCompat
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace schema {
|
||||
case 'statusBar/windowIndicator': return MenuId.StatusBarWindowIndicatorMenu;
|
||||
case 'view/title': return MenuId.ViewTitle;
|
||||
case 'view/item/context': return MenuId.ViewItemContext;
|
||||
case 'commentThread/title': return MenuId.CommentThreadTitle;
|
||||
case 'commentThread/actions': return MenuId.CommentThreadActions;
|
||||
case 'comment/title': return MenuId.CommentTitle;
|
||||
case 'comment/actions': return MenuId.CommentActions;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@@ -182,7 +186,27 @@ namespace schema {
|
||||
description: localize('view.itemContext', "The contributed view item context menu"),
|
||||
type: 'array',
|
||||
items: menuItem
|
||||
}
|
||||
},
|
||||
'commentThread/title': {
|
||||
description: localize('commentThread.title', "The contributed comment thread title menu"),
|
||||
type: 'array',
|
||||
items: menuItem
|
||||
},
|
||||
'commentThread/actions': {
|
||||
description: localize('commentThread.actions', "The contributed comment thread actions"),
|
||||
type: 'array',
|
||||
items: menuItem
|
||||
},
|
||||
'comment/title': {
|
||||
description: localize('comment.title', "The contributed comment title menu"),
|
||||
type: 'array',
|
||||
items: menuItem
|
||||
},
|
||||
'comment/actions': {
|
||||
description: localize('comment.actions', "The contributed comment actions"),
|
||||
type: 'array',
|
||||
items: menuItem
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -771,6 +771,7 @@ export function createApiFactory(
|
||||
ColorInformation: extHostTypes.ColorInformation,
|
||||
ColorPresentation: extHostTypes.ColorPresentation,
|
||||
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState,
|
||||
CommentMode: extHostTypes.CommentMode,
|
||||
CompletionItem: extHostTypes.CompletionItem,
|
||||
CompletionItemKind: extHostTypes.CompletionItemKind,
|
||||
CompletionList: extHostTypes.CompletionList,
|
||||
|
||||
Reference in New Issue
Block a user