(prompt?:string)
| 244 | |
| 245 | |
| 246 | public async search(prompt?:string) { |
| 247 | if (!this._ws || this._ws.readyState !== WebSocket.OPEN) { |
| 248 | console.error('WebSocket is not connected.'); |
| 249 | return; |
| 250 | } |
| 251 | |
| 252 | this._prompt = prompt; |
| 253 | if (!prompt) { |
| 254 | prompt = ''; |
| 255 | }; |
| 256 | |
| 257 | // focus gpt activity from activity bar |
| 258 | if (!this._view) { |
| 259 | await vscode.commands.executeCommand('chatgpt.chatView.focus'); |
| 260 | } else { |
| 261 | this._view?.show?.(true); |
| 262 | } |
| 263 | |
| 264 | let response = ''; |
| 265 | |
| 266 | // Get the selected text of the active editor |
| 267 | const selection = vscode.window.activeTextEditor?.selection; |
| 268 | // const selectedText = vscode.window.activeTextEditor?.document.getText(selection); |
| 269 | const selectedText = ''; |
| 270 | let searchPrompt = ''; |
| 271 | |
| 272 | if (selection && selectedText) { |
| 273 | // If there is a selection, add the prompt and the selected text to the search prompt |
| 274 | if (this.selectedInsideCodeblock) { |
| 275 | searchPrompt = `${prompt}\n\`\`\`\n${selectedText}\n\`\`\``; |
| 276 | } else { |
| 277 | searchPrompt = `${prompt}\n${selectedText}\n`; |
| 278 | } |
| 279 | } else { |
| 280 | // Otherwise, just use the prompt if user typed it |
| 281 | searchPrompt = prompt; |
| 282 | } |
| 283 | |
| 284 | this._fullPrompt = searchPrompt; |
| 285 | |
| 286 | |
| 287 | try { |
| 288 | |
| 289 | if (!this._ws) { |
| 290 | throw new Error('WebSocket connection not established'); |
| 291 | } |
| 292 | // Send the search prompt |
| 293 | const message = { |
| 294 | action: 'send_message', |
| 295 | message: searchPrompt |
| 296 | }; |
| 297 | |
| 298 | |
| 299 | this._chatHistory.push({ agent: 'User', message: searchPrompt }); |
| 300 | if (this._view && this._view.visible) { |
| 301 | this._view.webview.postMessage({ type: 'updateChatHistory', value: this._chatHistory }); |
| 302 | } |
| 303 |
no test coverage detected