Skip to content

Commit

Permalink
fixed #533
Browse files Browse the repository at this point in the history
feat #570
  • Loading branch information
thqby committed Aug 25, 2024
1 parent 9b412c7 commit 2f7a83b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 59 deletions.
50 changes: 36 additions & 14 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const ahkconfig = workspace.getConfiguration('AutoHotkey2');
let ahkpath_cur: string = ahkconfig.InterpreterPath, server_is_ready = false, zhcn = false;
const textdecoders: TextDecoder[] = [new TextDecoder('utf8', { fatal: true }), new TextDecoder('utf-16le', { fatal: true })];
const isWindows = process.platform === 'win32';
let extlist: string[] = [], debugexts: { [type: string]: string } = {}, langs: string[] = [];

export async function activate(context: ExtensionContext) {
// The server is implemented in node
Expand Down Expand Up @@ -121,7 +122,6 @@ export async function activate(context: ExtensionContext) {
server_is_ready = true;
});

let extlist: string[], debugexts: { [type: string]: string }, langs: string[] = [];
const id_has_register: string[] = [];
function update_extensions_info() {
debugexts = {};
Expand All @@ -141,11 +141,7 @@ export async function activate(context: ExtensionContext) {
async resolveDebugConfiguration(folder, config) {
if (config.__ahk2debug || window.activeTextEditor?.document.languageId !== 'ahk') {
const append_configs: (DebugConfiguration | undefined)[] = [];
const allconfigs = workspace.getConfiguration('launch').inspect<DebugConfiguration[]>('configurations');
let configs = allconfigs && [
...allconfigs.workspaceFolderValue ?? [],
...allconfigs.workspaceValue ?? [],
...allconfigs.globalValue ?? []];
let configs = get_debug_configs();
config.request ||= 'launch';
configs = configs?.filter(it => it.request === config.request && it.type === config.type);
if (!config.__ahk2debug) {
Expand Down Expand Up @@ -200,9 +196,10 @@ export async function activate(context: ExtensionContext) {
commands.registerTextEditorCommand('ahk2.selection.run', textEditor => runScript(textEditor, true)),
commands.registerCommand('ahk2.stop', stopRunningScript),
commands.registerCommand('ahk2.setinterpreter', setInterpreter),
commands.registerCommand('ahk2.debug', () => beginDebug(extlist, debugexts)),
commands.registerCommand('ahk2.debug.params', () => beginDebug(extlist, debugexts, true)),
commands.registerCommand('ahk2.debug.attach', () => beginDebug(extlist, debugexts, false, true)),
commands.registerCommand('ahk2.debug.file', () => beginDebug('f')),
commands.registerCommand('ahk2.debug.configs', () => beginDebug('c')),
commands.registerCommand('ahk2.debug.params', () => beginDebug('p')),
commands.registerCommand('ahk2.debug.attach', () => beginDebug('a')),
commands.registerCommand('ahk2.selectsyntaxes', selectSyntaxes),
commands.registerTextEditorCommand('ahk2.updateversioninfo', async textEditor => {
if (!server_is_ready)
Expand Down Expand Up @@ -491,24 +488,32 @@ if ${!!word} && !DllCall('oleacc\\AccessibleObjectFromWindow', 'ptr', ctl, 'uint
execSync(`"${executePath}" /ErrorStdOut *`, { input: script });
}

async function beginDebug(extlist: string[], debugexts: { [type: string]: string }, params = false, attach = false) {
function get_debug_configs() {
const allconfigs = workspace.getConfiguration('launch').inspect<DebugConfiguration[]>('configurations');
return allconfigs && [
...allconfigs.workspaceFolderValue ?? [],
...allconfigs.workspaceValue ?? [],
...allconfigs.globalValue ?? []].filter(it => !!debugexts[it.type]);
}

async function beginDebug(type: string) {
let extname: string | undefined;
const editor = window.activeTextEditor;
const config = { ...ahkconfig.get('DebugConfiguration'), request: 'launch', __ahk2debug: true } as DebugConfiguration;
let config = { ...ahkconfig.get('DebugConfiguration'), request: 'launch', __ahk2debug: true } as DebugConfiguration;
if (!extlist.length) {
window.showErrorMessage(zhcn ? '未找到debug扩展, 请先安装debug扩展!' : 'The debug extension was not found, please install the debug extension first!');
extname = await window.showQuickPick(['zero-plusplus.vscode-autohotkey-debug', 'helsmy.autohotkey-debug', 'mark-wiemer.vscode-autohotkey-plus-plus', 'cweijan.vscode-autohotkey-plus']);
if (extname)
commands.executeCommand('workbench.extensions.installExtension', extname);
return;
}
if (params || attach) {
if ('ap'.includes(type)) {
if (!extlist.includes(extname = 'zero-plusplus.vscode-autohotkey-debug')) {
window.showErrorMessage('zero-plusplus.vscode-autohotkey-debug was not found!');
return;
}
config.type = Object.entries(debugexts).find(([, v]) => v === extname)![0];
if (params) {
if (type === 'p') {
let input = await window.showInputBox({ prompt: zhcn ? '输入需要传递的命令行参数' : 'Enter the command line parameters that need to be passed' });
if ((input = input?.trim())) {
const args: string[] = [];
Expand All @@ -519,7 +524,24 @@ async function beginDebug(extlist: string[], debugexts: { [type: string]: string
config.args = args;
}
} else config.request = 'attach';
} else config.type ||= Object.keys(debugexts).sort().pop()!;
} else if (type === 'c') {
const configs = get_debug_configs();
if (configs?.length) {
const pick = window.createQuickPick();
pick.items = configs.map(it => ({ label: it.name, data: it }));
pick.show();
const it = await new Promise(resolve => {
pick.onDidAccept(() => resolve(
(pick.selectedItems[0] as unknown as { data: DebugConfiguration })?.data));
pick.onDidHide(() => resolve(undefined));
});
pick.dispose();
if (!it)
return;
config = it as DebugConfiguration;
}
} else config.program = '${file}';
config.type ||= Object.keys(debugexts).sort().pop()!;
config.name ||= `AutoHotkey ${config.request === 'attach' ? 'Attach' : 'Debug'}`;
debug.startDebugging(editor && workspace.getWorkspaceFolder(editor.document.uri), config);
}
Expand Down
108 changes: 71 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,19 @@
"commands": [
{
"enablement": "editorLangId == ahk2 && shellExecutionSupported",
"command": "ahk2.debug",
"title": "%ahk2.debug%",
"command": "ahk2.debug.file",
"title": "%ahk2.debug.file%",
"icon": "$(debug)",
"category": "ahk2"
},
{
"enablement": "!isWeb",
"enablement": "editorLangId == ahk2 && shellExecutionSupported",
"command": "ahk2.debug.configs",
"title": "%ahk2.debug.configs%",
"category": "ahk2"
},
{
"enablement": "shellExecutionSupported",
"command": "ahk2.debug.attach",
"title": "%ahk2.debug.attach%",
"category": "ahk2"
Expand Down Expand Up @@ -453,20 +459,43 @@
"menus": {
"editor/context": [
{
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.debug",
"group": "navigation@1"
"submenu": "ahk2.context",
"group": "navigation@0"
}
],
"editor/title/run": [
{
"command": "ahk2.run",
"group": "navigation",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
},
{
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.debug.attach",
"group": "navigation@2"
"command": "ahk2.stop",
"group": "navigation",
"when": "resourceLangId == ahk2 && ahk2:isRunning && shellExecutionSupported"
},
{
"command": "ahk2.debug.file",
"group": "navigation",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
},
{
"command": "ahk2.debug.configs",
"group": "navigation",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
},
{
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.debug.params",
"group": "navigation@2"
"group": "navigation",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
},
{
"command": "ahk2.debug.attach",
"group": "navigation",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
}
],
"ahk2.context": [
{
"when": "editorLangId == ahk2 && !isWeb && editorHasSelection",
"command": "ahk2.selection.run",
Expand All @@ -478,49 +507,54 @@
"group": "navigation@0"
},
{
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.compile",
"command": "ahk2.debug.file",
"when": "resourceLangId == ahk2 && shellExecutionSupported",
"group": "navigation@2"
},
{
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.help",
"group": "navigation@1"
"command": "ahk2.debug.configs",
"when": "resourceLangId == ahk2 && shellExecutionSupported",
"group": "navigation@2"
},
{
"when": "editorLangId == ahk2 && !isWeb && ahk2:isRunning",
"command": "ahk2.stop",
"group": "navigation@0"
"command": "ahk2.debug.params",
"when": "resourceLangId == ahk2 && shellExecutionSupported",
"group": "navigation@2"
},
{
"when": "editorLangId == ahk2",
"command": "ahk2.generate.comment",
"command": "ahk2.debug.attach",
"when": "resourceLangId == ahk2 && shellExecutionSupported",
"group": "navigation@2"
},
{
"when": "editorLangId == ahk2",
"command": "ahk2.updateversioninfo",
"group": "navigation@2"
}
],
"editor/title": [
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.compile"
},
{
"command": "ahk2.run",
"group": "navigation@0",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
"when": "editorLangId == ahk2 && !isWeb",
"command": "ahk2.help"
},
{
"when": "editorLangId == ahk2 && !isWeb && ahk2:isRunning",
"command": "ahk2.stop",
"group": "navigation@0",
"when": "resourceLangId == ahk2 && ahk2:isRunning && shellExecutionSupported"
"group": "navigation@0"
},
{
"command": "ahk2.debug",
"group": "navigation@1",
"when": "resourceLangId == ahk2 && shellExecutionSupported"
"when": "editorLangId == ahk2",
"command": "ahk2.generate.comment"
},
{
"when": "editorLangId == ahk2",
"command": "ahk2.updateversioninfo"
}
]
},
"submenus": [
{
"id": "ahk2.context",
"label": "AutoHotkey v2"
}
],
"keybindings": [
{
"command": "ahk2.run",
Expand All @@ -538,9 +572,9 @@
"when": "editorLangId == ahk2 && !isWeb"
},
{
"command": "ahk2.debug",
"command": "ahk2.debug.file",
"key": "f5",
"when": "editorLangId == ahk2 && !isWeb && !inDebugMode"
"when": "editorLangId == ahk2 && !isWeb"
},
{
"command": "ahk2.debug.params",
Expand Down
9 changes: 5 additions & 4 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"ahk2.compilercmd": "Compiler command line options. If ahk2exe.exe is not specified, the default path will be used. `${execPath}` is equal to the currently selected AutoHotkey.exe",
"ahk2.completefunctionparens": "Parentheses are added to function completion when there is no `(` or `[` on the right; otherwise move the cursor to the right",
"ahk2.completioncommitcharacters": "Characters which commit auto completion, such as `.(`",
"ahk2.debug.attach": "Attach Running Script",
"ahk2.debug.params": "Debug Script with Params",
"ahk2.debug": "Debug Script",
"ahk2.debug.attach": "Attach to ahk process",
"ahk2.debug.configs": "Debug ahk File using launch.json",
"ahk2.debug.file": "Debug ahk File",
"ahk2.debug.params": "Debug ahk File with Params",
"ahk2.debugconfiguration": "Append debugging configuration to the currently started debugger, same as launch.json configuration",
"ahk2.description": "Autohotkey2 Language Support using vscode-lsp",
"ahk2.diagnostic.full": "Diagnostic full text",
Expand All @@ -23,7 +24,7 @@
"ahk2.generatecomment": "Generate Comment Template",
"ahk2.help": "Quick Help",
"ahk2.interpreterpath": "The path of the `AutoHotkey.exe` executable file. If `AutoHotkeyUX.exe` is selected, the script will be launched using UX Launcher.",
"ahk2.run": "Run Script",
"ahk2.run": "Run ahk File",
"ahk2.selection.run": "Run Selected Script",
"ahk2.setinterpreter": "Select AutoHotkey2 Interpreter",
"ahk2.setscriptdir": "Set here as A_ScriptDir",
Expand Down
9 changes: 5 additions & 4 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"ahk2.compilercmd": "编译器命令行选项. 如果未指定ahk2exe.exe, 将使用默认路径. `${execPath}`等价于当前选择的AutoHotkey.exe",
"ahk2.completefunctionparens": "当右侧不存在`(`或`[`时, 给函数补全添加括号; 否则向右移动光标",
"ahk2.completioncommitcharacters": "提交自动完成的字符, 例如`.(`",
"ahk2.debug.attach": "附加到运行中的脚本",
"ahk2.debug.params": "带参调试",
"ahk2.debug": "调试脚本",
"ahk2.debug.attach": "附加到ahk进程",
"ahk2.debug.configs": "使用launch.json调试ahk文件",
"ahk2.debug.file": "调试ahk文件",
"ahk2.debug.params": "带参数调试",
"ahk2.debugconfiguration": "追加调试配置到当前启动的调试器, 与launch.json配置相同",
"ahk2.description": "基于 vscode-lsp 协议的 Autohotkey2 语言支持",
"ahk2.diagnostic.full": "诊断全文",
Expand All @@ -26,7 +27,7 @@
"ahk2.generatecomment": "生成注释模板",
"ahk2.help": "快捷帮助",
"ahk2.interpreterpath": "`AutoHotkey.exe`可执行文件的路径. 如果选择`AutoHotkeyUX.exe`, 将使用UX Launcher启动脚本.",
"ahk2.run": "运行脚本",
"ahk2.run": "运行ahk文件",
"ahk2.selection.run": "运行选择的脚本",
"ahk2.setinterpreter": "选择AutoHotkey2解释器",
"ahk2.setscriptdir": "设置此处为A_ScriptDir",
Expand Down

0 comments on commit 2f7a83b

Please sign in to comment.