Skip to content

Commit 4bae281

Browse files
committed
src/goDebugConfiguration.ts: add substitutePath to go.delveConfig
Allow users to configure substitutePath from settings.json so that the setting can be applied to codelenses. Updates #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]>
1 parent d9fd8f0 commit 4bae281

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

docs/debugging.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ You may not need to configure any settings to start debugging your programs, but
6969
* `maxStructFields`: Maximum number of fields read from a struct. A setting of `-1` indicates that all fields should be read (default: `-1`).
7070
* `maxVariableRecurse`: How far to recurse when evaluating nested types (default: `1`).
7171
* `followPointers`: Automatically dereference pointers (default: `true`).
72-
* `showGlobalVariables`: Show global variables in the Debug view (default: `false`).
72+
* `debugAdapter`: Controls which debug adapter to use (default: `legacy`).
73+
* `substitutePath`: Path mappings to apply to get from a path in the editor to a path in the compiled program (default: `[]`).
7374

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

docs/settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Delve settings that applies to all debugging sessions. Debug configuration in th
146146
| `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"` |
147147
| `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>} ``` |
148148
| `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not. <br/> Default: `false` |
149+
| `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. |
149150

150151
Default:
151152
```
@@ -160,6 +161,7 @@ Default:
160161
"maxVariableRecurse" : 1,
161162
},
162163
"showGlobalVariables" : false,
164+
"substitutePath" : [],
163165
}
164166
```
165167
### `go.disableConcurrentTests`

package.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,26 @@
17371737
],
17381738
"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.",
17391739
"default": "legacy"
1740+
},
1741+
"substitutePath": {
1742+
"type": "array",
1743+
"items": {
1744+
"type": "object",
1745+
"properties": {
1746+
"from": {
1747+
"type": "string",
1748+
"description": "The absolute local path to be replaced when passing paths to the debugger",
1749+
"default": ""
1750+
},
1751+
"to": {
1752+
"type": "string",
1753+
"description": "The absolute remote path to be replaced when passing paths back to the client",
1754+
"default": ""
1755+
}
1756+
}
1757+
},
1758+
"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.",
1759+
"default": []
17401760
}
17411761
},
17421762
"default": {
@@ -1749,7 +1769,8 @@
17491769
},
17501770
"apiVersion": 2,
17511771
"showGlobalVariables": false,
1752-
"debugAdapter": "legacy"
1772+
"debugAdapter": "legacy",
1773+
"substitutePath": []
17531774
},
17541775
"description": "Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.",
17551776
"scope": "resource"

src/goDebugConfiguration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
183183
) {
184184
debugConfiguration['showGlobalVariables'] = dlvConfig['showGlobalVariables'];
185185
}
186+
if (!debugConfiguration.hasOwnProperty('substitutePath') && dlvConfig.hasOwnProperty('substitutePath')) {
187+
debugConfiguration['substitutePath'] = dlvConfig['substitutePath'];
188+
}
186189
if (debugConfiguration.request === 'attach' && !debugConfiguration['cwd']) {
187190
debugConfiguration['cwd'] = '${workspaceFolder}';
188191
}

test/integration/goDebugConfiguration.test.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ suite('Debug Configuration Merge User Settings', () => {
200200
assert.strictEqual(filledResult.dlvToolPath, emptyResult.dlvToolPath);
201201
assert.strictEqual(filledResult.apiVersion, emptyResult.apiVersion);
202202
assert.strictEqual(filledResult.showGlobalVariables, emptyResult.showGlobalVariables);
203+
assert.strictEqual(filledResult.debugAdapter, emptyResult.debugAdapter);
204+
assert.strictEqual(filledResult.substitutePath, emptyResult.substitutePath);
203205
});
204206

205207
test('delve config in settings.json is added to debug config', async () => {
@@ -219,7 +221,9 @@ suite('Debug Configuration Merge User Settings', () => {
219221
maxStructFields: 5
220222
},
221223
apiVersion: 1,
222-
showGlobalVariables: true
224+
showGlobalVariables: true,
225+
debugAdapter: 'dlv-dap',
226+
substitutePath: [{ from: 'hello', to: 'goodbye' }]
223227
}
224228
}
225229
}) as vscode.WorkspaceConfiguration;
@@ -236,6 +240,10 @@ suite('Debug Configuration Merge User Settings', () => {
236240
const result = await debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
237241
assert.strictEqual(result.apiVersion, 1);
238242
assert.strictEqual(result.showGlobalVariables, true);
243+
assert.strictEqual(result.debugAdapter, 'dlv-dap');
244+
assert.strictEqual(result.substitutePath.length, 1);
245+
assert.strictEqual(result.substitutePath[0].from, 'hello');
246+
assert.strictEqual(result.substitutePath[0].to, 'goodbye');
239247
const dlvLoadConfig = result.dlvLoadConfig;
240248
assert.strictEqual(dlvLoadConfig.followPointers, false);
241249
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 3);
@@ -261,13 +269,15 @@ suite('Debug Configuration Merge User Settings', () => {
261269
maxStructFields: 5
262270
},
263271
apiVersion: 1,
264-
showGlobalVariables: true
272+
showGlobalVariables: true,
273+
debugAdapter: 'dlv-dap',
274+
substitutePath: [{ from: 'hello', to: 'goodbye' }]
265275
}
266276
}
267277
}) as vscode.WorkspaceConfiguration;
268278
sinon.stub(config, 'getGoConfig').returns(goConfig);
269279

270-
const cfg = {
280+
const cfg: vscode.DebugConfiguration = {
271281
name: 'Launch',
272282
type: 'go',
273283
request: 'launch',
@@ -281,12 +291,16 @@ suite('Debug Configuration Merge User Settings', () => {
281291
maxStringLen: 128,
282292
maxArrayValues: 128,
283293
maxStructFields: -1
284-
}
294+
},
295+
debugAdapter: 'legacy',
296+
substitutePath: []
285297
};
286298

287299
const result = await debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
288300
assert.strictEqual(result.apiVersion, 2);
289301
assert.strictEqual(result.showGlobalVariables, false);
302+
assert.strictEqual(result.debugAdapter, 'legacy');
303+
assert.strictEqual(result.substitutePath.length, 0);
290304
const dlvLoadConfig = result.dlvLoadConfig;
291305
assert.strictEqual(dlvLoadConfig.followPointers, true);
292306
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 6);

0 commit comments

Comments
 (0)