@@ -42,6 +42,11 @@ export function activate(context: vscode.ExtensionContext) {
42
42
43
43
}
44
44
45
+ let openGooseTerminal = vscode . commands . registerCommand ( 'extension.openGoose' , ( ) => {
46
+ getTerminal ( ) ;
47
+ } ) ;
48
+ context . subscriptions . push ( openGooseTerminal ) ;
49
+
45
50
let openTerminalDisposable = vscode . commands . registerCommand ( 'extension.openGooseTerminal' , ( ) => {
46
51
getTerminal ( ) ;
47
52
} ) ;
@@ -51,7 +56,15 @@ export function activate(context: vscode.ExtensionContext) {
51
56
//vscode.commands.executeCommand('extension.openGooseTerminal');
52
57
53
58
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 ( ) => {
55
68
const editor = vscode . window . activeTextEditor ;
56
69
if ( ! editor ) {
57
70
return ;
@@ -75,13 +88,16 @@ export function activate(context: vscode.ExtensionContext) {
75
88
const hasSelectedText = selectedText . trim ( ) . length > 0 ;
76
89
let textToAskGoose = question ;
77
90
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 } ].` +
81
95
` Note: If editing is required, keep edits around these lines and don't delete or modify unrelated code.`
82
96
} else {
83
97
// 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 } ]`
85
101
86
102
}
87
103
editor . document . save ( ) ;
@@ -137,10 +153,12 @@ export function activate(context: vscode.ExtensionContext) {
137
153
const filePath = document . uri . fsPath ;
138
154
const startLine = selection . start . line + 1 ;
139
155
156
+ const selectedText = document . getText ( selection ) ;
157
+ const tempFileName = createTempFileWithLines ( selectedText , startLine ) ;
140
158
document . save ( ) ;
141
159
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.` ) ;
144
162
} ) ;
145
163
context . subscriptions . push ( askGooseToFix ) ;
146
164
0 commit comments