2023-05-04 07:27:26 +08:00
|
|
|
import * as vscode from 'vscode';
|
2023-04-21 06:44:26 +08:00
|
|
|
const ChatPanel = require('./chatPanel').default;
|
2023-04-27 14:07:46 +08:00
|
|
|
const sendFileSelectMessage = require('./messageHandler').sendFileSelectMessage;
|
|
|
|
const sendCodeSelectMessage = require('./messageHandler').sendCodeSelectMessage;
|
2023-05-04 07:27:26 +08:00
|
|
|
import ExtensionContextHolder from './extensionContext';
|
2023-04-27 14:07:46 +08:00
|
|
|
|
2023-05-04 07:27:26 +08:00
|
|
|
function activate(context: vscode.ExtensionContext) {
|
|
|
|
ExtensionContextHolder.context = context;
|
2023-04-26 06:48:39 +08:00
|
|
|
let disposable = vscode.commands.registerCommand('devchat.openChatPanel', () => {
|
|
|
|
if (vscode.workspace.workspaceFolders) {
|
|
|
|
ChatPanel.createOrShow(context.extensionUri);
|
|
|
|
} else {
|
|
|
|
vscode.window.showErrorMessage('Please open a directory before using the chat panel.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-27 14:07:46 +08:00
|
|
|
const disposable_add_context = vscode.commands.registerCommand('devchat.addConext', (uri: { path: any; }) => {
|
|
|
|
if (!ChatPanel.currentPanel()) {
|
|
|
|
if (vscode.workspace.workspaceFolders) {
|
|
|
|
ChatPanel.createOrShow(context.extensionUri);
|
|
|
|
} else {
|
|
|
|
vscode.window.showErrorMessage('Please open a directory before using the chat panel.');
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendFileSelectMessage(ChatPanel.currentPanel().panel(), uri.path);
|
|
|
|
});
|
|
|
|
|
|
|
|
const disposableCodeContext = vscode.commands.registerCommand('devchat.askForCode', async () => {
|
|
|
|
const editor = vscode.window.activeTextEditor;
|
|
|
|
if (editor) {
|
|
|
|
if (!ChatPanel.currentPanel()) {
|
|
|
|
if (vscode.workspace.workspaceFolders) {
|
|
|
|
ChatPanel.createOrShow(context.extensionUri);
|
|
|
|
} else {
|
|
|
|
vscode.window.showErrorMessage('Please open a directory before using the chat panel.');
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectedText = editor.document.getText(editor.selection);
|
|
|
|
sendCodeSelectMessage(ChatPanel.currentPanel().panel(), selectedText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const disposableAskFile = vscode.commands.registerCommand('devchat.askForFile', async () => {
|
|
|
|
const editor = vscode.window.activeTextEditor;
|
|
|
|
if (editor) {
|
|
|
|
if (!ChatPanel.currentPanel()) {
|
|
|
|
if (vscode.workspace.workspaceFolders) {
|
|
|
|
ChatPanel.createOrShow(context.extensionUri);
|
|
|
|
} else {
|
|
|
|
vscode.window.showErrorMessage('Please open a directory before using the chat panel.');
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectedText = editor.document.getText();
|
|
|
|
sendCodeSelectMessage(ChatPanel.currentPanel().panel(), selectedText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-04-26 06:48:39 +08:00
|
|
|
context.subscriptions.push(disposable);
|
2023-04-27 14:07:46 +08:00
|
|
|
context.subscriptions.push(disposable_add_context);
|
|
|
|
context.subscriptions.push(disposableCodeContext)
|
|
|
|
context.subscriptions.push(disposableAskFile)
|
2023-04-14 08:05:41 +08:00
|
|
|
}
|
2023-04-21 06:44:26 +08:00
|
|
|
exports.activate = activate;
|