Skip to content

Commit ca353d3

Browse files
Add Tarantool debugging facilities
This patch introduces basic Tarantool debugging facilities into the extension. Basically it is done using EmmyLuaDebugger [^1]. Set up the debugger using the following instructions. * Insert debugger code in Tarantool application by pressing `Ctrl+Shift+P` (or `Cmd+Shift+P` on MacOS) and running `Tarantool: Insert debugger code` command. * Start single Tarantool instance. * Press `F5` or run `Debug: Start debugging` command by pressing `Ctrl+Shift+P` (or `Cmd+Shift+P` on MacOS). * Choose `EmmyLua New Debugger` in the list. This debugging configuration would run automatically from now. * Set up breakpoints & access the Tarantool instance through `Debug console` in the bottom panel. These features are supported. * Breakpoints. * Step-by-step execution within the fiber. * Multiple files support. * Interacting with the local variables, console at the debug mode. Needs EmmyLua/EmmyLuaDebugger#75 to be tested on MacOS on arm64. Closes #19 [^1] EmmyLua/EmmyLuaDebugger#75
1 parent f7d96e5 commit ca353d3

11 files changed

+104
-3
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.png filter=lfs diff=lfs merge=lfs -text
2+
debugger/*.dylib filter=lfs diff=lfs merge=lfs -text
3+
debugger/*.so filter=lfs diff=lfs merge=lfs -text

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
### Added
12+
13+
- Support for debugging Tarantool code using
14+
[EmmyLuaDebugger](https://github.com/EmmyLua/EmmyLuaDebugger).
15+
1116
## [0.2.0] - 28.05.2025
1217

1318
### Added

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<img src="https://avatars2.githubusercontent.com/u/2344919?v=2&s=100" align="right">
99
</a>
1010

11-
Tarantool VS Code Extension helps you to develop Tarantool applications in VS Code. It enhances your text editor with completions, suggestions, and snippets.
11+
Tarantool VS Code Extension helps you to develop Tarantool applications in VS Code. It enhances your text editor with completions, suggestions, snippets, and Lua debugger.
1212

1313
---
1414

@@ -22,6 +22,7 @@ This extension offers the following features.
2222
* Cluster configuration schema validation for Tarantool 3.0+.
2323
* [tt cluster management utility](https://github.com/tarantool/tt) inside the command palette.
2424
* Other auxiliary commands, e.g. install Tarantool of a specific version right from VS Code.
25+
* Debugger for Tarantool apps, allowing breakpoints, step-by-step execution, viewing local variables and Lua code execution.
2526

2627
---
2728

@@ -31,7 +32,6 @@ That's how you use this extension.
3132

3233
* Install the extension from the VS Code marketplace.
3334
* Open a Tarantool project in VS Code.
34-
* Run `Tarantool: Initialize VS Code extension in existing app` command from the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on macOS).
3535

3636
You may statically type your Lua functions as follows.
3737

@@ -54,6 +54,16 @@ local unnamed_user = { name = 'Unnamed' }
5454

5555
For more examples, refer to [the examples folder](examples/) with tutorials on how to type your Lua code.
5656

57+
## Using debugger
58+
59+
Tarantool VS Code extension provides debugger facility for developing Tarantool applications. It employs EmmyLuaDebugger that is a stop-the-world Lua debugger.
60+
61+
* Insert debugger code in Tarantool application by pressing `Ctrl+Shift+P` (or `Cmd+Shift+P` on MacOS) and running `Tarantool: Insert debugger code` command.
62+
* Start single Tarantool instance.
63+
* Press `F5` or run `Debug: Start debugging` command by pressing `Ctrl+Shift+P` (or `Cmd+Shift+P` on MacOS).
64+
* Choose `EmmyLua New Debugger` in the list. This debugging configuration would run automatically from now.
65+
* Set up breakpoints & access the Tarantool instance through `Debug console` in the bottom panel.
66+
5767
## Contributing
5868

5969
Feel free to open issues on feature requests, wrong type annotations and bugs. If you're dealing with a problem related to LSP we'd appreciate addressing a direct issue to [the used external Lua Language server](https://github.com/CppCXY/emmylua-analyzer-rust).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:c5e7b3f8a837c65e4d127bfaf946f76a4643f12cf6e9c56a0ebd1a9656cfc325
3+
size 499856
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f4a99aa3bffb67d5501f24b433ffdc2cd0915bd7e933a976ce72ea226a688b52
3+
size 483288
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:6b71974688b2bdfc7571b1025d194406efb9b647487209231a2c55145372bc6e
3+
size 792432
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:0366b8247f936afb9651820714b4052ffe72117f16dea91c19a3d866df0cf3b9
3+
size 778632

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
{
6262
"command": "tarantool.install-ce",
6363
"title": "Tarantool: Install Tarantool Community Edition (tt)"
64+
},
65+
{
66+
"command": "tarantool.debugger-code",
67+
"title": "Tarantool: Insert debugger code"
6468
}
6569
],
6670
"yamlValidation": [

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export function activate(context: vscode.ExtensionContext) {
115115
{ name: 'stat', cb: tt.stat },
116116
{ name: 'restart', cb: tt.restart },
117117
{ name: 'install-ce', cb: tt.installCe },
118+
{ name: 'debugger-code', cb: utils.insertDebuggerCode },
118119
];
119120

120121
commands.forEach((command) => {

src/utils.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as vscode from 'vscode';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
24

35
export function fetchWsFolder(opts?: { showWarning?: boolean }): vscode.WorkspaceFolder | null {
46
const file = vscode.window.activeTextEditor?.document.uri.fsPath;
@@ -21,3 +23,67 @@ export function fetchWsFolder(opts?: { showWarning?: boolean }): vscode.Workspac
2123

2224
return wsFolder;
2325
}
26+
27+
const dllPathTemplate = '{dllPath}';
28+
const debuggerCodeSnippet = `-- Start of Tarantool debugger block. Remove after debugging.
29+
do
30+
local old_cpath = package.cpath
31+
package.cpath = package.cpath .. ";${dllPathTemplate}"
32+
rawset(_G, 'tolua', false)
33+
rawset(_G, 'xlua', false)
34+
rawset(_G, 'emmyHelper', {})
35+
local dbg = require('emmy_core')
36+
local log = require('log')
37+
_G.emmyHelperInit()
38+
function init_debugger()
39+
dbg.tcpListen('localhost', 9966)
40+
dbg.waitIDE()
41+
end
42+
local ok, err = pcall(init_debugger)
43+
if ok then
44+
log.info('Set up Tarantool for debugging')
45+
else
46+
log.warn('Unable to start debugger: %s', err)
47+
end
48+
package.cpath = old_cpath
49+
end
50+
-- End of Tarantool debugger block. Remove after debugging.
51+
`;
52+
53+
const supportedDebuggerPlatforms = ['darwin', 'linux'];
54+
const supportedDebuggerArchs = ['x64', 'arm64'];
55+
56+
export async function insertDebuggerCode() {
57+
const activeEditor = vscode.window.activeTextEditor;
58+
if (!activeEditor) {
59+
vscode.window.showWarningMessage(`You should have an active text editor window to insert Tarantool debugger code. Consider opening a file`);
60+
return;
61+
}
62+
const document = activeEditor.document;
63+
if (document.languageId !== 'lua') {
64+
vscode.window.showWarningMessage(`Tarantool Debugger code is supposed to be used within .lua files`);
65+
return;
66+
}
67+
68+
const extensionPath = __dirname;
69+
const hostPlatform = process.platform;
70+
const platform = supportedDebuggerPlatforms.includes(hostPlatform) ? hostPlatform : (await vscode.window.showQuickPick(supportedDebuggerPlatforms));
71+
if (!platform)
72+
{return;}
73+
74+
const arch = await vscode.window.showQuickPick(supportedDebuggerArchs);
75+
if (!arch) {
76+
return;
77+
}
78+
79+
const extension = platform === 'darwin' ? 'dylib' : 'so';
80+
81+
const dllPath = path.join(extensionPath, `emmyluadebugger-${platform}-${arch}.${extension}`);
82+
if (!fs.existsSync(dllPath)) {
83+
vscode.window.showWarningMessage(`Unable to access the Tarantool debugger for ${platform} on ${arch}. Try reinstalling the extension. If it does not help consider manually modifying the "cpath" variable in the pasted debugger code`);
84+
}
85+
86+
const snippet = new vscode.SnippetString();
87+
snippet.appendText(debuggerCodeSnippet.replace(dllPathTemplate, dllPath.replace(/\\/g, '/')));
88+
activeEditor.insertSnippet(snippet);
89+
}

0 commit comments

Comments
 (0)