Skip to content

Commit

Permalink
Merge pull request #195 from uqbar-project/debugger-improvements
Browse files Browse the repository at this point in the history
Debugger improvements
  • Loading branch information
PalumboN authored Jan 16, 2025
2 parents f868711 + 025145b commit 1d19045
Show file tree
Hide file tree
Showing 17 changed files with 588 additions and 134 deletions.
31 changes: 23 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,53 @@
"languages": [
"wollok"
],
"program": "./out/debug-adapter/src/index.js",
"runtime": "node",
"configurationAttributes": {
"launch": {
"required": [
"file",
"target"
],
"properties": {
"target": {
"type": "object",
"description": "Program or test to run.",
"properties": {
"type": {
"type": "string",
"description": "The type of targetting.",
"enum": [
"program",
"test",
"fqn"
],
"enumDescriptions": [
"Target a program, should specify program and file",
"Target a test, should specify test, describe and file",
"Target a fully qualified name, should specify fqn"
]
},
"program": {
"type": "string",
"description": "The program's name."
},
"describe": {
"type": "string",
"description": "(optional) The describe's name.",
"optional": true
"description": "(optional) The describe's name."
},
"test": {
"type": "string",
"description": "The test's name."
},
"fqn": {
"type": "string",
"description": "The fully qualified name of the describe/test/program you want to run."
},
"file": {
"type": "string",
"description": "Absolute path to a Wollok file."
}
}
},
"file": {
"type": "string",
"description": "Absolute path to a Wollok file."
},
"stopOnEntry": {
"type": "boolean",
"description": "Stop on the first line of the program/test.",
Expand Down
20 changes: 19 additions & 1 deletion packages/client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
asShellString,
fsToShell,
} from './platform-string-utils'
import { COMMAND_RUN_ALL_TESTS, COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL, wollokLSPExtensionCode, COMMAND_INIT_PROJECT } from './shared-definitions'
import { COMMAND_RUN_ALL_TESTS, COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL, wollokLSPExtensionCode, COMMAND_INIT_PROJECT, COMMAND_DEBUG } from './shared-definitions'
import { getLSPMessage } from './messages'

export const subscribeWollokCommands = (context: ExtensionContext): void => {
Expand All @@ -32,6 +32,7 @@ export const subscribeWollokCommands = (context: ExtensionContext): void => {
context.subscriptions.push(
registerCLICommand(COMMAND_INIT_PROJECT, initProject),
)
context.subscriptions.push(registerDebuggerCommand())
}

/**
Expand Down Expand Up @@ -143,3 +144,20 @@ const wollokCLITask = (task: string, name: string, cliCommands: Array<string | v
new ShellExecution(fsToShell(wollokCliPath), shellCommandArgs),
)
}
function registerDebuggerCommand(): { dispose(): any } {
return commands.registerCommand(COMMAND_DEBUG, async (fqn: string) => {
vscode.debug.startDebugging(
vscode.workspace.workspaceFolders[0],
{
type: "wollok",
request: "launch",
name: "Launch Debug Session",
stopOnEntry: false,
target: {
type: 'fqn',
fqn,
},
}
)
})
}
4 changes: 3 additions & 1 deletion packages/client/src/shared-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export const COMMAND_RUN_GAME = 'wollok.run.game'
export const COMMAND_RUN_PROGRAM = 'wollok.run.program'
export const COMMAND_RUN_ALL_TESTS = 'wollok.run.allTests'
export const COMMAND_RUN_TEST = 'wollok.run.test'
export const COMMAND_INIT_PROJECT = 'wollok.init.project'
export const COMMAND_INIT_PROJECT = 'wollok.init.project'
//ToDo: Create shared package
export const COMMAND_DEBUG = 'wollok.debug'
16 changes: 16 additions & 0 deletions packages/client/src/test/code-lens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ suite('Should do code lenses', () => {
arguments: ['pepitaGame.juego'],
},
),
new CodeLens(
new Range(new Position(0, 0), new Position(2, 1)),
{
title: 'Debug program',
command: 'wollok.debug',
arguments: ['pepitaGame.juego'],
}
),
])
})

Expand Down Expand Up @@ -52,6 +60,14 @@ suite('Should do code lenses', () => {
arguments: [null, 'test.wtest', 'pepita test', 'pepita is happy'],
},
),
new CodeLens(
new Range(new Position(1, 4), new Position(3, 5)),
{
title: 'Debug test',
command: 'wollok.debug',
arguments: ['test."pepita test"."pepita is happy"'],
}
),
])
})

Expand Down
5 changes: 3 additions & 2 deletions packages/debug-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
"@vscode/debugprotocol": "^1.66.0"
},
"devDependencies": {
"@types/chai": "^4",
"@types/mocha": "^10",
"@types/node": "^18.14.1",
"@types/vscode": "^1.92.0",
"@vscode/debugadapter-testsupport": "^1.67.0",
"chai": "4.3.10",
"mocha": "^10.7.3",
"nyc": "^17.0.0",
"ts-mocha": "^10.0.0",
"wollok-ts": "4.2.0"
"ts-mocha": "^10.0.0"
}
}
25 changes: 13 additions & 12 deletions packages/debug-adapter/src/debug-configuration-provider.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, ProviderResult, WorkspaceFolder } from 'vscode'
import * as vscode from 'vscode'

const targetTypeRequiredKeys = {
'fqn': ['fqn'],
'program': ['file', 'program'],
'test': ['file', 'test'],
}

export class WollokDebugConfigurationProvider implements DebugConfigurationProvider {

resolveDebugConfiguration(_folder: WorkspaceFolder | undefined, config: DebugConfiguration, _token?: CancellationToken): ProviderResult<DebugConfiguration> {
if (!config.file) {
return vscode.window.showErrorMessage("Cannot find a file to debug").then(_ => {
return undefined // abort launch
})
if(!config.target.type) {
return vscode.window.showErrorMessage('No target type provided').then(() => undefined)
}

if(config.target.program && config.target.test){
return vscode.window.showErrorMessage("Cannot specify both program and test properties at the same time").then(_ => {
return undefined // abort launch
})
if(!targetTypeRequiredKeys[config.target.type]) {
return vscode.window.showErrorMessage(`Unknown target type: ${config.target.type}`).then(() => undefined)
}

if(!config.target.program && !config.target.test) {
return vscode.window.showErrorMessage("Must specify either program or test property").then(_ => {
return undefined // abort launch
})
const missingKeys = targetTypeRequiredKeys[config.target.type].filter(key => !config.target[key])
if(missingKeys.length) {
return vscode.window.showErrorMessage(`Missing required target parameters: ${missingKeys.join(', ')}`).then(() => undefined)
}

return config
Expand Down
Loading

0 comments on commit 1d19045

Please sign in to comment.