mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-30 08:40:29 -04:00
Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 (#6381)
* Merge from vscode 8e0f348413f4f616c23a88ae30030efa85811973 * disable strict null check
This commit is contained in:
@@ -3,13 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CommentThread, DocumentCommentProvider, CommentThreadChangedEvent, CommentInfo, Comment, CommentReaction, CommentingRanges, CommentThread2 } from 'vs/editor/common/modes';
|
||||
import { CommentThreadChangedEvent, CommentInfo, Comment, CommentReaction, CommentingRanges, CommentThread } from 'vs/editor/common/modes';
|
||||
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Range, IRange } from 'vs/editor/common/core/range';
|
||||
import { keys } from 'vs/base/common/map';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel';
|
||||
@@ -38,37 +37,27 @@ export interface ICommentService {
|
||||
readonly onDidSetResourceCommentInfos: Event<IResourceCommentThreadEvent>;
|
||||
readonly onDidSetAllCommentThreads: Event<IWorkspaceCommentThreadsEvent>;
|
||||
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent>;
|
||||
readonly onDidChangeActiveCommentThread: Event<CommentThread | null>;
|
||||
readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>;
|
||||
readonly onDidSetDataProvider: Event<void>;
|
||||
readonly onDidDeleteDataProvider: Event<string>;
|
||||
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void;
|
||||
setWorkspaceComments(owner: string, commentsByResource: CommentThread[] | CommentThread2[]): void;
|
||||
setWorkspaceComments(owner: string, commentsByResource: CommentThread[]): void;
|
||||
removeWorkspaceComments(owner: string): void;
|
||||
registerCommentController(owner: string, commentControl: MainThreadCommentController): void;
|
||||
unregisterCommentController(owner: string): void;
|
||||
getCommentController(owner: string): MainThreadCommentController | undefined;
|
||||
createCommentThreadTemplate(owner: string, resource: URI, range: Range): void;
|
||||
updateCommentThreadTemplate(owner: string, threadHandle: number, range: Range): Promise<void>;
|
||||
getCommentMenus(owner: string): CommentMenus;
|
||||
registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void;
|
||||
unregisterDataProvider(owner: string): void;
|
||||
updateComments(ownerId: string, event: CommentThreadChangedEvent): void;
|
||||
disposeCommentThread(ownerId: string, threadId: string): void;
|
||||
createNewCommentThread(owner: string, resource: URI, range: Range, text: string): Promise<CommentThread | null>;
|
||||
replyToCommentThread(owner: string, resource: URI, range: Range, thread: CommentThread, text: string): Promise<CommentThread | null>;
|
||||
editComment(owner: string, resource: URI, comment: Comment, text: string): Promise<void>;
|
||||
deleteComment(owner: string, resource: URI, comment: Comment): Promise<boolean>;
|
||||
getComments(resource: URI): Promise<(ICommentInfo | null)[]>;
|
||||
getCommentingRanges(resource: URI): Promise<IRange[]>;
|
||||
startDraft(owner: string, resource: URI): void;
|
||||
deleteDraft(owner: string, resource: URI): void;
|
||||
finishDraft(owner: string, resource: URI): void;
|
||||
getStartDraftLabel(owner: string): string | undefined;
|
||||
getDeleteDraftLabel(owner: string): string | undefined;
|
||||
getFinishDraftLabel(owner: string): string | undefined;
|
||||
addReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>;
|
||||
deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void>;
|
||||
getReactionGroup(owner: string): CommentReaction[] | undefined;
|
||||
toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise<void>;
|
||||
hasReactionHandler(owner: string): boolean;
|
||||
toggleReaction(owner: string, resource: URI, thread: CommentThread, comment: Comment, reaction: CommentReaction): Promise<void>;
|
||||
setActiveCommentThread(commentThread: CommentThread | null): void;
|
||||
}
|
||||
|
||||
export class CommentService extends Disposable implements ICommentService {
|
||||
@@ -89,6 +78,9 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
private readonly _onDidUpdateCommentThreads: Emitter<ICommentThreadChangedEvent> = this._register(new Emitter<ICommentThreadChangedEvent>());
|
||||
readonly onDidUpdateCommentThreads: Event<ICommentThreadChangedEvent> = this._onDidUpdateCommentThreads.event;
|
||||
|
||||
private readonly _onDidChangeActiveCommentThread = this._register(new Emitter<CommentThread | null>());
|
||||
readonly onDidChangeActiveCommentThread = this._onDidChangeActiveCommentThread.event;
|
||||
|
||||
private readonly _onDidChangeActiveCommentingRange: Emitter<{
|
||||
range: Range, commentingRangesInfo:
|
||||
CommentingRanges
|
||||
@@ -98,8 +90,6 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
}>());
|
||||
readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }> = this._onDidChangeActiveCommentingRange.event;
|
||||
|
||||
private _commentProviders = new Map<string, DocumentCommentProvider>();
|
||||
|
||||
private _commentControls = new Map<string, MainThreadCommentController>();
|
||||
private _commentMenus = new Map<string, CommentMenus>();
|
||||
|
||||
@@ -109,6 +99,10 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
super();
|
||||
}
|
||||
|
||||
setActiveCommentThread(commentThread: CommentThread | null) {
|
||||
this._onDidChangeActiveCommentThread.fire(commentThread);
|
||||
}
|
||||
|
||||
setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void {
|
||||
this._onDidSetResourceCommentInfos.fire({ resource, commentInfos });
|
||||
}
|
||||
@@ -145,6 +139,16 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
commentController.createCommentThreadTemplate(resource, range);
|
||||
}
|
||||
|
||||
async updateCommentThreadTemplate(owner: string, threadHandle: number, range: Range) {
|
||||
const commentController = this._commentControls.get(owner);
|
||||
|
||||
if (!commentController) {
|
||||
return;
|
||||
}
|
||||
|
||||
await commentController.updateCommentThreadTemplate(threadHandle, range);
|
||||
}
|
||||
|
||||
disposeCommentThread(owner: string, threadId: string) {
|
||||
let controller = this.getCommentController(owner);
|
||||
if (controller) {
|
||||
@@ -164,112 +168,12 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
return menu;
|
||||
}
|
||||
|
||||
registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void {
|
||||
this._commentProviders.set(owner, commentProvider);
|
||||
this._onDidSetDataProvider.fire();
|
||||
}
|
||||
|
||||
unregisterDataProvider(owner: string): void {
|
||||
this._commentProviders.delete(owner);
|
||||
this._onDidDeleteDataProvider.fire(owner);
|
||||
}
|
||||
|
||||
updateComments(ownerId: string, event: CommentThreadChangedEvent): void {
|
||||
const evt: ICommentThreadChangedEvent = assign({}, event, { owner: ownerId });
|
||||
this._onDidUpdateCommentThreads.fire(evt);
|
||||
}
|
||||
|
||||
async createNewCommentThread(owner: string, resource: URI, range: Range, text: string): Promise<CommentThread | null> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return await commentProvider.createNewCommentThread(resource, range, text, CancellationToken.None);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
async replyToCommentThread(owner: string, resource: URI, range: Range, thread: CommentThread, text: string): Promise<CommentThread | null> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return await commentProvider.replyToCommentThread(resource, range, thread, text, CancellationToken.None);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
editComment(owner: string, resource: URI, comment: Comment, text: string): Promise<void> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return commentProvider.editComment(resource, comment, text, CancellationToken.None);
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
deleteComment(owner: string, resource: URI, comment: Comment): Promise<boolean> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return commentProvider.deleteComment(resource, comment, CancellationToken.None).then(() => true);
|
||||
}
|
||||
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
async startDraft(owner: string, resource: URI): Promise<void> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider && commentProvider.startDraft) {
|
||||
return commentProvider.startDraft(resource, CancellationToken.None);
|
||||
} else {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
}
|
||||
|
||||
async deleteDraft(owner: string, resource: URI): Promise<void> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider && commentProvider.deleteDraft) {
|
||||
return commentProvider.deleteDraft(resource, CancellationToken.None);
|
||||
} else {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
}
|
||||
|
||||
async finishDraft(owner: string, resource: URI): Promise<void> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider && commentProvider.finishDraft) {
|
||||
return commentProvider.finishDraft(resource, CancellationToken.None);
|
||||
} else {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
}
|
||||
|
||||
async addReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider && commentProvider.addReaction) {
|
||||
return commentProvider.addReaction(resource, comment, reaction, CancellationToken.None);
|
||||
} else {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
}
|
||||
|
||||
async deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise<void> {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider && commentProvider.deleteReaction) {
|
||||
return commentProvider.deleteReaction(resource, comment, reaction, CancellationToken.None);
|
||||
} else {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
}
|
||||
|
||||
async toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise<void> {
|
||||
async toggleReaction(owner: string, resource: URI, thread: CommentThread, comment: Comment, reaction: CommentReaction): Promise<void> {
|
||||
const commentController = this._commentControls.get(owner);
|
||||
|
||||
if (commentController) {
|
||||
@@ -295,57 +199,17 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getStartDraftLabel(owner: string): string | undefined {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
hasReactionHandler(owner: string): boolean {
|
||||
const commentProvider = this._commentControls.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return commentProvider.startDraftLabel;
|
||||
return !!commentProvider.features.reactionHandler;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getDeleteDraftLabel(owner: string): string | undefined {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return commentProvider.deleteDraftLabel;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
getFinishDraftLabel(owner: string): string | undefined {
|
||||
const commentProvider = this._commentProviders.get(owner);
|
||||
|
||||
if (commentProvider) {
|
||||
return commentProvider.finishDraftLabel;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return false;
|
||||
}
|
||||
|
||||
async getComments(resource: URI): Promise<(ICommentInfo | null)[]> {
|
||||
const result: Promise<ICommentInfo | null>[] = [];
|
||||
for (const owner of keys(this._commentProviders)) {
|
||||
const provider = this._commentProviders.get(owner);
|
||||
if (provider && provider.provideDocumentComments) {
|
||||
result.push(provider.provideDocumentComments(resource, CancellationToken.None).then(commentInfo => {
|
||||
if (commentInfo) {
|
||||
return <ICommentInfo>{
|
||||
owner: owner,
|
||||
threads: commentInfo.threads,
|
||||
commentingRanges: commentInfo.commentingRanges,
|
||||
reply: commentInfo.reply,
|
||||
draftMode: commentInfo.draftMode
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
let commentControlResult: Promise<ICommentInfo | null>[] = [];
|
||||
|
||||
this._commentControls.forEach(control => {
|
||||
@@ -356,7 +220,7 @@ export class CommentService extends Disposable implements ICommentService {
|
||||
}));
|
||||
});
|
||||
|
||||
return Promise.all([...result, ...commentControlResult]);
|
||||
return Promise.all(commentControlResult);
|
||||
}
|
||||
|
||||
async getCommentingRanges(resource: URI): Promise<IRange[]> {
|
||||
|
||||
Reference in New Issue
Block a user