You've already forked qoder-cli-vscode
chore: add compiled JavaScript output
- Add compiled extension.js and source maps - Generated from TypeScript source 🤖 Generated with [Qoder](https://qoder.com)
This commit is contained in:
84
out/extension.js
Normal file
84
out/extension.js
Normal file
@@ -0,0 +1,84 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.deactivate = exports.activate = void 0;
|
||||
const vscode = require("vscode");
|
||||
function activate(context) {
|
||||
console.log('Terminal Tab Extension is now active!');
|
||||
// 注册打开终端标签页命令
|
||||
const openTerminalTabCommand = vscode.commands.registerCommand('terminalTab.open', async () => {
|
||||
await openTerminalInEditor();
|
||||
});
|
||||
// 注册在当前目录打开终端标签页命令
|
||||
const openInCurrentDirCommand = vscode.commands.registerCommand('terminalTab.openInCurrentDirectory', async (uri) => {
|
||||
let cwd;
|
||||
if (uri && uri.fsPath) {
|
||||
// 从右键菜单获取路径
|
||||
const fs = require('fs');
|
||||
const stat = fs.statSync(uri.fsPath);
|
||||
if (stat.isDirectory()) {
|
||||
cwd = uri.fsPath;
|
||||
}
|
||||
else {
|
||||
cwd = uri.fsPath.substring(0, uri.fsPath.lastIndexOf('\\') || uri.fsPath.lastIndexOf('/'));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 从当前活动编辑器获取路径
|
||||
const activeEditor = vscode.window.activeTextEditor;
|
||||
if (activeEditor) {
|
||||
const filePath = activeEditor.document.uri.fsPath;
|
||||
cwd = filePath.substring(0, filePath.lastIndexOf('\\') || filePath.lastIndexOf('/'));
|
||||
}
|
||||
}
|
||||
await openTerminalInEditor(cwd);
|
||||
});
|
||||
context.subscriptions.push(openTerminalTabCommand, openInCurrentDirCommand);
|
||||
}
|
||||
exports.activate = activate;
|
||||
async function openTerminalInEditor(cwd) {
|
||||
const config = vscode.workspace.getConfiguration('terminalTab');
|
||||
const preserveFocus = config.get('preserveFocus') || false;
|
||||
// 先执行向右拆分命令,创建右侧编辑器组
|
||||
await vscode.commands.executeCommand('workbench.action.splitEditorRight');
|
||||
// 创建终端选项,在编辑器中打开
|
||||
const terminalOptions = {
|
||||
name: 'Qoder CLI',
|
||||
cwd: cwd,
|
||||
location: vscode.TerminalLocation.Editor
|
||||
};
|
||||
// 创建终端
|
||||
const terminal = vscode.window.createTerminal(terminalOptions);
|
||||
// 显示终端
|
||||
terminal.show(preserveFocus);
|
||||
// 发送 qodercli 命令
|
||||
terminal.sendText('qodercli', true);
|
||||
// 锁定编辑器组
|
||||
setTimeout(async () => {
|
||||
await lockTerminalTab(terminal);
|
||||
}, 500);
|
||||
}
|
||||
async function lockTerminalTab(terminal) {
|
||||
// VS Code API 限制:无法直接通过 API 锁定标签页
|
||||
// 但我们可以通过以下方式模拟锁定行为:
|
||||
// 1. 监听终端关闭事件,如果是我们的终端,可以提示用户
|
||||
const disposable = vscode.window.onDidCloseTerminal((closedTerminal) => {
|
||||
if (closedTerminal === terminal) {
|
||||
// 终端已关闭,清理资源
|
||||
disposable.dispose();
|
||||
}
|
||||
});
|
||||
// 2. 尝试通过命令锁定编辑器组(如果支持)
|
||||
try {
|
||||
// 使用 VS Code 内置命令锁定编辑器组
|
||||
await vscode.commands.executeCommand('workbench.action.lockEditorGroup');
|
||||
}
|
||||
catch (error) {
|
||||
// 命令可能不存在,忽略错误
|
||||
console.log('Lock editor group command not available');
|
||||
}
|
||||
}
|
||||
function deactivate() {
|
||||
console.log('Terminal Tab Extension is now deactivated!');
|
||||
}
|
||||
exports.deactivate = deactivate;
|
||||
//# sourceMappingURL=extension.js.map
|
||||
Reference in New Issue
Block a user