提交 a51d518f 编写于 作者: M Matt Bierner

Strict null check mainThreadComments

上级 1e8d0211
......@@ -1203,7 +1203,7 @@ export interface Command {
* @internal
*/
export interface CommentInfo {
extensionId: string;
extensionId?: string;
threads: CommentThread[];
commentingRanges?: (IRange[] | CommentingRanges);
reply?: Command;
......@@ -1266,8 +1266,8 @@ export interface CommentThread2 {
comments: Comment[];
onDidChangeComments: Event<Comment[]>;
collapsibleState?: CommentThreadCollapsibleState;
input: CommentInput;
onDidChangeInput: Event<CommentInput>;
input: CommentInput | undefined;
onDidChangeInput: Event<CommentInput | undefined>;
acceptInputCommand?: Command;
additionalCommands: Command[];
onDidChangeAcceptInputCommand: Event<Command>;
......@@ -1368,8 +1368,8 @@ export interface CommentThreadChangedEvent {
*/
export interface DocumentCommentProvider {
provideDocumentComments(resource: URI, token: CancellationToken): Promise<CommentInfo>;
createNewCommentThread(resource: URI, range: Range, text: string, token: CancellationToken): Promise<CommentThread>;
replyToCommentThread(resource: URI, range: Range, thread: CommentThread, text: string, token: CancellationToken): Promise<CommentThread>;
createNewCommentThread(resource: URI, range: Range, text: string, token: CancellationToken): Promise<CommentThread | null>;
replyToCommentThread(resource: URI, range: Range, thread: CommentThread, text: string, token: CancellationToken): Promise<CommentThread | null>;
editComment(resource: URI, comment: Comment, text: string, token: CancellationToken): Promise<void>;
deleteComment(resource: URI, comment: Comment, token: CancellationToken): Promise<void>;
startDraft?(resource: URI, token: CancellationToken): Promise<void>;
......
......@@ -127,7 +127,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 {
}
get acceptInputCommand(): modes.Command {
return this._acceptInputCommand;
return this._acceptInputCommand!;
}
private _onDidChangeAcceptInputCommand = new Emitter<modes.Command>();
......@@ -249,7 +249,7 @@ export class MainThreadCommentController {
}
deleteCommentThread(commentThreadHandle: number) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
this._threads.delete(commentThreadHandle);
this._commentService.updateComments(this._uniqueId, {
......@@ -263,7 +263,7 @@ export class MainThreadCommentController {
}
updateComments(commentThreadHandle: number, comments: modes.Comment[]) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
thread.comments = comments;
this._commentService.updateComments(this._uniqueId, {
......@@ -275,27 +275,27 @@ export class MainThreadCommentController {
}
updateAcceptInputCommand(commentThreadHandle: number, acceptInputCommand: modes.Command) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
thread.acceptInputCommand = acceptInputCommand;
}
updateAdditionalCommands(commentThreadHandle: number, additionalCommands: modes.Command[]) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
thread.additionalCommands = additionalCommands;
}
updateCollapsibleState(commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
thread.collapsibleState = collapseState;
}
updateCommentThreadRange(commentThreadHandle: number, range: IRange) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
thread.range = range;
}
updateCommentThreadLabel(commentThreadHandle: number, label: string) {
let thread = this._threads.get(commentThreadHandle);
let thread = this.getKnownThread(commentThreadHandle);
thread.label = label;
}
......@@ -309,11 +309,21 @@ export class MainThreadCommentController {
}
}
private getKnownThread(commentThreadHandle: number) {
const thread = this._threads.get(commentThreadHandle);
if (!thread) {
throw new Error('unknown thread');
}
return thread;
}
async getDocumentComments(resource: URI, token) {
let ret = [];
let ret: modes.CommentThread2[] = [];
for (let thread of keys(this._threads)) {
if (this._threads.get(thread).resource === resource.toString()) {
ret.push(this._threads.get(thread));
const commentThread = this._threads.get(thread)!;
if (commentThread.resource === resource.toString()) {
ret.push(commentThread);
}
}
......@@ -338,9 +348,9 @@ export class MainThreadCommentController {
}
getAllComments(): MainThreadCommentThread[] {
let ret = [];
let ret: MainThreadCommentThread[] = [];
for (let thread of keys(this._threads)) {
ret.push(this._threads.get(thread));
ret.push(this._threads.get(thread)!);
}
return ret;
......@@ -540,17 +550,17 @@ export class MainThreadComments extends Disposable implements MainThreadComments
keys(this._workspaceProviders).forEach(handle => {
this._proxy.$provideWorkspaceComments(handle).then(commentThreads => {
if (commentThreads) {
const providerId = this._handlers.get(handle);
const providerId = this.getHandler(handle);
this._commentService.setWorkspaceComments(providerId, commentThreads);
}
});
});
keys(this._commentControllers).forEach(handle => {
let threads = this._commentControllers.get(handle).getAllComments();
let threads = this._commentControllers.get(handle)!.getAllComments();
if (threads.length) {
const providerId = this._handlers.get(handle);
const providerId = this.getHandler(handle);
this._commentService.setWorkspaceComments(providerId, threads);
}
});
......@@ -564,6 +574,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments
}
}
private getHandler(handle: number) {
if (!this._handlers.has(handle)) {
throw new Error('Unknown handler');
}
return this._handlers.get(handle)!;
}
$registerWorkspaceCommentProvider(handle: number, extensionId: ExtensionIdentifier): void {
this._workspaceProviders.set(handle, undefined);
......@@ -611,7 +628,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
$unregisterDocumentCommentProvider(handle: number): void {
this._documentProviders.delete(handle);
const handlerId = this._handlers.get(handle);
const handlerId = this.getHandler(handle);
this._commentService.unregisterDataProvider(handlerId);
this._handlers.delete(handle);
}
......@@ -627,14 +644,14 @@ export class MainThreadComments extends Disposable implements MainThreadComments
}
}
const handlerId = this._handlers.get(handle);
const handlerId = this.getHandler(handle);
this._commentService.removeWorkspaceComments(handlerId);
this._handlers.delete(handle);
}
$onDidCommentThreadsChange(handle: number, event: modes.CommentThreadChangedEvent) {
// notify comment service
const providerId = this._handlers.get(handle);
const providerId = this.getHandler(handle);
this._commentService.updateComments(providerId, event);
}
......@@ -658,7 +675,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments
async provideWorkspaceComments(): Promise<modes.CommentThread[]> {
const result: modes.CommentThread[] = [];
for (const handle of keys(this._workspaceProviders)) {
result.push(...await this._proxy.$provideWorkspaceComments(handle));
const result = await this._proxy.$provideWorkspaceComments(handle);
if (Array.isArray(result)) {
result.push(...result);
}
}
return result;
}
......
......@@ -1106,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 | null>;
$onCommentWidgetInputChange(commentControllerHandle: number, input: string): Promise<number | undefined>;
$onCommentWidgetInputChange(commentControllerHandle: number, input: string | undefined): Promise<number | undefined>;
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void;
$replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise<modes.CommentThread | null>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册