Skip to content

Commit

Permalink
src/goDebugConfiguration.ts: add substitutePath to go.delveConfig
Browse files Browse the repository at this point in the history
Allow users to configure substitutePath from settings.json so that
the setting can be applied to codelenses.

Updates golang#1467

Change-Id: I504d91e60f5b1a8c79369ad933b79247caa371ac
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/318589
Trust: Suzy Mueller <[email protected]>
Run-TryBot: Suzy Mueller <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
suzmue committed May 12, 2021
1 parent d9fd8f0 commit 4bae281
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ You may not need to configure any settings to start debugging your programs, but
* `maxStructFields`: Maximum number of fields read from a struct. A setting of `-1` indicates that all fields should be read (default: `-1`).
* `maxVariableRecurse`: How far to recurse when evaluating nested types (default: `1`).
* `followPointers`: Automatically dereference pointers (default: `true`).
* `showGlobalVariables`: Show global variables in the Debug view (default: `false`).
* `debugAdapter`: Controls which debug adapter to use (default: `legacy`).
* `substitutePath`: Path mappings to apply to get from a path in the editor to a path in the compiled program (default: `[]`).

There are some common cases when you might want to tweak the Delve configurations.

Expand Down
2 changes: 2 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Delve settings that applies to all debugging sessions. Debug configuration in th
| `debugAdapter` | Select which debug adapter to use by default. This is also used for choosing which debug adapter to use when no launch.json is present and with codelenses. <br/> Allowed Options: `legacy`, `dlv-dap` <br/> Default: `"legacy"` |
| `dlvLoadConfig` | LoadConfig describes to delve, how to load values from target's memory. Ignored by 'dlv-dap'. <br/> Default: ``` { <pre>"followPointers" : true,<br/>"maxArrayValues" : 64,<br/>"maxStringLen" : 64,<br/>"maxStructFields" : -1,<br/>"maxVariableRecurse" : 1,</pre>} ``` |
| `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not. <br/> Default: `false` |
| `substitutePath` | An array of mappings from a local path to the remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls. Overriden by remotePath. |

Default:
```
Expand All @@ -160,6 +161,7 @@ Default:
"maxVariableRecurse" : 1,
},
"showGlobalVariables" : false,
"substitutePath" : [],
}
```
### `go.disableConcurrentTests`
Expand Down
23 changes: 22 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,26 @@
],
"description": "Select which debug adapter to use by default. This is also used for choosing which debug adapter to use when no launch.json is present and with codelenses.",
"default": "legacy"
},
"substitutePath": {
"type": "array",
"items": {
"type": "object",
"properties": {
"from": {
"type": "string",
"description": "The absolute local path to be replaced when passing paths to the debugger",
"default": ""
},
"to": {
"type": "string",
"description": "The absolute remote path to be replaced when passing paths back to the client",
"default": ""
}
}
},
"description": "An array of mappings from a local path to the remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls. Overriden by remotePath.",
"default": []
}
},
"default": {
Expand All @@ -1749,7 +1769,8 @@
},
"apiVersion": 2,
"showGlobalVariables": false,
"debugAdapter": "legacy"
"debugAdapter": "legacy",
"substitutePath": []
},
"description": "Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.",
"scope": "resource"
Expand Down
3 changes: 3 additions & 0 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
) {
debugConfiguration['showGlobalVariables'] = dlvConfig['showGlobalVariables'];
}
if (!debugConfiguration.hasOwnProperty('substitutePath') && dlvConfig.hasOwnProperty('substitutePath')) {
debugConfiguration['substitutePath'] = dlvConfig['substitutePath'];
}
if (debugConfiguration.request === 'attach' && !debugConfiguration['cwd']) {
debugConfiguration['cwd'] = '${workspaceFolder}';
}
Expand Down
22 changes: 18 additions & 4 deletions test/integration/goDebugConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ suite('Debug Configuration Merge User Settings', () => {
assert.strictEqual(filledResult.dlvToolPath, emptyResult.dlvToolPath);
assert.strictEqual(filledResult.apiVersion, emptyResult.apiVersion);
assert.strictEqual(filledResult.showGlobalVariables, emptyResult.showGlobalVariables);
assert.strictEqual(filledResult.debugAdapter, emptyResult.debugAdapter);
assert.strictEqual(filledResult.substitutePath, emptyResult.substitutePath);
});

test('delve config in settings.json is added to debug config', async () => {
Expand All @@ -219,7 +221,9 @@ suite('Debug Configuration Merge User Settings', () => {
maxStructFields: 5
},
apiVersion: 1,
showGlobalVariables: true
showGlobalVariables: true,
debugAdapter: 'dlv-dap',
substitutePath: [{ from: 'hello', to: 'goodbye' }]
}
}
}) as vscode.WorkspaceConfiguration;
Expand All @@ -236,6 +240,10 @@ suite('Debug Configuration Merge User Settings', () => {
const result = await debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
assert.strictEqual(result.apiVersion, 1);
assert.strictEqual(result.showGlobalVariables, true);
assert.strictEqual(result.debugAdapter, 'dlv-dap');
assert.strictEqual(result.substitutePath.length, 1);
assert.strictEqual(result.substitutePath[0].from, 'hello');
assert.strictEqual(result.substitutePath[0].to, 'goodbye');
const dlvLoadConfig = result.dlvLoadConfig;
assert.strictEqual(dlvLoadConfig.followPointers, false);
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 3);
Expand All @@ -261,13 +269,15 @@ suite('Debug Configuration Merge User Settings', () => {
maxStructFields: 5
},
apiVersion: 1,
showGlobalVariables: true
showGlobalVariables: true,
debugAdapter: 'dlv-dap',
substitutePath: [{ from: 'hello', to: 'goodbye' }]
}
}
}) as vscode.WorkspaceConfiguration;
sinon.stub(config, 'getGoConfig').returns(goConfig);

const cfg = {
const cfg: vscode.DebugConfiguration = {
name: 'Launch',
type: 'go',
request: 'launch',
Expand All @@ -281,12 +291,16 @@ suite('Debug Configuration Merge User Settings', () => {
maxStringLen: 128,
maxArrayValues: 128,
maxStructFields: -1
}
},
debugAdapter: 'legacy',
substitutePath: []
};

const result = await debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
assert.strictEqual(result.apiVersion, 2);
assert.strictEqual(result.showGlobalVariables, false);
assert.strictEqual(result.debugAdapter, 'legacy');
assert.strictEqual(result.substitutePath.length, 0);
const dlvLoadConfig = result.dlvLoadConfig;
assert.strictEqual(dlvLoadConfig.followPointers, true);
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 6);
Expand Down

0 comments on commit 4bae281

Please sign in to comment.