Skip to content

Commit 2c4505f

Browse files
committed
Update program configuration settings
1 parent 2c7f1f8 commit 2c4505f

File tree

10 files changed

+75
-152
lines changed

10 files changed

+75
-152
lines changed

.github/workflows/bundle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ jobs:
2828

2929
- uses: actions/upload-artifact@v3
3030
with:
31-
name: tarantool-local-lua-debugger-vscode
32-
path: tarantool-local-lua-debugger-vscode-*.vsix
31+
name: tarantool-lua-debugger-vscode
32+
path: tarantool-lua-debugger-vscode-*.vsix

README.md

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,53 +18,24 @@ Beginning in version 0.3.0, projects which use sourcemaps to debug code transpil
1818
---
1919
## Usage
2020

21-
### Lua Stand-Alone Interpreter
22-
To debug a Lua program using a stand-alone interpreter, set `lua-local.interpreter` in your user or workspace settings:
23-
24-
!["lua-local.interpreter": "lua5.1"](resources/settings.png '"lua-local.interpreter": "lua5.1"')
21+
### Tarantool Lua Stand-Alone Interpreter
22+
To debug a Lua program using a stand-alone interpreter, set `lua-tarantool.interpreter` in your user or workspace settings.
2523

2624
Alternatively, you can set the interpreter and file to run in `launch.json`:
2725
```json
2826
{
2927
"configurations": [
3028
{
31-
"type": "lua-local",
29+
"type": "lua-tarantool",
3230
"request": "launch",
3331
"name": "Debug",
3432
"program": {
35-
"lua": "lua5.1",
36-
"file": "main.lua"
33+
"file": "init.lua"
3734
}
3835
}
3936
]
4037
}
4138
```
42-
43-
### Custom Lua Environment
44-
To debug using a custom Lua executable, you must set up your `launch.json` with the name/path of the executable and any additional arguments that may be needed.
45-
```json
46-
{
47-
"configurations": [
48-
{
49-
"type": "lua-local",
50-
"request": "launch",
51-
"name": "Debug Custom Executable",
52-
"program": {
53-
"command": "executable"
54-
},
55-
"args": [
56-
"${workspaceFolder}"
57-
]
58-
}
59-
]
60-
}
61-
```
62-
You must then manually start the debugger in your Lua code:
63-
```lua
64-
require("lldebugger").start()
65-
```
66-
Note that the path to `lldebugger` will automatically be appended to the `LUA_PATH` environment variable, so it can be found by Lua.
67-
6839
---
6940
## Requirements & Limitations
7041
- The Lua environment must support communication via either stdio or pipes (named pipes on Windows, fifos on Linux).

extension/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const EXTENSION_ID = "usenko-timur.tarantool-local-lua-debugger-vscode";
1+
export const EXTENSION_ID = "tarantool.tarantool-lua-debugger-vscode";

extension/extension.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import * as Net from "net";
2525
import * as path from "path";
2626
import {EXTENSION_ID} from "./constants";
2727
import {LuaDebugSession} from "./luaDebugSession";
28-
import {LaunchConfig, isCustomProgramConfig, LuaProgramConfig} from "./launchConfig";
28+
import {LaunchConfig, TarantoolProgramConfig} from "./launchConfig";
2929

3030
const enableServer = true;
31-
const debuggerType = "lua-local";
31+
const debuggerType = "lua-tarantool";
3232
const interpreterSetting = `${debuggerType}.interpreter`;
3333

3434
function abortLaunch(message: string) {
@@ -53,29 +53,30 @@ const configurationProvider: vscode.DebugConfigurationProvider = {
5353
config.type = debuggerType;
5454
}
5555

56-
if (typeof config.program === "undefined" || !isCustomProgramConfig(config.program)) {
57-
const luaConfig: Partial<LuaProgramConfig> = config.program ?? {};
58-
if (typeof luaConfig.lua === "undefined") {
59-
const luaBin: string | undefined = vscode.workspace.getConfiguration().get(interpreterSetting);
60-
if (typeof luaBin === "undefined" || luaBin.length === 0) {
61-
return abortLaunch(
62-
`You must set "${interpreterSetting}" in your settings, or "program.lua" `
63-
+ "in your launch.json, to debug with a lua interpreter."
64-
);
65-
}
66-
luaConfig.lua = luaBin;
56+
const luaConfig: Partial<TarantoolProgramConfig> = {
57+
tarantool: config.program?.tarantool,
58+
file: config.program?.file,
59+
};
60+
if (typeof luaConfig.tarantool === "undefined") {
61+
const luaBin: string | undefined = vscode.workspace.getConfiguration().get(interpreterSetting);
62+
if (typeof luaBin === "undefined" || luaBin.length === 0) {
63+
return abortLaunch(
64+
`You must set "${interpreterSetting}" in your settings, or "program.lua" `
65+
+ "in your launch.json, to debug with a lua interpreter."
66+
);
6767
}
68-
if (typeof luaConfig.file === "undefined") {
69-
if (typeof editor === "undefined"
70-
|| editor.document.languageId !== "lua"
71-
|| editor.document.isUntitled
72-
) {
73-
return abortLaunch("'program.file' not set in launch.json");
74-
}
75-
luaConfig.file = editor.document.uri.fsPath;
68+
luaConfig.tarantool = luaBin;
69+
}
70+
if (typeof luaConfig.file === "undefined") {
71+
if (typeof editor === "undefined"
72+
|| editor.document.languageId !== "lua"
73+
|| editor.document.isUntitled
74+
) {
75+
return abortLaunch("'program.file' not set in launch.json");
7676
}
77-
config.program = luaConfig as LuaProgramConfig;
77+
luaConfig.file = editor.document.uri.fsPath;
7878
}
79+
config.program = luaConfig as TarantoolProgramConfig;
7980

8081
if (Array.isArray(config.scriptFiles)) {
8182
const nonString = config.scriptFiles.find(p => typeof p !== "string");

extension/launchConfig.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,16 @@
2020
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
//SOFTWARE.
2222

23-
export interface LuaProgramConfig {
24-
lua: string;
23+
export interface TarantoolProgramConfig {
24+
tarantool?: string;
2525
file: string;
2626
communication?: string;
2727
}
2828

29-
export interface CustomProgramConfig {
30-
command: string;
31-
communication?: string;
32-
}
33-
3429
export interface LaunchConfig {
3530
extensionPath: string;
3631
workspacePath: string;
37-
program: LuaProgramConfig | CustomProgramConfig;
32+
program: TarantoolProgramConfig;
3833
args?: string[];
3934
cwd: string;
4035
env?: { [name: string]: string };
@@ -46,7 +41,3 @@ export interface LaunchConfig {
4641
scriptFiles?: string[];
4742
ignorePatterns?: string[];
4843
}
49-
50-
export function isCustomProgramConfig(config: LuaProgramConfig | CustomProgramConfig): config is CustomProgramConfig {
51-
return typeof (config as CustomProgramConfig).command !== "undefined";
52-
}

extension/luaDebugSession.ts

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import * as childProcess from "child_process";
4040
import * as path from "path";
4141
import * as fs from "fs";
4242
import {Message} from "./message";
43-
import {LaunchConfig, isCustomProgramConfig} from "./launchConfig";
44-
import {createFifoPipe, createNamedPipe, DebugPipe} from "./debugPipe";
43+
import {LaunchConfig} from "./launchConfig";
44+
import {createFifoPipe, DebugPipe} from "./debugPipe";
4545

4646
interface MessageHandler<T extends LuaDebug.Message = LuaDebug.Message> {
4747
(msg: T): void;
@@ -213,7 +213,7 @@ export class LuaDebugSession extends LoggingDebugSession {
213213
env: Object.assign({}, process.env),
214214
cwd,
215215
shell: true,
216-
detached: process.platform !== "win32"
216+
detached: true,
217217
};
218218

219219
if (typeof this.config.env !== "undefined") {
@@ -241,11 +241,7 @@ export class LuaDebugSession extends LoggingDebugSession {
241241

242242
//Open pipes
243243
if (this.config.program.communication === "pipe") {
244-
if (process.platform === "win32") {
245-
this.debugPipe = createNamedPipe();
246-
} else {
247-
this.debugPipe = createFifoPipe();
248-
}
244+
this.debugPipe = createFifoPipe();
249245
this.debugPipe.open(
250246
data => { void this.onDebuggerOutput(data); },
251247
err => { this.showOutput(`${err}`, OutputCategory.Error); }
@@ -262,28 +258,22 @@ export class LuaDebugSession extends LoggingDebugSession {
262258
this.updateLuaPath("LUA_PATH", processOptions.env, true);
263259

264260
//Launch process
265-
let processExecutable: string;
266-
let processArgs: string[];
267-
if (isCustomProgramConfig(this.config.program)) {
268-
processExecutable = `"${this.config.program.command}"`;
269-
processArgs = typeof this.config.args !== "undefined" ? this.config.args : [];
261+
const processExecutable = `"${this.config.program.tarantool}"`;
262+
const configArgs = (typeof this.config.args !== "undefined")
263+
? `, ${this.config.args.map(a => `[[${a}]]`)}`
264+
: "";
265+
const processArgs: string[] = [
266+
"-e",
267+
"\"require 'strict'.off()\"",
268+
"-e",
269+
"\"require('lldebugger').runFile("
270+
+ `[[${this.config.program.file}]],`
271+
+ "true,"
272+
+ `{[-1]=[[${this.config.program.tarantool}]],[0]=[[${this.config.program.file}]]${configArgs}}`
273+
+ ")\""
274+
];
270275

271-
} else {
272-
processExecutable = `"${this.config.program.lua}"`;
273-
const programArgs = (typeof this.config.args !== "undefined")
274-
? `, ${this.config.args.map(a => `[[${a}]]`)}`
275-
: "";
276-
processArgs = [
277-
"-e",
278-
"\"require('lldebugger').runFile("
279-
+ `[[${this.config.program.file}]],`
280-
+ "true,"
281-
+ `{[-1]=[[${this.config.program.lua}]],[0]=[[${this.config.program.file}]]${programArgs}}`
282-
+ ")\""
283-
];
284-
}
285276
this.process = childProcess.spawn(processExecutable, processArgs, processOptions);
286-
287277
this.showOutput(
288278
`launching \`${processExecutable} ${processArgs.join(" ")}\` from "${cwd}"`,
289279
OutputCategory.Info
@@ -703,11 +693,7 @@ export class LuaDebugSession extends LoggingDebugSession {
703693
this.showOutput("terminateRequest", OutputCategory.Request);
704694

705695
if (this.process !== null) {
706-
if (process.platform === "win32") {
707-
childProcess.spawn("taskkill", ["/pid", this.assert(this.process.pid).toString(), "/f", "/t"]);
708-
} else {
709-
process.kill(-this.assert(this.process.pid), "SIGKILL");
710-
}
696+
process.kill(-this.assert(this.process.pid), "SIGKILL");
711697
}
712698

713699
this.isRunning = false;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"name": "tarantool-local-lua-debugger-vscode",
3-
"publisher": "usenko-timur",
4-
"version": "0.3.3",
5-
"description": "Tarantool Local Lua Debugger - tarantool local lua debugger with no dependencies",
6-
"displayName": "Tarantool Local Lua Debugger",
2+
"name": "tarantool-lua-debugger-vscode",
3+
"publisher": "tarantool",
4+
"version": "0.4.0",
5+
"description": "Tarantool Lua Debugger - tarantool lua debugger with no dependencies",
6+
"displayName": "Tarantool Lua Debugger",
77
"icon": "resources/tarantool-logo-small_128x128.png",
88
"repository": {
99
"type": "github",
@@ -20,9 +20,6 @@
2020
"tstl",
2121
"typescripttolua",
2222
"typescript-to-lua",
23-
"love",
24-
"löve",
25-
"corona",
2623
"tarantool"
2724
],
2825
"scripts": {
@@ -59,12 +56,12 @@
5956
"contributes": {
6057
"configuration": [
6158
{
62-
"title": "Local Lua Debugger",
59+
"title": "Tarantool Lua Debugger",
6360
"properties": {
64-
"lua-local.interpreter": {
61+
"lua-tarantool.interpreter": {
6562
"type": "string",
66-
"default": "",
67-
"description": "Lua stand-alone interpreter to use when none is specified in launch.json"
63+
"default": "tarantool",
64+
"description": "Tarantool Lua stand-alone interpreter to use when none is specified in launch.json"
6865
}
6966
}
7067
}
@@ -76,29 +73,21 @@
7673
],
7774
"debuggers": [
7875
{
79-
"type": "lua-local",
80-
"label": "Local Lua Debugger",
76+
"type": "lua-tarantool",
77+
"label": "Tarantool Lua Debugger",
8178
"program": "./extension/debugAdapter.js",
8279
"runtime": "node",
8380
"languages": [
8481
"lua"
8582
],
8683
"initialConfigurations": [
8784
{
88-
"name": "Debug Lua Interpreter",
89-
"type": "lua-local",
85+
"name": "Debug Tarantool Lua Interpreter",
86+
"type": "lua-tarantool",
9087
"request": "launch",
9188
"program": {
92-
"lua": "lua",
89+
"tarantool": "tarantool",
9390
"file": "${file}"
94-
}
95-
},
96-
{
97-
"name": "Debug Custom Lua Environment",
98-
"type": "lua-local",
99-
"request": "launch",
100-
"program": {
101-
"command": "command"
10291
},
10392
"args": []
10493
}
@@ -172,40 +161,25 @@
172161
{
173162
"type": "object",
174163
"properties": {
175-
"lua": {
164+
"tarantool": {
176165
"type": "string",
177-
"description": "Lua stand-alone interpreter to use",
178-
"default": "lua"
166+
"description": "Tarantool Lua stand-alone interpreter to use",
167+
"default": "tarantool"
179168
},
180169
"file": {
181170
"type": "string",
182171
"description": "The entry point file of the program",
183172
"default": "${file}"
184173
},
185174
"communication": {
186-
"enum": ["stdio", "pipe"],
187-
"description": "Communication method between extension and debugger.",
188-
"default": "stdio"
189-
}
190-
},
191-
"additionalProperties": false
192-
},
193-
{
194-
"type": "object",
195-
"properties": {
196-
"command": {
197-
"type": "string",
198-
"description": "The custom command to run"
199-
},
200-
"communication": {
201-
"enum": ["stdio", "pipe"],
175+
"enum": [
176+
"stdio",
177+
"pipe"
178+
],
202179
"description": "Communication method between extension and debugger.",
203180
"default": "stdio"
204181
}
205182
},
206-
"required": [
207-
"command"
208-
],
209183
"additionalProperties": false
210184
}
211185
]

resources/Lua-Logo_128x128.png

-9.12 KB
Binary file not shown.

resources/settings.png

-13 KB
Binary file not shown.

0 commit comments

Comments
 (0)