Skip to content

Commit 4cb7b81

Browse files
committed
added stepUnmappedLines option and disabled stepping through lua in sourcemapped files by default
1 parent 1c18c3c commit 4cb7b81

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ A list of [Lua patterns](https://www.lua.org/manual/5.4/manual.html#6.4.1) that
113113

114114
Example: `ignorePatterns: ["^/usr"]`
115115

116+
#### `stepUnmappedLines`
117+
118+
Step into Lua when stepping through source-mapped code and no mapping is available for the current line.
119+
116120
#### `breakInCoroutines`
117121

118122
Break into the debugger when errors occur inside coroutines.

debugger/debugger.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ export namespace Debugger {
815815

816816
const debugHookStackOffset = 2;
817817
const breakpointLookup = Breakpoint.getLookup();
818+
const stepUnmappedLinesEnv: LuaDebug.StepUnmappedLinesEnv = "LOCAL_LUA_DEBUGGER_STEP_UNMAPPED_LINES";
819+
const skipUnmappedLines = (os.getenv(stepUnmappedLinesEnv) !== "1");
818820

819821
function debugHook(event: "call" | "return" | "tail return" | "count" | "line", line?: number) {
820822
//Stepping
@@ -849,8 +851,9 @@ export namespace Debugger {
849851
}
850852

851853
//Ignore patterns
854+
let source: string | undefined;
852855
if (ignorePatterns) {
853-
const source = Path.format(topFrameSource.source);
856+
source = Path.format(topFrameSource.source);
854857
for (const pattern of ignorePatterns) {
855858
const [match] = source.match(pattern);
856859
if (match) {
@@ -859,6 +862,16 @@ export namespace Debugger {
859862
}
860863
}
861864

865+
//Ignore un-mapped lines in files with source maps
866+
if (skipUnmappedLines) {
867+
source ||= Path.format(topFrameSource.source);
868+
const sourceMap = SourceMap.get(source);
869+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
870+
if (sourceMap && !sourceMap.mappings[line!]) {
871+
return;
872+
}
873+
}
874+
862875
Send.debugBreak("step", "step", getThreadId(activeThread));
863876
if (debugBreak(activeThread, debugHookStackOffset, line)) {
864877
return;

debugger/protocol.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ declare namespace LuaDebug {
113113

114114
type ScriptRootsEnv = "LOCAL_LUA_DEBUGGER_SCRIPT_ROOTS";
115115
type BreakInCoroutinesEnv = "LOCAL_LUA_DEBUGGER_BREAK_IN_COROUTINES";
116+
type StepUnmappedLinesEnv = "LOCAL_LUA_DEBUGGER_STEP_UNMAPPED_LINES";
116117
type InputFileEnv = "LOCAL_LUA_DEBUGGER_INPUT_FILE";
117118
type OutputFileEnv = "LOCAL_LUA_DEBUGGER_OUTPUT_FILE";
118119
}

extension/launchConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface LaunchConfig {
4242
verbose?: boolean;
4343
stopOnEntry?: boolean;
4444
breakInCoroutines?: boolean;
45+
stepUnmappedLines?: boolean;
4546
scriptFiles?: string[];
4647
ignorePatterns?: string[];
4748
}

extension/luaDebugSession.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const envVariable = "LOCAL_LUA_DEBUGGER_VSCODE";
7272
const filePathEnvVariable = "LOCAL_LUA_DEBUGGER_FILEPATH";
7373
const scriptRootsEnvVariable: LuaDebug.ScriptRootsEnv = "LOCAL_LUA_DEBUGGER_SCRIPT_ROOTS";
7474
const breakInCoroutinesEnv: LuaDebug.BreakInCoroutinesEnv = "LOCAL_LUA_DEBUGGER_BREAK_IN_COROUTINES";
75+
const stepUnmappedLinesEnv: LuaDebug.StepUnmappedLinesEnv = "LOCAL_LUA_DEBUGGER_STEP_UNMAPPED_LINES";
7576
const inputFileEnv: LuaDebug.InputFileEnv = "LOCAL_LUA_DEBUGGER_INPUT_FILE";
7677
const outputFileEnv: LuaDebug.OutputFileEnv = "LOCAL_LUA_DEBUGGER_OUTPUT_FILE";
7778

@@ -232,6 +233,9 @@ export class LuaDebugSession extends LoggingDebugSession {
232233
if (typeof this.config.breakInCoroutines !== "undefined") {
233234
processOptions.env[breakInCoroutinesEnv] = this.config.breakInCoroutines ? "1" : "0";
234235
}
236+
if (typeof this.config.stepUnmappedLines !== "undefined") {
237+
processOptions.env[stepUnmappedLinesEnv] = this.config.stepUnmappedLines ? "1" : "0";
238+
}
235239

236240
//Open pipes
237241
if (this.config.program.communication === "pipe") {

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
},
132132
"description": "Lua patterns specifying scripts to be ignored when stepping"
133133
},
134+
"stepUnmappedLines": {
135+
"type": "boolean",
136+
"description": "Step into lua when stepping through unmapped lines in source-mapped files",
137+
"default": true
138+
},
134139
"verbose": {
135140
"type": "boolean",
136141
"description": "Enable verbose output",

0 commit comments

Comments
 (0)