Skip to content

Commit

Permalink
reafactor: added strict to tsconfig (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
satoren authored Feb 20, 2022
1 parent e0d0fc5 commit f2e3837
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 67 deletions.
29 changes: 21 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@

// 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"],

// The tsc compiler is started in watching mode
"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
}
}
]
}
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 12 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
78 changes: 40 additions & 38 deletions src/lrdbDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, DebugProtocol.Breakpoint[]>()
Expand All @@ -90,7 +90,7 @@ export class LuaDebugSession extends DebugSession {

private _sourceHandles = new Handles<string>()

private _stopOnEntry: boolean
private _stopOnEntry: boolean| undefined = undefined

/**
* Creates a new debug adapter that is used for one debug session.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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')
Expand All @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand All @@ -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'))
Expand Down Expand Up @@ -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,
})
}
Expand All @@ -541,38 +543,38 @@ export class LuaDebugSession extends DebugSession {
response: DebugProtocol.ContinueResponse,
// args: DebugProtocol.ContinueArguments
): void {
this._debug_client.continue()
this._debug_client?.continue()
this.sendResponse(response)
}

protected nextRequest(
response: DebugProtocol.NextResponse,
// args: DebugProtocol.NextArguments
): void {
this._debug_client.step()
this._debug_client?.step()
this.sendResponse(response)
}

protected stepInRequest(
response: DebugProtocol.StepInResponse,
// args: DebugProtocol.StepInArguments
): void {
this._debug_client.stepIn()
this._debug_client?.stepIn()
this.sendResponse(response)
}

protected stepOutRequest(
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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions test/debugadapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 () => {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"outDir": "out",
"lib": ["es6"],
"sourceMap": true,
"rootDir": "./src"
"rootDir": "./src",
"strict": true
},
"exclude": ["node_modules", ".vscode-test"],
"include": ["src"]
Expand Down

0 comments on commit f2e3837

Please sign in to comment.