Skip to content

Commit

Permalink
add mock2
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed May 17, 2024
1 parent f9f23d6 commit 2a2c5de
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 22 deletions.
109 changes: 109 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"browser": "./dist/web-extension.js",
"activationEvents": [
"onDebugResolve:mock",
"onDebugResolve:mock2",
"onDebugDynamicConfigurations:mock",
"onCommand:extension.mock-debug.getProgramName"
],
Expand Down Expand Up @@ -237,6 +238,114 @@
"variables": {
"AskForProgramName": "extension.mock-debug.getProgramName"
}
},
{
"type": "mock2",
"languages": [
"markdown"
],
"label": "Mock Debug",
"program": "./out/debugAdapter.js",
"runtime": "node",
"configurationAttributes": {
"launch": {
"required": [
"program"
],
"properties": {
"program": {
"type": "string",
"description": "Absolute path to a text file.",
"default": "${workspaceFolder}/${command:AskForProgramName}"
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after launch.",
"default": true
},
"trace": {
"type": "boolean",
"description": "Enable logging of the Debug Adapter Protocol.",
"default": true
},
"compileError": {
"type": "string",
"description": "Simulates a compile error in 'launch' request.",
"enum": [
"default",
"show",
"hide"
],
"enumDescriptions": [
"default: show fake compile error to user",
"show fake compile error to user",
"do not show fake compile error to user"
]
}
}
},
"attach": {
"required": [
"program"
],
"properties": {
"program": {
"type": "string",
"description": "Absolute path to a text file.",
"default": "${workspaceFolder}/${command:AskForProgramName}"
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after attach.",
"default": true
},
"trace": {
"type": "boolean",
"description": "Enable logging of the Debug Adapter Protocol.",
"default": true
},
"compileError": {
"type": "string",
"description": "Simulates a compile error in 'attach' request.",
"enum": [
"default",
"show",
"hide"
],
"enumDescriptions": [
"default: show fake compile error to user",
"show fake compile error to user",
"do not show fake compile error to user"
]
}
}
}
},
"initialConfigurations": [
{
"type": "mock",
"request": "launch",
"name": "Ask for file name",
"program": "${workspaceFolder}/${command:AskForProgramName}",
"stopOnEntry": true
}
],
"configurationSnippets": [
{
"label": "Mock Debug: Launch",
"description": "A new configuration for 'debugging' a user selected markdown file.",
"body": {
"type": "mock",
"request": "launch",
"name": "Ask for file name",
"program": "^\"\\${workspaceFolder}/\\${command:AskForProgramName}\"",
"stopOnEntry": true
}
}
],
"variables": {
"AskForProgramName": "extension.mock-debug.getProgramName"
}
}
]
}
Expand Down
6 changes: 3 additions & 3 deletions sampleWorkspace/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"version": "0.2.0",
"configurations": [
{
"type": "mock",
"type": "mock2",
"request": "launch",
"name": "Debug readme.md",
"program": "${workspaceFolder}/readme.md",
// "program": "${workspaceFolder}/readme.md",
"stopOnEntry": true,
"trace": false
// "trace": false
},
{
"type": "mock",
Expand Down
41 changes: 22 additions & 19 deletions src/activateMockDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export function activateMockDebug(context: vscode.ExtensionContext, factory?: vs

// register a configuration provider for 'mock' debug type
const provider = new MockConfigurationProvider();
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('mock', provider));
// context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('mock', provider));
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('mock2', provider));

// register a dynamic configuration provider for 'mock' debug type
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('mock', {
Expand Down Expand Up @@ -159,24 +160,26 @@ class MockConfigurationProvider implements vscode.DebugConfigurationProvider {
* e.g. add all missing attributes to the debug configuration.
*/
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, config: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {

// if launch.json is missing or empty
if (!config.type && !config.request && !config.name) {
const editor = vscode.window.activeTextEditor;
if (editor && editor.document.languageId === 'markdown') {
config.type = 'mock';
config.name = 'Launch';
config.request = 'launch';
config.program = '${file}';
config.stopOnEntry = true;
}
}

if (!config.program) {
return vscode.window.showInformationMessage("Cannot find a program to debug").then(_ => {
return undefined; // abort launch
});
}
config.type = 'mock';
config.program = '${file}';

// // if launch.json is missing or empty
// if (!config.type && !config.request && !config.name) {
// const editor = vscode.window.activeTextEditor;
// if (editor && editor.document.languageId === 'markdown') {
// config.type = 'mock';
// config.name = 'Launch';
// config.request = 'launch';
// config.program = '${file}';
// config.stopOnEntry = true;
// }
// }

// if (!config.program) {
// return vscode.window.showInformationMessage("Cannot find a program to debug").then(_ => {
// return undefined; // abort launch
// });
// }

return config;
}
Expand Down

0 comments on commit 2a2c5de

Please sign in to comment.