Skip to content

Commit

Permalink
Merge pull request microsoft#190491 from microsoft/joh/entitled-lungfish
Browse files Browse the repository at this point in the history
use proper enum for `ChatVariableLevel`
  • Loading branch information
jrieken authored Aug 15, 2023
2 parents cb94a70 + 66e5308 commit ce8c0de
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
TerminalOutputAnchor: extHostTypes.TerminalOutputAnchor,
ChatMessage: extHostTypes.ChatMessage,
ChatMessageRole: extHostTypes.ChatMessageRole,
ChatVariableLevel: extHostTypes.ChatVariableLevel,
CallHierarchyIncomingCall: extHostTypes.CallHierarchyIncomingCall,
CallHierarchyItem: extHostTypes.CallHierarchyItem,
CallHierarchyOutgoingCall: extHostTypes.CallHierarchyOutgoingCall,
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/api/common/extHostChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,15 @@ export class ExtHostChat implements ExtHostChatShape {
const requestObj: vscode.InteractiveRequest = {
session: realSession,
message: typeof request.message === 'string' ? request.message : typeConvert.ChatReplyFollowup.to(request.message),
variables: request.variables ?? {}
variables: {}
};

if (request.variables) {
for (const key of Object.keys(request.variables)) {
requestObj.variables[key] = request.variables[key].map(typeConvert.ChatVariable.to);
}
}

const stopWatch = StopWatch.create(false);
let firstProgress: number | undefined;
const progressObj: vscode.Progress<vscode.InteractiveProgress> = {
Expand Down
8 changes: 6 additions & 2 deletions src/vs/workbench/api/common/extHostChatVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensio
import { ExtHostChatVariablesShape, IMainContext, MainContext, MainThreadChatVariablesShape } from 'vs/workbench/api/common/extHost.protocol';
import { IChatRequestVariableValue, IChatVariableData } from 'vs/workbench/contrib/chat/common/chatVariables';
import { onUnexpectedExternalError } from 'vs/base/common/errors';
import { ChatVariable } from 'vs/workbench/api/common/extHostTypeConverters';

export class ExtHostChatVariables implements ExtHostChatVariablesShape {

Expand All @@ -28,11 +29,14 @@ export class ExtHostChatVariables implements ExtHostChatVariablesShape {
return undefined;
}
try {
return (await item.resolver.resolve(item.data.name, { message: messageText }, token)) ?? undefined;
const value = await item.resolver.resolve(item.data.name, { message: messageText }, token);
if (value) {
return value.map(ChatVariable.from);
}
} catch (err) {
onUnexpectedExternalError(err);
return undefined;
}
return undefined;
}

registerVariableResolver(extension: IExtensionDescription, name: string, description: string, resolver: vscode.ChatVariableResolver): IDisposable {
Expand Down
43 changes: 43 additions & 0 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/ed
import type * as vscode from 'vscode';
import * as types from './extHostTypes';
import * as chatProvider from 'vs/workbench/contrib/chat/common/chatProvider';
import { IChatRequestVariableValue } from 'vs/workbench/contrib/chat/common/chatVariables';

export namespace Command {

Expand Down Expand Up @@ -2200,6 +2201,48 @@ export namespace ChatMessageRole {
}
}

export namespace ChatVariable {
export function to(variable: IChatRequestVariableValue): vscode.ChatVariableValue {
return {
level: ChatVariableLevel.to(variable.level),
value: variable.value,
description: variable.description
};
}

export function from(variable: vscode.ChatVariableValue): IChatRequestVariableValue {
return {
level: ChatVariableLevel.from(variable.level),
value: variable.value,
description: variable.description
};
}
}

export namespace ChatVariableLevel {


export function to(level: 'short' | 'medium' | 'full'): vscode.ChatVariableLevel {
switch (level) {
case 'short': return types.ChatVariableLevel.Short;
case 'medium': return types.ChatVariableLevel.Medium;
case 'full':
default:
return types.ChatVariableLevel.Full;
}
}
export function from(level: vscode.ChatVariableLevel): 'short' | 'medium' | 'full' {
switch (level) {
case types.ChatVariableLevel.Short: return 'short';
case types.ChatVariableLevel.Medium: return 'medium';
case types.ChatVariableLevel.Full:
default:
return 'full';
}
}
}


export namespace TerminalQuickFix {
export function from(quickFix: vscode.TerminalQuickFixExecuteTerminalCommand | vscode.TerminalQuickFixOpener | vscode.Command, converter: Command.ICommandsConverter, disposables: DisposableStore): extHostProtocol.ITerminalQuickFixExecuteTerminalCommandDto | extHostProtocol.ITerminalQuickFixOpenerDto | extHostProtocol.ICommandDto | undefined {
if ('terminalCommand' in quickFix) {
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4097,6 +4097,12 @@ export enum ChatMessageRole {
Function = 3,
}

export enum ChatVariableLevel {
Short = 1,
Medium = 2,
Full = 3
}

export class ChatMessage implements vscode.ChatMessage {

role: ChatMessageRole;
Expand Down
9 changes: 7 additions & 2 deletions src/vscode-dts/vscode.proposed.chatVariables.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ declare module 'vscode' {
variables: Record<string, ChatVariableValue[]>;
}

export enum ChatVariableLevel {
Short = 1,
Medium = 2,
Full = 3
}

export interface ChatVariableValue {
// eslint-disable-next-line local/vscode-dts-literal-or-types, local/vscode-dts-string-type-literals
level: 'short' | 'medium' | 'full';
level: ChatVariableLevel;
value: string;
description?: string;
}
Expand Down

0 comments on commit ce8c0de

Please sign in to comment.