Skip to content

Commit 3dadb29

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 3dadb29

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

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 is 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).

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,5 @@
11
import * as vscode from 'vscode';
2+
import * as path from 'path';
23

34
export function fetchWsFolder(opts?: { showWarning?: boolean }): vscode.WorkspaceFolder | null {
45
const file = vscode.window.activeTextEditor?.document.uri.fsPath;
@@ -21,3 +22,68 @@ export function fetchWsFolder(opts?: { showWarning?: boolean }): vscode.Workspac
2122

2223
return wsFolder;
2324
}
25+
26+
const dllPathTemplate = '{dllPath}';
27+
const debuggerCodeSnippet = `-- Start of Tarantool debugger block. Remove after debugging.
28+
do
29+
local old_cpath = package.cpath
30+
package.cpath = package.cpath .. ";${dllPathTemplate}"
31+
rawset(_G, 'tolua', false)
32+
rawset(_G, 'xlua', false)
33+
rawset(_G, 'emmyHelper', {})
34+
local dbg = require('emmy_core')
35+
local log = require('log')
36+
_G.emmyHelperInit()
37+
function init_debugger()
38+
dbg.tcpListen('localhost', 9966)
39+
dbg.waitIDE()
40+
end
41+
local ok, err = pcall(init_debugger)
42+
if ok then
43+
log.info('Set up Tarantool for debugging')
44+
else
45+
log.warn('Unable to start debugger: %s', err)
46+
end
47+
package.cpath = old_cpath
48+
end
49+
-- End of Tarantool debugger block. Remove after debugging.
50+
`;
51+
52+
export async function insertDebuggerCode() {
53+
const activeEditor = vscode.window.activeTextEditor;
54+
if (!activeEditor) {
55+
vscode.window.showWarningMessage(`You should have an active text editor window to insert Tarantool debugger code. Consider opening a file`);
56+
return;
57+
}
58+
const document = activeEditor.document;
59+
if (document.languageId !== 'lua') {
60+
vscode.window.showWarningMessage(`Tarantool Debugger code is supposed to be used within .lua files`);
61+
return;
62+
}
63+
64+
let dllPath = '';
65+
const extensionPath = __dirname;
66+
const isWindows = process.platform === 'win32';
67+
const isMac = process.platform === 'darwin';
68+
const isLinux = process.platform === 'linux';
69+
if (isWindows) {
70+
const arch = await vscode.window.showQuickPick(['x64', 'x86']);
71+
if (!arch) {
72+
return;
73+
}
74+
dllPath = path.join(extensionPath, `debugger/emmy/windows/${arch}/?.dll`);
75+
} else if (isMac) {
76+
const arch = await vscode.window.showQuickPick(['x64', 'arm64']);
77+
if (!arch) {
78+
return;
79+
}
80+
dllPath = path.join(extensionPath, `debugger/emmy/mac/${arch}/emmy_core.dylib`);
81+
}
82+
else if (isLinux) {
83+
dllPath = path.join(extensionPath, `debugger/emmy/linux/emmy_core.so`);
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)