Skip to content

Commit 4a20a67

Browse files
authored
Add Garbage Collection button to debugToolbar (#10)
- Add 'CustomCommand' constructor - Adds 'cabal' and 'stack' initial configurations - Removes 'hello' configuration - Adds custom command to dap-extension for 'garbageCollect'
1 parent 7075f48 commit 4a20a67

File tree

5 files changed

+62
-50
lines changed

5 files changed

+62
-50
lines changed

dap-extension/package.json

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,51 @@
99
"categories": [
1010
"Debuggers"
1111
],
12-
"activationEvents": [ "onDebug", "onDebugResolve:dap-extension", "onDebug:closures" ],
12+
"activationEvents": [ "onDebug", "onDebugResolve:dap-extension", "onDebug:garbageCollect" ],
1313
"main": "./out/extension.js",
1414
"contributes": {
15-
"views": {
16-
"debug": [
17-
{ "id": "closures"
18-
, "name": "closures"
19-
, "visibility": "visible"
20-
, "initialSize": 30
21-
, "contextualTitle": "Closures for ${workspaceFolder}"
22-
, "type": "tree"
23-
}
15+
"menus": {
16+
"debug/toolBar":
17+
[
18+
{ "when": "inDebugMode",
19+
"command": "dap-extension.garbageCollect",
20+
"group": "debug"
21+
}
2422
]
2523
},
26-
"debuggers": [
24+
"commands" :[
2725
{
28-
"type": "dap-extension",
29-
"languages": [
30-
"Haskell"
31-
],
32-
"program": "${workspaceFolder}/test.fullpak",
33-
"label": "dap-extension",
34-
"configurationAttributes": {
35-
"attach": {
36-
"required": ["program"],
37-
"properties": {
38-
"program": {
39-
"type": "string",
40-
"description": "Absolute path to the program",
41-
"default": "${workspaceFolder}/test.fullpak"
42-
}
43-
}
44-
}
45-
},
46-
"initialConfigurations": [
47-
{
48-
"name": "my project",
49-
"type": "dap-extension",
50-
"request": "attach",
51-
"program": "${workspaceFolder}/test.fullpak"
52-
}
53-
]
26+
"command": "dap-extension.garbageCollect",
27+
"category": "debug",
28+
"title": "Garbage Collect"
29+
}
30+
],
31+
"debuggers": [
32+
{ "type": "dap-extension",
33+
"languages": [
34+
"haskell"
35+
],
36+
"program": "${workspaceFolder}/test.fullpak",
37+
"label": "dap-extension",
38+
"configurationAttributes": {
39+
"attach": {
40+
"required": ["program"],
41+
"properties": {
42+
"program": {
43+
"type": "string",
44+
"description": "Absolute path to the program",
45+
"default": "${workspaceFolder}/test.fullpak"
46+
}
47+
}
48+
}
49+
},
50+
"initialConfigurations": [
51+
{
52+
"type": "Connect to DAP ESTGi",
53+
"request": "attach",
54+
"program": "${workspaceFolder}/test.fullpak"
55+
}
56+
]
5457
}
5558
]
5659
},

dap-extension/src/extension.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@ export function activate(context: vscode.ExtensionContext) {
1616
// vscode.debug.onDidReceiveDebugSessionCustomEvent
1717
// Use the console to output diagnostic information (console.log) and errors (console.error)
1818
// This line of code will only be executed once when your extension is activated
19-
console.log('Congratulations, your extension "external-stg-debugger" is now active!');
2019

2120
// The command has been defined in the package.json file
2221
// Now provide the implementation of the command with registerCommand
2322
// The commandId parameter must match the command field in package.json
24-
let disposable = vscode.commands.registerCommand('external-stg-debugger.helloWorld', () => {
2523
// The code you place here will be executed every time your command is executed
2624
// Display a message box to the user
27-
vscode.window.showInformationMessage('Hello World from external-stg-debugger!');
28-
});
29-
console.log('foo');
25+
context.subscriptions.push(vscode.commands.registerCommand('dap-extension.garbageCollect', () => {
26+
// The code you place here will be executed every time your command is executed
27+
// Display a message box to the user
28+
vscode.debug.activeDebugSession?.customRequest('garbageCollect');
29+
window.showInformationMessage('Running garbage collection...');
30+
}));
3031

3132
runDebugger (context, new MockDebugAdapterServerDescriptorFactory());
32-
33-
context.subscriptions.push(disposable);
3433
}
3534

3635
export function runDebugger (context: vscode.ExtensionContext, factory: MockDebugAdapterServerDescriptorFactory) {
37-
3836
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('dap-extension', factory));
3937
console.log('made it to runDebugger');
4038

dap/exe/Main.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ talk CommandAttach = do
216216
emitEvent :: DebugOutput -> Adaptor ESTG ()
217217
emitEvent cmd = logInfo $ BL8.pack (show cmd)
218218
----------------------------------------------------------------------------
219+
talk (CustomCommand "garbageCollect") = do
220+
logInfo "Running garbage collection..."
221+
sendAndWait (CmdInternal "gc")
222+
sendSuccesfulEmptyResponse
223+
----------------------------------------------------------------------------
219224
talk CommandContinue = do
220225
ESTG {..} <- getDebugSession
221226
sendAndWait CmdContinue

dap/hello/.vscode/launch.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
"type": "dap-extension",
99
"request": "attach",
1010
"program": "${workspaceFolder}/hello-macos.fullpak",
11-
"name": "hello"
11+
"name": "stack"
12+
},
13+
{
14+
"type": "dap-extension",
15+
"request": "attach",
16+
"program": "${workspaceFolder}/hello-macos.fullpak",
17+
"name": "cabal"
1218
}
1319
]
14-
}
20+
}

dap/src/DAP/Types.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ data Command
978978
| CommandReadMemory
979979
| CommandWriteMemory
980980
| CommandDisassemble
981-
| CommandUnknown Text
981+
| CustomCommand Text
982982
deriving stock (Show, Eq, Read, Generic)
983983
----------------------------------------------------------------------------
984984
instance FromJSON Command where
@@ -987,12 +987,12 @@ instance FromJSON Command where
987987
Just cmd ->
988988
pure cmd
989989
Nothing ->
990-
pure (CommandUnknown command)
990+
pure (CustomCommand command)
991991
where
992992
name = show (typeRep (Proxy @Command))
993993
----------------------------------------------------------------------------
994994
instance ToJSON Command where
995-
toJSON (CommandUnknown x) = toJSON x
995+
toJSON (CustomCommand x) = toJSON x
996996
toJSON cmd = genericToJSONWithModifier cmd
997997
----------------------------------------------------------------------------
998998
data ErrorMessage

0 commit comments

Comments
 (0)