Skip to content

Commit 2fc23dd

Browse files
committed
pass in context better
1 parent da7e35b commit 2fc23dd

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "goose-vscode",
3-
"version": "0.0.17",
3+
"version": "0.0.18",
44
"publisher": "michaelneale",
55
"icon": "goose-icon.png",
66
"main": "./out/extension.js",
@@ -53,7 +53,11 @@
5353
"commands": [
5454
{
5555
"command": "extension.sendToGoose",
56-
"title": "🪿 Ask Goose 🪿"
56+
"title": "🪿 ask goose 🪿"
57+
},
58+
{
59+
"command": "extension.openGoose",
60+
"title": "🪿 open goose 🪿"
5761
}
5862
],
5963
"menus": {

src/extension.ts

+25-7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export function activate(context: vscode.ExtensionContext) {
4242

4343
}
4444

45+
let openGooseTerminal = vscode.commands.registerCommand('extension.openGoose', () => {
46+
getTerminal();
47+
});
48+
context.subscriptions.push(openGooseTerminal);
49+
4550
let openTerminalDisposable = vscode.commands.registerCommand('extension.openGooseTerminal', () => {
4651
getTerminal();
4752
});
@@ -51,7 +56,15 @@ export function activate(context: vscode.ExtensionContext) {
5156
//vscode.commands.executeCommand('extension.openGooseTerminal');
5257

5358

54-
let sendToGooseDisposable = vscode.commands.registerCommand('extension.sendToGoose', async () => {
59+
function createTempFileWithLines(selectedText: string, startLine: number): string {
60+
const selectedLines = selectedText.split('\n').map((line, index) => `${startLine + index}: ${line}`).join('\n');
61+
const tempDir = os.tmpdir();
62+
const tempFileName = path.join(tempDir, `goose_context_${Date.now()}.txt`);
63+
fs.writeFileSync(tempFileName, selectedLines);
64+
return tempFileName;
65+
}
66+
67+
let sendToGooseDisposable = vscode.commands.registerCommand('extension.sendToGoose', async () => {
5568
const editor = vscode.window.activeTextEditor;
5669
if (!editor) {
5770
return;
@@ -75,13 +88,16 @@ export function activate(context: vscode.ExtensionContext) {
7588
const hasSelectedText = selectedText.trim().length > 0;
7689
let textToAskGoose = question;
7790
if (hasSelectedText) {
78-
// There is some selected test
79-
textToAskGoose = `Looking at file: ${filePath} regarding lines: ${startLine} to ${endLine}` +
80-
` please load fhe file, answer this question: [${question}].` +
91+
// There is some selected text
92+
const tempFileName = createTempFileWithLines(selectedText, startLine);
93+
textToAskGoose = `Looking at file: ${filePath} with context: ${tempFileName}.` +
94+
` please load the file, answer this question: [${question}].` +
8195
` Note: If editing is required, keep edits around these lines and don't delete or modify unrelated code.`
8296
} else {
8397
// cursor is just position in file
84-
textToAskGoose = `Please answer the query: [${question}] `
98+
const cursorLine = editor.selection.active.line + 1;
99+
textToAskGoose = `Looking at file: ${filePath}, you are on line ${cursorLine}. ` +
100+
`Please answer the query: [${question}]`
85101

86102
}
87103
editor.document.save();
@@ -137,10 +153,12 @@ export function activate(context: vscode.ExtensionContext) {
137153
const filePath = document.uri.fsPath;
138154
const startLine = selection.start.line + 1;
139155

156+
const selectedText = document.getText(selection);
157+
const tempFileName = createTempFileWithLines(selectedText, startLine);
140158
document.save();
141159

142-
getTerminal().sendText(`Can you look at the code on line: ${startLine} in file: ${filePath}. ` +
143-
`and fix any problems you see on this line and near it. Try not to delete content.`);
160+
getTerminal().sendText(`Can you look at the code in file: ${filePath} with context: ${tempFileName}. ` +
161+
`and fix any problems you see around it. Try not to delete content.`);
144162
});
145163
context.subscriptions.push(askGooseToFix);
146164

0 commit comments

Comments
 (0)