Skip to content

Commit f67feb4

Browse files
authored
Merge pull request #5 from jaseci-labs/debugger_setup
🚀 Automate Visual Debugger Setup - One-Click Debugging Experience
2 parents d0362b6 + 5285286 commit f67feb4

File tree

4 files changed

+119
-24
lines changed

4 files changed

+119
-24
lines changed

package.json

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,14 @@
4444
}
4545
}
4646
},
47-
"debuggers": [
48-
{
49-
"type": "jacdebug",
50-
"label": "Jac Debug",
51-
"initialConfigurations": [
52-
{
53-
"type": "debugpy",
54-
"request": "launch",
55-
"name": "Run a jac file",
56-
"program": "${command:extension.jaclang-extension.getJacPath}",
57-
"args": "run ${file}"
58-
}
59-
]
60-
}
61-
],
6247
"commands": [
6348
{
6449
"command": "jaclang-extension.visualizeGraph",
65-
"title": "jacvis: Visualize Jaclang Graph"
50+
"title": "Jac: Visualize Graph"
6651
},
6752
{
6853
"command": "jaclang-extension.selectEnv",
69-
"title": "Jaclang: Select Environment"
54+
"title": "Jac: Select Environment"
7055
},
7156
{
7257
"command": "jaclang-extension.toggleDeveloperMode",
@@ -83,9 +68,9 @@
8368
"icon": "$(play)"
8469
},
8570
{
86-
"command": "jaclang-extension.checkCurrentFile",
87-
"title": "Jac: Check",
88-
"icon": "$(shield)"
71+
"command": "jaclang-extension.debugCurrentFile",
72+
"title": "Jac: Debug",
73+
"icon": "$(debug-alt)"
8974
},
9075
{
9176
"command": "jaclang-extension.serveCurrentFile",
@@ -101,7 +86,7 @@
10186
"when": "resourceLangId == jac"
10287
},
10388
{
104-
"command": "jaclang-extension.checkCurrentFile",
89+
"command": "jaclang-extension.debugCurrentFile",
10590
"group": "navigation@1",
10691
"when": "resourceLangId == jac"
10792
}
@@ -142,6 +127,76 @@
142127
"scopeName": "source.jac",
143128
"path": "./syntaxes/jac.tmLanguage.json"
144129
}
130+
],
131+
"debuggers": [
132+
{
133+
"type": "jacdebug",
134+
"label": "Jac Debug",
135+
"configurationAttributes": {
136+
"launch": {
137+
"required": [],
138+
"properties": {
139+
"program": {
140+
"type": "string",
141+
"description": "Path to the Jac executable",
142+
"default": "${command:extension.jaclang-extension.getJacPath}"
143+
},
144+
"args": {
145+
"type": "array",
146+
"description": "Command line arguments passed to the program",
147+
"items": {
148+
"type": "string"
149+
},
150+
"default": ["run", "${file}"]
151+
},
152+
"console": {
153+
"enum": ["internalConsole", "integratedTerminal", "externalTerminal"],
154+
"description": "Where to launch the debug target",
155+
"default": "integratedTerminal"
156+
},
157+
"justMyCode": {
158+
"type": "boolean",
159+
"description": "Enable/disable debugging just the user's code",
160+
"default": true
161+
}
162+
}
163+
}
164+
},
165+
"initialConfigurations": [
166+
{
167+
"type": "debugpy",
168+
"request": "launch",
169+
"name": "Jac: Debug Current File",
170+
"python": "${command:extension.jaclang-extension.getPythonPath}",
171+
"program": "${command:extension.jaclang-extension.getJacPath}",
172+
"args": [
173+
"run",
174+
"${file}"
175+
],
176+
"console": "integratedTerminal",
177+
"justMyCode": true
178+
}
179+
],
180+
"configurationSnippets": [
181+
{
182+
"label": "Jac: Debug Current File",
183+
"description": "Debug the currently active Jac file",
184+
"body": {
185+
"type": "debugpy",
186+
"request": "launch",
187+
"name": "Jac: Debug Current File",
188+
"python": "${command:extension.jaclang-extension.getPythonPath}",
189+
"program": "${command:extension.jaclang-extension.getJacPath}",
190+
"args": [
191+
"run",
192+
"${file}"
193+
],
194+
"console": "integratedTerminal",
195+
"justMyCode": true
196+
}
197+
}
198+
]
199+
}
145200
]
146201
},
147202
"main": "./out/extension.js",

src/commands/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,30 @@ export function registerAllCommands(context: vscode.ExtensionContext, envManager
1616
})
1717
);
1818
context.subscriptions.push(
19-
vscode.commands.registerCommand(COMMANDS.CHECK_FILE, () => {
20-
runJacCommandForCurrentFile('check', envManager);
19+
vscode.commands.registerCommand(COMMANDS.DEBUG_FILE, async () => {
20+
const editor = vscode.window.activeTextEditor;
21+
if (!editor || editor.document.languageId !== 'jac') {
22+
vscode.window.showErrorMessage('Please open a Jac file to debug.');
23+
return;
24+
}
25+
26+
// Open the visual debugger webview
27+
await vscode.commands.executeCommand(COMMANDS.VISUALIZE);
28+
29+
// Start debugging with dynamic configuration
30+
await vscode.debug.startDebugging(
31+
vscode.workspace.getWorkspaceFolder(editor.document.uri),
32+
{
33+
type: 'debugpy',
34+
request: 'launch',
35+
name: 'Jac: Debug Current File',
36+
python: envManager.getPythonPath(),
37+
program: envManager.getJacPath(),
38+
args: ['run', editor.document.uri.fsPath],
39+
console: 'integratedTerminal',
40+
justMyCode: true
41+
}
42+
);
2143
})
2244
);
2345
context.subscriptions.push(
@@ -31,6 +53,12 @@ export function registerAllCommands(context: vscode.ExtensionContext, envManager
3153
return envManager.getJacPath();
3254
})
3355
);
56+
context.subscriptions.push(
57+
vscode.commands.registerCommand(COMMANDS.GET_PYTHON_PATH, () => {
58+
// Use envManager to get the Python path from same environment as Jac
59+
return envManager.getPythonPath();
60+
})
61+
);
3462
context.subscriptions.push(
3563
vscode.commands.registerCommand(COMMANDS.TOGGLE_DEV_MODE, async () => {
3664
const config = vscode.workspace.getConfiguration('jaclang-extension');

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ export const TERMINAL_NAME = "Jac Terminal";
22

33
export const COMMANDS = {
44
RUN_FILE: 'jaclang-extension.runCurrentFile',
5-
CHECK_FILE: 'jaclang-extension.checkCurrentFile',
65
SERVE_FILE: 'jaclang-extension.serveCurrentFile',
6+
DEBUG_FILE: 'jaclang-extension.debugCurrentFile',
77
SELECT_ENV: 'jaclang-extension.selectEnv',
88
TOGGLE_DEV_MODE: 'jaclang-extension.toggleDeveloperMode',
99
RESTART_LSP: 'jaclang-extension.restartLanguageServer',
1010
GET_JAC_PATH: 'extension.jaclang-extension.getJacPath',
11+
GET_PYTHON_PATH: 'extension.jaclang-extension.getPythonPath',
1112
VISUALIZE: 'jaclang-extension.visualizeGraph',
1213
};

src/environment/manager.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ export class EnvManager {
5353
return process.platform === 'win32' ? 'jac.exe' : 'jac';
5454
}
5555

56+
getPythonPath(): string {
57+
if (this.jacPath) {
58+
// Convert jac path to python path (same directory)
59+
const jacDir = path.dirname(this.jacPath);
60+
const pythonExecutable = process.platform === 'win32' ? 'python.exe' : 'python';
61+
return path.join(jacDir, pythonExecutable);
62+
}
63+
// Fallback: try to find python in PATH
64+
return process.platform === 'win32' ? 'python.exe' : 'python';
65+
}
66+
5667
async promptEnvironmentSelection() {
5768
try {
5869
const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || process.cwd();

0 commit comments

Comments
 (0)