diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 29406b31..0065d0e7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,17 +8,11 @@ // A task runner that calls a custom npm script that compiles the extension. { - "version": "0.1.0", + "version": "2.0.0", // we want to run npm "command": "npm", - // the command is a shell script - "isShellCommand": true, - - // show the output window only if unrecognized errors occur. - "showOutput": "silent", - // we run the custom script "compile" as defined in package.json "args": ["run", "compile", "--loglevel", "silent"], @@ -26,5 +20,24 @@ "isWatching": true, // use the standard tsc in watch mode problem matcher to find compile problems in the output. - "problemMatcher": "$tsc-watch" + "problemMatcher": "$tsc-watch", + "tasks": [ + { + "label": "npm", + "type": "shell", + "command": "npm", + "args": [ + "run", + "compile", + "--loglevel", + "silent" + ], + "isBackground": true, + "problemMatcher": "$tsc-watch", + "group": { + "_id": "build", + "isDefault": false + } + } + ] } diff --git a/package-lock.json b/package-lock.json index 7fd49770..34f47957 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "devDependencies": { "@semantic-release/changelog": "^6.0.0", "@semantic-release/git": "^10.0.0", - "@types/node": "^6.14.13", + "@types/node": "^14.16.0", "@types/vscode": "^1.52.0", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", @@ -1873,9 +1873,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "6.14.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-6.14.13.tgz", - "integrity": "sha512-J1F0XJ/9zxlZel5ZlbeSuHW2OpabrUAqpFuC2sm2I3by8sERQ8+KCjNKUcq8QHuzpGMWiJpo9ZxeHrqrP2KzQw==", + "version": "14.18.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.12.tgz", + "integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==", "dev": true }, "node_modules/@types/normalize-package-data": { @@ -17941,9 +17941,9 @@ "dev": true }, "@types/node": { - "version": "6.14.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-6.14.13.tgz", - "integrity": "sha512-J1F0XJ/9zxlZel5ZlbeSuHW2OpabrUAqpFuC2sm2I3by8sERQ8+KCjNKUcq8QHuzpGMWiJpo9ZxeHrqrP2KzQw==", + "version": "14.18.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.18.12.tgz", + "integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==", "dev": true }, "@types/normalize-package-data": { diff --git a/package.json b/package.json index 2078bec6..6f0f445d 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "devDependencies": { "@semantic-release/changelog": "^6.0.0", "@semantic-release/git": "^10.0.0", - "@types/node": "^6.14.13", + "@types/node": "^14.16.0", "@types/vscode": "^1.52.0", "@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/parser": "^4.33.0", diff --git a/src/extension.ts b/src/extension.ts index 20c0d95a..ad2019b1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -65,12 +65,6 @@ function createLaunchConfigFromContext( folder: vscode.WorkspaceFolder | undefined, resolve: boolean ): vscode.DebugConfiguration { - const config = { - type: 'lrdb', - request: 'launch', - name: localize('lrdb.launch.config.name', 'Launch Lua program'), - } - let program: string | undefined // try to use file open in editor @@ -94,8 +88,18 @@ function createLaunchConfigFromContext( } if (program) { - config['program'] = program + return { + type: 'lrdb', + request: 'launch', + name: localize('lrdb.launch.config.name', 'Launch Lua program'), + program + } + } + + return { + type: 'lrdb', + request: 'launch', + name: localize('lrdb.launch.config.name', 'Launch Lua program'), } - return config } diff --git a/src/lrdbDebug.ts b/src/lrdbDebug.ts index ce22daf1..1757f533 100644 --- a/src/lrdbDebug.ts +++ b/src/lrdbDebug.ts @@ -77,9 +77,9 @@ export class LuaDebugSession extends DebugSession { // Lua private static THREAD_ID = 1 - private _debug_server_process: ChildProcess + private _debug_server_process: ChildProcess | undefined = undefined - private _debug_client: LRDBClient.Client + private _debug_client: LRDBClient.Client | undefined = undefined // maps from sourceFile to array of Breakpoints private _breakPoints = new Map() @@ -90,7 +90,7 @@ export class LuaDebugSession extends DebugSession { private _sourceHandles = new Handles() - private _stopOnEntry: boolean + private _stopOnEntry: boolean| undefined = undefined /** * Creates a new debug adapter that is used for one debug session. @@ -120,15 +120,17 @@ export class LuaDebugSession extends DebugSession { this._debug_client.end() delete this._debug_client } - // This debug adapter implements the configurationDoneRequest. - response.body.supportsConfigurationDoneRequest = true - - response.body.supportsConditionalBreakpoints = true - - response.body.supportsHitConditionalBreakpoints = true - - // make VS Code to use 'evaluate' when hovering over source - response.body.supportsEvaluateForHovers = true + if (response.body) { + // This debug adapter implements the configurationDoneRequest. + response.body.supportsConfigurationDoneRequest = true + + response.body.supportsConditionalBreakpoints = true + + response.body.supportsHitConditionalBreakpoints = true + + // make VS Code to use 'evaluate' when hovering over source + response.body.supportsEvaluateForHovers = true + } this.sendResponse(response) } @@ -223,10 +225,10 @@ export class LuaDebugSession extends DebugSession { this.sendEvent(new InitializedEvent()) }) - this._debug_server_process.stdout.on('data', (data) => { + this._debug_server_process.stdout?.on('data', (data) => { this.sendEvent(new OutputEvent(data.toString(), 'stdout')) }) - this._debug_server_process.stderr.on('data', (data) => { + this._debug_server_process.stderr?.on('data', (data) => { this.sendEvent(new OutputEvent(data.toString(), 'stderr')) }) this._debug_server_process.on('error', (msg: string) => { @@ -281,6 +283,11 @@ export class LuaDebugSession extends DebugSession { args: DebugProtocol.SetBreakpointsArguments ): void { const path = args.source.path + if (!path) { + this.sendResponse(response) + console.error('can not found source path') + return + } // read file contents into array for direct access const lines = readFileSync(path).toString().split('\n') @@ -289,9 +296,9 @@ export class LuaDebugSession extends DebugSession { const debuggerFilePath = this.convertClientPathToDebugger(path) - this._debug_client.clearBreakPoints({ file: debuggerFilePath }) + this._debug_client?.clearBreakPoints({ file: debuggerFilePath }) // verify breakpoint locations - for (const souceBreakpoint of args.breakpoints) { + for (const souceBreakpoint of args.breakpoints ?? []) { let l = this.convertClientLineToDebugger(souceBreakpoint.line) let verified = false while (l <= lines.length) { @@ -309,18 +316,12 @@ export class LuaDebugSession extends DebugSession { ) bp.id = this._breakPointID++ breakpoints.push(bp) - if (verified) { + if (verified && this._debug_client) { const sendbreakpoint = { line: l, file: debuggerFilePath, - condition: undefined, - hit_condition: undefined, - } - if (souceBreakpoint.condition) { - sendbreakpoint.condition = souceBreakpoint.condition - } - if (souceBreakpoint.hitCondition) { - sendbreakpoint.hit_condition = souceBreakpoint.hitCondition + hit_condition: souceBreakpoint.hitCondition ? souceBreakpoint.hitCondition : undefined, + condition: souceBreakpoint.condition ? souceBreakpoint.condition : undefined } this._debug_client.addBreakPoint(sendbreakpoint) } @@ -349,7 +350,7 @@ export class LuaDebugSession extends DebugSession { response: DebugProtocol.StackTraceResponse, args: DebugProtocol.StackTraceArguments ): void { - this._debug_client.getStackTrace().then((res) => { + this._debug_client?.getStackTrace().then((res) => { if (res.result) { const startFrame = typeof args.startFrame === 'number' ? args.startFrame : 0 @@ -435,7 +436,7 @@ export class LuaDebugSession extends DebugSession { ): void { const parent = this._variableHandles.get(args.variablesReference) - if (parent != null) { + if (parent != null && this._debug_client) { const res = (() => { switch (parent.type) { case 'get_global': @@ -453,6 +454,7 @@ export class LuaDebugSession extends DebugSession { case 'eval': return this._debug_client .eval(parent.params) + // @ts-expect-error need fix type .then((res) => res.result[0]) default: return Promise.reject(Error('invalid')) @@ -519,14 +521,14 @@ export class LuaDebugSession extends DebugSession { variablesReference: varRef, }) }) - } else if (typeof variablesData === 'object') { - for (const k in variablesData) { - const typename = typeof variablesData[k] + } else if (typeof variablesData === 'object' && variablesData != null) { + for (const [k, value] of Object.entries(variablesData)) { + const typename = typeof value const varRef = (typename == 'object') ? this._variableHandles.create(evalParam(k)) : 0 variables.push({ name: k, type: typename, - value: stringify(variablesData[k]), + value: stringify(value), variablesReference: varRef, }) } @@ -541,7 +543,7 @@ export class LuaDebugSession extends DebugSession { response: DebugProtocol.ContinueResponse, // args: DebugProtocol.ContinueArguments ): void { - this._debug_client.continue() + this._debug_client?.continue() this.sendResponse(response) } @@ -549,7 +551,7 @@ export class LuaDebugSession extends DebugSession { response: DebugProtocol.NextResponse, // args: DebugProtocol.NextArguments ): void { - this._debug_client.step() + this._debug_client?.step() this.sendResponse(response) } @@ -557,7 +559,7 @@ export class LuaDebugSession extends DebugSession { response: DebugProtocol.StepInResponse, // args: DebugProtocol.StepInArguments ): void { - this._debug_client.stepIn() + this._debug_client?.stepIn() this.sendResponse(response) } @@ -565,14 +567,14 @@ export class LuaDebugSession extends DebugSession { response: DebugProtocol.StepOutResponse, // args: DebugProtocol.StepOutArguments ): void { - this._debug_client.stepOut() + this._debug_client?.stepOut() this.sendResponse(response) } protected pauseRequest( response: DebugProtocol.PauseResponse, // args: DebugProtocol.PauseArguments ): void { - this._debug_client.pause() + this._debug_client?.pause() this.sendResponse(response) } @@ -608,7 +610,7 @@ export class LuaDebugSession extends DebugSession { response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments ): void { - if (!this._debug_client) { + if (!this._debug_client || args.frameId == null) { response.success = false this.sendResponse(response) return @@ -648,7 +650,7 @@ export class LuaDebugSession extends DebugSession { private handleServerEvents(event: LRDBClient.DebuggerNotify) { if (event.method == 'paused') { if (event.params.reason === 'entry' && !this._stopOnEntry) { - this._debug_client.continue() + this._debug_client?.continue() } else { this.sendEvent( new StoppedEvent(event.params.reason, LuaDebugSession.THREAD_ID) diff --git a/test/debugadapter.test.ts b/test/debugadapter.test.ts index e07a39de..916a5128 100644 --- a/test/debugadapter.test.ts +++ b/test/debugadapter.test.ts @@ -70,7 +70,7 @@ describe('Lua Debug Adapter', () => { describe('initialize', () => { test('should return supported features', async () => { const response = await dc.initializeRequest() - expect(response.body.supportsConfigurationDoneRequest).toBe(true) + expect(response.body?.supportsConfigurationDoneRequest).toBe(true) }) test("should produce error for invalid 'pathFormat'", async () => { @@ -221,7 +221,7 @@ describe('Lua Debug Adapter', () => { .then((res) => res.body.scopes.find((scope) => scope.name === 'Upvalues') ) - .then((ref) => dc.variablesRequest(ref)) + .then((ref) => dc.variablesRequest(ref!)) .then((res) => expect(res.body.variables[0]).toMatchSnapshot()) }) test('check upvalue a', async () => { @@ -277,7 +277,7 @@ describe('Lua Debug Adapter', () => { return dc .scopesRequest({ frameId: 0 }) .then((res) => res.body.scopes.find((scope) => scope.name === 'Global')) - .then((ref) => dc.variablesRequest(ref)) + .then((ref) => dc.variablesRequest(ref!)) .then(((value) => expect(value.body.variables).toContainEqual({ name: '_VERSION', @@ -313,7 +313,7 @@ describe('Lua Debug Adapter', () => { return dc .scopesRequest({ frameId: 0 }) .then((res) => res.body.scopes.find((scope) => scope.name === 'Local')) - .then((ref) => dc.variablesRequest(ref)) + .then((ref) => dc.variablesRequest(ref!)) .then((res) => expect(res).toMatchSnapshot()) }) test('get local_value1', async () => { diff --git a/tsconfig.json b/tsconfig.json index 31cbdc05..789fe298 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "outDir": "out", "lib": ["es6"], "sourceMap": true, - "rootDir": "./src" + "rootDir": "./src", + "strict": true }, "exclude": ["node_modules", ".vscode-test"], "include": ["src"]