diff --git a/src/ask-sourcery.ts b/src/ask-sourcery.ts index ef880a12..b9ecf5a9 100644 --- a/src/ask-sourcery.ts +++ b/src/ask-sourcery.ts @@ -4,28 +4,26 @@ import { ChatRequest } from "./chat"; export function askSourceryCommand(recipes: Recipe[], contextRange?) { showAskSourceryQuickPick(recipes).then((result: any) => { - vscode.commands.executeCommand("sourcery.chat.focus").then(() => { - let request: ChatRequest; - if ("id" in result) { - request = { - type: "recipe_request", - data: { - kind: "recipe_request", - name: result.label, - id: result.id, - }, - context_range: contextRange, - }; - } else { - request = { - type: "chat_request", - data: { kind: "user_message", message: result.label }, - context_range: contextRange, - }; - } + let request: ChatRequest; + if ("id" in result) { + request = { + type: "recipe_request", + data: { + kind: "recipe_request", + name: result.label, + id: result.id, + }, + context_range: contextRange, + }; + } else { + request = { + type: "chat_request", + data: { kind: "user_message", message: result.label }, + context_range: contextRange, + }; + } - vscode.commands.executeCommand("sourcery.chat_request", request); - }); + vscode.commands.executeCommand("sourcery.chat_request", request); }); } diff --git a/src/extension.ts b/src/extension.ts index 8b576cf8..59ca9e0d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -406,29 +406,31 @@ function registerCommands( commands.registerCommand( "sourcery.chat_request", (message: ChatRequest) => { - // Use the editor selection unless a range was passed through in - // the message - let selectionLocation = getSelectionLocation(); - if (message.context_range != null) { - selectionLocation = { - uri: selectionLocation.uri, - range: message.context_range, + vscode.commands.executeCommand("sourcery.chat.focus").then(() => { + // Use the editor selection unless a range was passed through in + // the message + let selectionLocation = getSelectionLocation(); + if (message.context_range != null) { + selectionLocation = { + uri: selectionLocation.uri, + range: message.context_range, + }; + } + let { activeFile, allFiles } = activeFiles(); + + let request: ExecuteCommandParams = { + command: "sourcery/chat/request", + arguments: [ + { + message: message, + selected: selectionLocation, + active_file: activeFile, + all_open_files: allFiles, + }, + ], }; - } - let { activeFile, allFiles } = activeFiles(); - - let request: ExecuteCommandParams = { - command: "sourcery/chat/request", - arguments: [ - { - message: message, - selected: selectionLocation, - active_file: activeFile, - all_open_files: allFiles, - }, - ], - }; - languageClient.sendRequest(ExecuteCommandRequest.type, request); + languageClient.sendRequest(ExecuteCommandRequest.type, request); + }); } ) );