Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger improvements #195

Merged
merged 15 commits into from
Jan 16, 2025
Merged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- DO NOT REMOVE - contributor_list:data:start:["ivojawer", "fdodino", "PalumboN", "npasserini", "Miranda-03", "dependabot[bot]", "FerRomMu"]:end -->
<!-- DO NOT REMOVE - contributor_list:data:start:["ivojawer", "fdodino", "PalumboN", "npasserini", "dependabot[bot]", "Miranda-03", "FerRomMu"]:end -->


# Wollok IDE
Expand Down Expand Up @@ -40,6 +40,6 @@ Do you want to contribute? Great, you are always welcome!
<!-- DO NOT REMOVE - contributor_list:start -->
## 👥 Contributors

<img src="https://avatars.githubusercontent.com/u/18614957?v=4" height="40" width="40" alt="ivojawer" title="ivojawer" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4549002?v=4" height="40" width="40" alt="fdodino" title="fdodino" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4098184?v=4" height="40" width="40" alt="PalumboN" title="PalumboN" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4633913?v=4" height="40" width="40" alt="npasserini" title="npasserini" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/72475370?v=4" height="40" width="40" alt="Miranda-03" title="Miranda-03" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/in/29110?v=4" height="40" width="40" alt="dependabot[bot]" title="dependabot[bot]" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/70177008?v=4" height="40" width="40" alt="FerRomMu" title="FerRomMu" class="avatar circle"/>&nbsp;
<img src="https://avatars.githubusercontent.com/u/18614957?v=4" height="40" width="40" alt="ivojawer" title="ivojawer" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4549002?v=4" height="40" width="40" alt="fdodino" title="fdodino" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4098184?v=4" height="40" width="40" alt="PalumboN" title="PalumboN" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4633913?v=4" height="40" width="40" alt="npasserini" title="npasserini" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/in/29110?v=4" height="40" width="40" alt="dependabot[bot]" title="dependabot[bot]" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/72475370?v=4" height="40" width="40" alt="Miranda-03" title="Miranda-03" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/70177008?v=4" height="40" width="40" alt="FerRomMu" title="FerRomMu" class="avatar circle"/>&nbsp;
<!-- DO NOT REMOVE - contributor_list:end -->
<!-- prettier-ignore-end -->
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 @@
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 @@
context.subscriptions.push(
registerCLICommand(COMMAND_INIT_PROJECT, initProject),
)
context.subscriptions.push(registerDebuggerCommand())
}

/**
Expand Down Expand Up @@ -141,3 +142,20 @@
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,
},
}
)

Check warning on line 159 in packages/client/src/commands.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/commands.ts#L147-L159

Added lines #L147 - L159 were not covered by tests
})
}
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)

Check warning on line 14 in packages/debug-adapter/src/debug-configuration-provider.ts

View check run for this annotation

Codecov / codecov/patch

packages/debug-adapter/src/debug-configuration-provider.ts#L13-L14

Added lines #L13 - L14 were not covered by tests
}

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)

Check warning on line 18 in packages/debug-adapter/src/debug-configuration-provider.ts

View check run for this annotation

Codecov / codecov/patch

packages/debug-adapter/src/debug-configuration-provider.ts#L17-L18

Added lines #L17 - L18 were not covered by tests
}

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)

Check warning on line 23 in packages/debug-adapter/src/debug-configuration-provider.ts

View check run for this annotation

Codecov / codecov/patch

packages/debug-adapter/src/debug-configuration-provider.ts#L21-L23

Added lines #L21 - L23 were not covered by tests
}

return config
Expand Down
Loading
Loading