Skip to content

Commit df2d03c

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

File tree

11 files changed

+79
-156
lines changed

11 files changed

+79
-156
lines changed

.github/workflows/bundle.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: [master]
66
tags: ['*']
7+
pull_request:
78
workflow_dispatch:
89

910
jobs:
@@ -28,5 +29,5 @@ jobs:
2829

2930
- uses: actions/upload-artifact@v3
3031
with:
31-
name: tarantool-local-lua-debugger-vscode
32-
path: tarantool-local-lua-debugger-vscode-*.vsix
32+
name: tarantool-lua-debugger-vscode
33+
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).

debugger/debugger.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ import {Thread, mainThread, mainThreadName, isThread} from "./thread";
3838

3939
import * as tarantool from "tarantool";
4040

41-
const luaTarantoolGetSources =
42-
tarantool.debug.getsources ??
43-
function (filePath: string): null {
41+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
42+
const luaTarantoolGetSources = tarantool.debug.getsources ?? function(filePath: string) {
4443
return null;
45-
};
44+
};
4645

4746
export interface Var {
4847
val: unknown;

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.tarantool" `
65+
+ "in your launch.json, to debug with a tarantool 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.

0 commit comments

Comments
 (0)