Fix some unsafe type assertions (#211918)

Part of #211878
This commit is contained in:
Alex Ross 2024-05-03 13:30:13 +02:00 committed by GitHub
parent 3982027f02
commit 529656f789
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 31 additions and 28 deletions

View file

@ -1782,9 +1782,9 @@ export interface CommentThreadTemplate {
/**
* @internal
*/
export interface CommentInfo {
export interface CommentInfo<T = IRange> {
extensionId?: string;
threads: CommentThread[];
threads: CommentThread<T>[];
pendingCommentThreads?: PendingCommentThread[];
commentingRanges: CommentingRanges;
}

View file

@ -12,7 +12,7 @@ import * as languages from 'vs/editor/common/languages';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { Registry } from 'vs/platform/registry/common/platform';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { ICommentController, ICommentInfo, ICommentService, INotebookCommentInfo } from 'vs/workbench/contrib/comments/browser/commentService';
import { ICommentController, ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
import { CommentsPanel } from 'vs/workbench/contrib/comments/browser/commentsView';
import { CommentProviderFeatures, ExtHostCommentsShape, ExtHostContext, MainContext, MainThreadCommentsShape, CommentThreadChanges } from '../common/extHost.protocol';
import { COMMENTS_VIEW_ID, COMMENTS_VIEW_STORAGE_ID, COMMENTS_VIEW_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
@ -416,46 +416,50 @@ export class MainThreadCommentController implements ICommentController {
};
}
const ret: languages.CommentThread<IRange | ICellRange>[] = [];
const ret: languages.CommentThread<IRange>[] = [];
for (const thread of [...this._threads.keys()]) {
const commentThread = this._threads.get(thread)!;
if (commentThread.resource === resource.toString()) {
ret.push(commentThread);
if (commentThread.isDocumentCommentThread()) {
ret.push(commentThread);
}
}
}
const commentingRanges = await this._proxy.$provideCommentingRanges(this.handle, resource, token);
return <ICommentInfo>{
return {
uniqueOwner: this._uniqueId,
label: this.label,
threads: ret,
commentingRanges: {
resource: resource,
ranges: commentingRanges?.ranges || [],
fileComments: commentingRanges?.fileComments
fileComments: !!commentingRanges?.fileComments
}
};
}
async getNotebookComments(resource: URI, token: CancellationToken) {
if (resource.scheme !== Schemas.vscodeNotebookCell) {
return <INotebookCommentInfo>{
return {
uniqueOwner: this._uniqueId,
label: this.label,
threads: []
};
}
const ret: languages.CommentThread<IRange | ICellRange>[] = [];
const ret: languages.CommentThread<ICellRange>[] = [];
for (const thread of [...this._threads.keys()]) {
const commentThread = this._threads.get(thread)!;
if (commentThread.resource === resource.toString()) {
ret.push(commentThread);
if (!commentThread.isDocumentCommentThread()) {
ret.push(commentThread as languages.CommentThread<ICellRange>);
}
}
}
return <INotebookCommentInfo>{
return {
uniqueOwner: this._uniqueId,
label: this.label,
threads: ret

View file

@ -37,10 +37,10 @@ export function getSockets(stdout: string): Record<string, { pid: number; socket
});
}
});
const socketMap = mapped.reduce((m, socket) => {
const socketMap = mapped.reduce((m: Record<string, typeof mapped[0]>, socket) => {
m[socket.socket] = socket;
return m;
}, {} as Record<string, typeof mapped[0]>);
}, {});
return socketMap;
}
@ -96,10 +96,10 @@ export function loadConnectionTable(stdout: string): Record<string, string>[] {
const lines = stdout.trim().split('\n');
const names = lines.shift()!.trim().split(/\s+/)
.filter(name => name !== 'rx_queue' && name !== 'tm->when');
const table = lines.map(line => line.trim().split(/\s+/).reduce((obj, value, i) => {
const table = lines.map(line => line.trim().split(/\s+/).reduce((obj: Record<string, string>, value, i) => {
obj[names[i] || i] = value;
return obj;
}, {} as Record<string, string>));
}, {}));
return table;
}
@ -126,10 +126,10 @@ export function getRootProcesses(stdout: string) {
}
export async function findPorts(connections: { socket: number; ip: string; port: number }[], socketMap: Record<string, { pid: number; socket: number }>, processes: { pid: number; cwd: string; cmd: string }[]): Promise<CandidatePort[]> {
const processMap = processes.reduce((m, process) => {
const processMap = processes.reduce((m: Record<string, typeof processes[0]>, process) => {
m[process.pid] = process;
return m;
}, {} as Record<string, typeof processes[0]>);
}, {});
const ports: CandidatePort[] = [];
connections.forEach(({ socket, ip, port }) => {

View file

@ -828,7 +828,7 @@ abstract class AbstractTreeView extends Disposable implements ITreeView {
}
},
getActionsContext: () => (<TreeViewItemHandleArg>{ $treeViewId: this.id, $treeItemHandle: node.handle }),
getActionsContext: () => ({ $treeViewId: this.id, $treeItemHandle: node.handle } satisfies TreeViewItemHandleArg),
actionRunner
});

View file

@ -30,7 +30,7 @@ interface IResourceCommentThreadEvent {
commentInfos: ICommentInfo[];
}
export interface ICommentInfo extends CommentInfo {
export interface ICommentInfo<T = IRange> extends CommentInfo<T> {
uniqueOwner: string;
label?: string;
}
@ -67,7 +67,7 @@ export interface ICommentController {
updateCommentThreadTemplate(threadHandle: number, range: IRange): Promise<void>;
deleteCommentThreadMain(commentThreadId: string): void;
toggleReaction(uri: URI, thread: CommentThread, comment: Comment, reaction: CommentReaction, token: CancellationToken): Promise<void>;
getDocumentComments(resource: URI, token: CancellationToken): Promise<ICommentInfo>;
getDocumentComments(resource: URI, token: CancellationToken): Promise<ICommentInfo<IRange>>;
getNotebookComments(resource: URI, token: CancellationToken): Promise<INotebookCommentInfo>;
setActiveCommentAndThread(commentInfo: { thread: CommentThread; comment?: Comment } | undefined): Promise<void>;
}

View file

@ -46,7 +46,6 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility';
import { URI } from 'vs/base/common/uri';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { ITextResourceEditorInput } from 'vs/platform/editor/common/editor';
export const ID = 'editor.contrib.review';
@ -408,7 +407,7 @@ export function revealCommentThread(commentService: ICommentService, editorServi
preserveFocus: preserveFocus,
selection: range ?? new Range(1, 1, 1, 1)
}
} as ITextResourceEditorInput, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => {
}, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(editor => {
if (editor) {
const control = editor.getControl();
if (threadToReveal && isCodeEditor(control)) {
@ -1169,10 +1168,10 @@ export class CommentController implements IEditorContribution {
const picks: QuickPickInput[] = commentInfos.map((commentInfo) => {
const { ownerId, extensionId, label } = commentInfo.action;
return <IQuickPickItem>{
label: label || extensionId,
return {
label: label ?? extensionId ?? ownerId,
id: ownerId
};
} satisfies IQuickPickItem;
});
return picks;

View file

@ -320,7 +320,7 @@ export class CommentNodeRenderer implements IListRenderer<ITreeNode<CommentNode>
commentControlHandle: node.element.controllerHandle,
commentThreadHandle: node.element.threadHandle,
$mid: MarshalledId.CommentThread
} as MarshalledCommentThread;
} satisfies MarshalledCommentThread;
if (!node.element.hasReply()) {
templateData.repliesMetadata.container.style.display = 'none';

View file

@ -48,7 +48,7 @@ export class CommentsFilters extends Disposable {
set showUnresolved(showUnresolved: boolean) {
if (this._showUnresolved.get() !== showUnresolved) {
this._showUnresolved.set(showUnresolved);
this._onDidChange.fire(<CommentsFiltersChangeEvent>{ showUnresolved: true });
this._onDidChange.fire({ showUnresolved: true });
}
}
@ -59,7 +59,7 @@ export class CommentsFilters extends Disposable {
set showResolved(showResolved: boolean) {
if (this._showResolved.get() !== showResolved) {
this._showResolved.set(showResolved);
this._onDidChange.fire(<CommentsFiltersChangeEvent>{ showResolved: true });
this._onDidChange.fire({ showResolved: true });
}
}