Skip to content

Commit

Permalink
Fix unsafe type assertions in chat code (microsoft#224247)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jul 30, 2024
1 parent 1acc838 commit 3c490da
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/chat/browser/actions/chatActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class ChatHistoryAction extends Action2 {
picker.items = getPicks();
store.add(picker.onDidTriggerItemButton(context => {
if (context.button === openInEditorButton) {
editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: <IChatEditorOptions>{ target: { sessionId: context.item.chat.sessionId }, pinned: true } }, ACTIVE_GROUP);
const options: IChatEditorOptions = { target: { sessionId: context.item.chat.sessionId }, pinned: true };
editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options }, ACTIVE_GROUP);
picker.hide();
} else if (context.button === deleteButton) {
chatService.removeHistoryEntry(context.item.chat.sessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export function registerChatExportActions() {
throw new Error('Invalid chat session data');
}

await editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: { target: { data }, pinned: true } as IChatEditorOptions });
const options: IChatEditorOptions = { target: { data }, pinned: true };
await editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options });
} catch (err) {
throw err;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function executeMoveToAction(accessor: ServicesAccessor, moveTo: MoveToNew

const widget = chatView?.widget ?? widgetService.lastFocusedWidget;
if (!widget || !('viewId' in widget.viewContext)) {
await editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: <IChatEditorOptions>{ pinned: true } }, moveTo === MoveToNewLocation.Window ? AUX_WINDOW_GROUP : ACTIVE_GROUP);
await editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: { pinned: true } }, moveTo === MoveToNewLocation.Window ? AUX_WINDOW_GROUP : ACTIVE_GROUP);
return;
}

Expand All @@ -109,7 +109,8 @@ async function executeMoveToAction(accessor: ServicesAccessor, moveTo: MoveToNew
const viewState = widget.getViewState();
widget.clear();

await editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options: <IChatEditorOptions>{ target: { sessionId }, pinned: true, viewState: viewState } }, moveTo === MoveToNewLocation.Window ? AUX_WINDOW_GROUP : ACTIVE_GROUP);
const options: IChatEditorOptions = { target: { sessionId }, pinned: true, viewState: viewState };
await editorService.openEditor({ resource: ChatEditorInput.getNewEditorUri(), options }, moveTo === MoveToNewLocation.Window ? AUX_WINDOW_GROUP : ACTIVE_GROUP);
}

async function moveToSidebar(accessor: ServicesAccessor): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ export class ChatDynamicVariableModel extends Disposable implements IChatWidgetC
}

private updateDecorations(): void {
this.widget.inputEditor.setDecorationsByType('chat', dynamicVariableDecorationType, this._variables.map(r => (<IDecorationOptions>{
this.widget.inputEditor.setDecorationsByType('chat', dynamicVariableDecorationType, this._variables.map((r): IDecorationOptions => ({
range: r.range,
hoverMessage: this.getHoverForReference(r)
})));
}

private getHoverForReference(ref: IDynamicVariable): string | IMarkdownString {
private getHoverForReference(ref: IDynamicVariable): IMarkdownString | undefined {
const value = ref.data;
if (URI.isUri(value)) {
return new MarkdownString(this.labelService.getUriLabel(value, { relative: true }));
} else {
return (value as any).toString();
return undefined;
}
}
}
Expand Down Expand Up @@ -162,11 +162,10 @@ export class SelectAndInsertFileAction extends Action2 {
// This of course assumes that the `files` variable has the behavior that it searches
// through files in the workspace.
if (chatVariablesService.hasVariable(SelectAndInsertFileAction.Name)) {
options = {
providerOptions: <AnythingQuickAccessProviderRunOptions>{
additionPicks: [SelectAndInsertFileAction.Item, { type: 'separator' }]
},
const providerOptions: AnythingQuickAccessProviderRunOptions = {
additionPicks: [SelectAndInsertFileAction.Item, { type: 'separator' }]
};
options = { providerOptions };
}
// TODO: have dedicated UX for this instead of using the quick access picker
const picks = await quickInputService.quickAccess.pick('', options);
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ export class ChatModel extends Disposable implements IChatModel {

// Port entries from old format
const result = 'responseErrorDetails' in raw ?
// eslint-disable-next-line local/code-no-dangerous-type-assertions
{ errorDetails: raw.responseErrorDetails } as IChatAgentResult : raw.result;
request.response = new ChatResponseModel(raw.response ?? [new MarkdownString(raw.response)], this, agent, raw.slashCommand, request.id, true, raw.isCanceled, raw.vote, result, raw.followups);
if (raw.usedContext) { // @ulugbekna: if this's a new vscode sessions, doc versions are incorrect anyway?
Expand Down

0 comments on commit 3c490da

Please sign in to comment.