(context: vscode.ExtensionContext)
| 15 | } |
| 16 | |
| 17 | export function activate(context: vscode.ExtensionContext) { |
| 18 | // Get the API session token from the extension's configuration |
| 19 | |
| 20 | const config = vscode.workspace.getConfiguration('chatgpt'); |
| 21 | |
| 22 | // Create a new ChatGPTViewProvider instance and register it with the extension's context |
| 23 | const provider = new ChatGPTViewProvider(context.extensionUri); |
| 24 | |
| 25 | |
| 26 | // Put configuration settings into the provider |
| 27 | provider.selectedInsideCodeblock = config.get('selectedInsideCodeblock') || false; |
| 28 | provider.pasteOnClick = config.get('pasteOnClick') || false; |
| 29 | provider.keepConversation = config.get('keepConversation') || false; |
| 30 | provider.timeoutLength = config.get('timeoutLength') || 60; |
| 31 | |
| 32 | context.subscriptions.push( |
| 33 | vscode.window.registerWebviewViewProvider(ChatGPTViewProvider.viewType, provider, { |
| 34 | webviewOptions: { retainContextWhenHidden: true } |
| 35 | }) |
| 36 | ); |
| 37 | |
| 38 | |
| 39 | // Register the commands that can be called from the extension's package.json |
| 40 | const commandHandler = (command:string) => { |
| 41 | const config = vscode.workspace.getConfiguration('chatgpt'); |
| 42 | const prompt = config.get(command) as string; |
| 43 | provider.search(prompt); |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | const commandAsk = vscode.commands.registerCommand('chatgpt.ask', () => { |
| 48 | vscode.window.showInputBox({ prompt: 'What do you want to do?' }).then((value) => { |
| 49 | provider.search(value); |
| 50 | }); |
| 51 | }); |
| 52 | |
| 53 | const commandExplain = vscode.commands.registerCommand('chatgpt.explain', () => { |
| 54 | commandHandler('promptPrefix.explain'); |
| 55 | }); |
| 56 | const commandRefactor = vscode.commands.registerCommand('chatgpt.refactor', () => { |
| 57 | commandHandler('promptPrefix.refactor'); |
| 58 | }); |
| 59 | const commandOptimize = vscode.commands.registerCommand('chatgpt.optimize', () => { |
| 60 | commandHandler('promptPrefix.optimize'); |
| 61 | }); |
| 62 | const commandProblems = vscode.commands.registerCommand('chatgpt.findProblems', () => { |
| 63 | commandHandler('promptPrefix.findProblems'); |
| 64 | }); |
| 65 | |
| 66 | |
| 67 | context.subscriptions.push(commandAsk, commandExplain, commandRefactor, commandOptimize, commandProblems); |
| 68 | |
| 69 | |
| 70 | |
| 71 | // Change the extension's session token when configuration is changed |
| 72 | vscode.workspace.onDidChangeConfiguration((event: vscode.ConfigurationChangeEvent) => { |
| 73 | if (event.affectsConfiguration('chatgpt.sessionToken')) { |
| 74 | // Get the extension's configuration |
nothing calls this directly
no test coverage detected