Skip to content

Add Tarantool debugging facilities #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Support for debugging Tarantool code using
[EmmyLuaDebugger](https://github.com/EmmyLua/EmmyLuaDebugger).

## [0.2.0] - 28.05.2025

### Added
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<img src="https://avatars2.githubusercontent.com/u/2344919?v=2&s=100" align="right">
</a>

Tarantool VS Code Extension helps you to develop Tarantool applications in VS Code. It enhances your text editor with completions, suggestions, and snippets.
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.

---

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

---

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

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

You may statically type your Lua functions as follows.

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

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

## Using debugger

Tarantool VS Code extension provides debugger facility for developing Tarantool applications. It is employs EmmyLuaDebugger that is a stop-the-world Lua debugger.

* 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.

## Contributing

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).
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
{
"command": "tarantool.install-ce",
"title": "Tarantool: Install Tarantool Community Edition (tt)"
},
{
"command": "tarantool.debugger-code",
"title": "Tarantool: Insert debugger code"
}
],
"yamlValidation": [
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import * as tt from './tt';
import * as fs from 'fs';
import * as _ from 'lodash';

Check warning on line 4 in src/extension.ts

View workflow job for this annotation

GitHub Actions / Lint

Import name `_` must match one of the following formats: camelCase, PascalCase
import * as semver from 'semver';
import * as utils from './utils';

Expand Down Expand Up @@ -115,6 +115,7 @@
{ name: 'stat', cb: tt.stat },
{ name: 'restart', cb: tt.restart },
{ name: 'install-ce', cb: tt.installCe },
{ name: 'debugger-code', cb: utils.insertDebuggerCode },
];

commands.forEach((command) => {
Expand Down
66 changes: 66 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import * as path from 'path';

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

return wsFolder;
}

const dllPathTemplate = '{dllPath}';
const debuggerCodeSnippet = `-- Start of Tarantool debugger block. Remove after debugging.
do
local old_cpath = package.cpath
package.cpath = package.cpath .. ";${dllPathTemplate}"
rawset(_G, 'tolua', false)
rawset(_G, 'xlua', false)
rawset(_G, 'emmyHelper', {})
local dbg = require('emmy_core')
local log = require('log')
_G.emmyHelperInit()
function init_debugger()
dbg.tcpListen('localhost', 9966)
dbg.waitIDE()
end
local ok, err = pcall(init_debugger)
if ok then
log.info('Set up Tarantool for debugging')
else
log.warn('Unable to start debugger: %s', err)
end
package.cpath = old_cpath
end
-- End of Tarantool debugger block. Remove after debugging.
`;

export async function insertDebuggerCode() {
const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showWarningMessage(`You should have an active text editor window to insert Tarantool debugger code. Consider opening a file`);
return;
}
const document = activeEditor.document;
if (document.languageId !== 'lua') {
vscode.window.showWarningMessage(`Tarantool Debugger code is supposed to be used within .lua files`);
return;
}

let dllPath = '';
const extensionPath = __dirname;
const isWindows = process.platform === 'win32';
const isMac = process.platform === 'darwin';
const isLinux = process.platform === 'linux';
if (isWindows) {
const arch = await vscode.window.showQuickPick(['x64', 'x86']);
if (!arch) {
return;
}
dllPath = path.join(extensionPath, `debugger/emmy/windows/${arch}/?.dll`);
} else if (isMac) {
const arch = await vscode.window.showQuickPick(['x64', 'arm64']);
if (!arch) {
return;
}
dllPath = path.join(extensionPath, `debugger/emmy/mac/${arch}/emmy_core.dylib`);
}
else if (isLinux) {
dllPath = path.join(extensionPath, `debugger/emmy/linux/emmy_core.so`);
}

const snippet = new vscode.SnippetString();
snippet.appendText(debuggerCodeSnippet.replace(dllPathTemplate, dllPath.replace(/\\/g, '/')));
activeEditor.insertSnippet(snippet);
}