Skip to content

Commit

Permalink
feat: focus chat window on all chat requests (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellebore authored Jul 8, 2023
1 parent 9c9734d commit 3b24723
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
40 changes: 19 additions & 21 deletions src/ask-sourcery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
46 changes: 24 additions & 22 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
)
);
Expand Down

0 comments on commit 3b24723

Please sign in to comment.