From: Brendan Hansen Date: Wed, 14 Feb 2024 21:43:31 +0000 (-0600) Subject: added: better VS Code support for debug session selection X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=275a6936d1e85b73f3811c8d7df7f136e4f51cf1;p=onyx.git added: better VS Code support for debug session selection --- diff --git a/misc/vscode/extension.ts b/misc/vscode/extension.ts index 97f8a58b..27534440 100644 --- a/misc/vscode/extension.ts +++ b/misc/vscode/extension.ts @@ -1,15 +1,73 @@ import * as vscode from "vscode"; import * as vsctmls from 'vscode-textmate-languageservice'; +import * as fs from "fs"; import * as vslc2 from "vscode-languageclient"; import * as vslc from "vscode-languageclient/node"; let client: vslc.LanguageClient; +function get_onyx_path() { + let onyx_path = process.env['ONYX_PATH']; + if (!onyx_path) { + onyx_path = require('os').homedir() + "/.onyx"; + process.env["ONYX_PATH"] = onyx_path; + process.env["PATH"] = process.env["PATH"] + ":" + onyx_path + "/bin" + } + return onyx_path; +} + +function registerCommands() { + vscode.commands.registerCommand('extension.pickOnyxSession', () => { + return new Promise((res, rej) => { + let onyx_path = get_onyx_path(); + + const sessionEntries = fs + .readdirSync(onyx_path) + .filter(file => file.startsWith("debug.")) + .map(file => ({ + label: file.split(".")[1], + pid: parseInt(file.split(".")[1]) + })) + + if (sessionEntries.length == 0) { rej(new Error("No sessions waiting to be debugged")); return; } + if (sessionEntries.length == 1) { res(`${onyx_path}/debug.${sessionEntries[0].pid}`); return; } + + const quickPick = vscode.window.createQuickPick<{label: string, pid: number}>(); + quickPick.title = "Attach to session"; + quickPick.canSelectMany = false; + quickPick.matchOnDescription = true; + quickPick.matchOnDetail = true; + quickPick.placeholder = "Select the session to attach to"; + quickPick.items = sessionEntries; + + quickPick.onDidAccept(() => { + if (quickPick.selectedItems.length !== 1) { + rej(new Error(`Session not selected. case one`)); + } + + const selectedId = quickPick.selectedItems[0].pid; + quickPick.dispose(); + + res(`${onyx_path}/debug.${selectedId}`); + }); + + quickPick.onDidHide(() => { + quickPick.dispose(); + }); + + quickPick.show(); + }); + }); + +} + export async function activate(context: vscode.ExtensionContext) { let console = vscode.window.createOutputChannel("Onyx Extension"); console.appendLine("Starting Onyx Extension"); + registerCommands(); + const selector: vscode.DocumentSelector = { language: 'onyx', scheme: "file" }; const engine = new vsctmls.textmateEngine.TextmateEngine('onyx', 'source.onyx'); const documentSymbolProvider = new vsctmls.documentSymbols.DocumentSymbolProvider(engine); @@ -20,12 +78,7 @@ export async function activate(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(workspaceSymbolProvider)); context.subscriptions.push(vscode.languages.registerDefinitionProvider({ 'language': 'onyx' }, peekFileDefinitionProvider)); - let onyx_path = process.env['ONYX_PATH']; - if (!onyx_path) { - onyx_path = require('os').homedir() + "/.onyx"; - process.env["ONYX_PATH"] = onyx_path; - process.env["PATH"] = process.env["PATH"] + ":" + onyx_path + "/bin" - } + let onyx_path = get_onyx_path(); let executable = `${onyx_path}/bin/onyx`; if (process.platform == "win32") { diff --git a/misc/vscode/onyxlang-0.1.10.vsix b/misc/vscode/onyxlang-0.1.10.vsix new file mode 100644 index 00000000..6a65c31e Binary files /dev/null and b/misc/vscode/onyxlang-0.1.10.vsix differ diff --git a/misc/vscode/out/extension.js b/misc/vscode/out/extension.js index 9c416e10..2be9d694 100644 --- a/misc/vscode/out/extension.js +++ b/misc/vscode/out/extension.js @@ -12,12 +12,64 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.deactivate = exports.activate = void 0; const vscode = require("vscode"); const vsctmls = require("vscode-textmate-languageservice"); +const fs = require("fs"); const vslc = require("vscode-languageclient/node"); let client; +function get_onyx_path() { + let onyx_path = process.env['ONYX_PATH']; + if (!onyx_path) { + onyx_path = require('os').homedir() + "/.onyx"; + process.env["ONYX_PATH"] = onyx_path; + process.env["PATH"] = process.env["PATH"] + ":" + onyx_path + "/bin"; + } + return onyx_path; +} +function registerCommands() { + vscode.commands.registerCommand('extension.pickOnyxSession', () => { + return new Promise((res, rej) => { + let onyx_path = get_onyx_path(); + const sessionEntries = fs + .readdirSync(onyx_path) + .filter(file => file.startsWith("debug.")) + .map(file => ({ + label: file.split(".")[1], + pid: parseInt(file.split(".")[1]) + })); + if (sessionEntries.length == 0) { + rej(new Error("No sessions waiting to be debugged")); + return; + } + if (sessionEntries.length == 1) { + res(`${onyx_path}/debug.${sessionEntries[0].pid}`); + return; + } + const quickPick = vscode.window.createQuickPick(); + quickPick.title = "Attach to session"; + quickPick.canSelectMany = false; + quickPick.matchOnDescription = true; + quickPick.matchOnDetail = true; + quickPick.placeholder = "Select the session to attach to"; + quickPick.items = sessionEntries; + quickPick.onDidAccept(() => { + if (quickPick.selectedItems.length !== 1) { + rej(new Error(`Session not selected. case one`)); + } + const selectedId = quickPick.selectedItems[0].pid; + quickPick.dispose(); + res(`${onyx_path}/debug.${selectedId}`); + }); + quickPick.onDidHide(() => { + quickPick.dispose(); + }); + quickPick.show(); + }); + }); +} function activate(context) { return __awaiter(this, void 0, void 0, function* () { let console = vscode.window.createOutputChannel("Onyx Extension"); console.appendLine("Starting Onyx Extension"); + registerCommands(); const selector = { language: 'onyx', scheme: "file" }; const engine = new vsctmls.textmateEngine.TextmateEngine('onyx', 'source.onyx'); const documentSymbolProvider = new vsctmls.documentSymbols.DocumentSymbolProvider(engine); @@ -26,12 +78,7 @@ function activate(context) { context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(selector, documentSymbolProvider)); context.subscriptions.push(vscode.languages.registerWorkspaceSymbolProvider(workspaceSymbolProvider)); context.subscriptions.push(vscode.languages.registerDefinitionProvider({ 'language': 'onyx' }, peekFileDefinitionProvider)); - let onyx_path = process.env['ONYX_PATH']; - if (!onyx_path) { - onyx_path = require('os').homedir() + "/.onyx"; - process.env["ONYX_PATH"] = onyx_path; - process.env["PATH"] = process.env["PATH"] + ":" + onyx_path + "/bin"; - } + let onyx_path = get_onyx_path(); let executable = `${onyx_path}/bin/onyx`; if (process.platform == "win32") { // Windows distributions are different diff --git a/misc/vscode/package.json b/misc/vscode/package.json index a57961a6..74fe3095 100644 --- a/misc/vscode/package.json +++ b/misc/vscode/package.json @@ -2,7 +2,7 @@ "name": "onyxlang", "displayName": "Onyx Programming Language", "description": "Onyx syntax highlighting and debugger support.", - "version": "0.1.9", + "version": "0.1.10", "publisher": "onyxlang", "license": "BSD-2-Clause", "engines": { @@ -73,13 +73,16 @@ "label": "Onyx Debug", "program": "./out/debugAdapter.js", "runtime": "node", + "variables": { + "pickSession": "extension.pickOnyxSession" + }, "configurationAttributes": { "attach": { "properties": { "socketPath": { "type": "string", "description": "Path to UNIX socket for attaching to debugger", - "default": "/tmp/ovm-debug.0000" + "default": "${command:pickSession}" }, "stopOnEntry": { "type": "boolean", diff --git a/tests/for_loop_indexes b/tests/for_loop_indexes new file mode 100644 index 00000000..77afe771 --- /dev/null +++ b/tests/for_loop_indexes @@ -0,0 +1,125 @@ +0: 10 +1: 11 +2: 12 +3: 13 +4: 14 +5: 15 +6: 16 +7: 17 +8: 18 +9: 19 +10: 20 +11: 21 +12: 22 +13: 23 +14: 24 +15: 25 +16: 26 +17: 27 +18: 28 +19: 29 +20: 30 +21: 31 +22: 32 +23: 33 +24: 34 +25: 35 +26: 36 +27: 37 +28: 38 +29: 39 +30: 40 +31: 41 +32: 42 +33: 43 +34: 44 +35: 45 +36: 46 +37: 47 +38: 48 +39: 49 +40: 50 +41: 51 +42: 52 +43: 53 +44: 54 +45: 55 +46: 56 +47: 57 +48: 58 +49: 59 +50: 60 +51: 61 +52: 62 +53: 63 +54: 64 +55: 65 +56: 66 +57: 67 +58: 68 +59: 69 +60: 70 +61: 71 +62: 72 +63: 73 +64: 74 +65: 75 +66: 76 +67: 77 +68: 78 +69: 79 +70: 80 +71: 81 +72: 82 +73: 83 +74: 84 +75: 85 +76: 86 +77: 87 +78: 88 +79: 89 +80: 90 +81: 91 +82: 92 +83: 93 +84: 94 +85: 95 +86: 96 +87: 97 +88: 98 +89: 99 +(i64) 0: 20 +(i64) 1: 21 +(i64) 2: 22 +(i64) 3: 23 +(i64) 4: 24 +(i64) 5: 25 +(i64) 6: 26 +(i64) 7: 27 +(i64) 8: 28 +(i64) 9: 29 +(i64) 10: 30 +(i64) 11: 31 +(i64) 12: 32 +(i64) 13: 33 +(i64) 14: 34 +(i64) 15: 35 +(i64) 16: 36 +(i64) 17: 37 +(i64) 18: 38 +(i64) 19: 39 +(i64) 20: 40 +(i64) 21: 41 +(i64) 22: 42 +(i64) 23: 43 +(i64) 24: 44 +(i64) 25: 45 +(i64) 26: 46 +(i64) 27: 47 +(i64) 28: 48 +(i64) 29: 49 +0: 2 +1: 3 +2: 5 +3: 7 +4: 11 diff --git a/tests/for_loop_indexes.onyx b/tests/for_loop_indexes.onyx new file mode 100644 index 00000000..669166c9 --- /dev/null +++ b/tests/for_loop_indexes.onyx @@ -0,0 +1,26 @@ +use core {*} + +main :: () { + for value, index in 10 .. 100 { + // value: 10 -> 99 + // index: 0 -> 89 + // + // value is i32 + // index is i32 + printf("{}: {}\n", index, value); + } + + for value, index: i64 in 20 .. 50 { + // value: 20 -> 49 + // index: 0 -> 29 + // + // value is i32 + // index is i64 + printf("({}) {}: {}\n", typeof index, index, value); + } + + values := .[2, 3, 5, 7, 11]; + for value: i32, index in values { + printf("{}: {}\n", index, value); + } +}