Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add debug configuration options for test debug codelens #1749

Merged
merged 7 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 115 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@
}
},
"description": "LoadConfig describes to delve, how to load values from target's memory",
"default": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 64,
"maxArrayValues": 64,
"maxStructFields": -1
}
"default": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 64,
"maxArrayValues": 64,
"maxStructFields": -1
}
},
"useApiV1": {
"type": "boolean",
Expand Down Expand Up @@ -645,71 +645,71 @@
"scope": "resource"
},
"go.coverageDecorator": {
"type": "object",
"properties": {
"type": {
"type": "string",
"default": "highlight",
"enum": [
"highlight",
"gutter"
]
},
"coveredHighlightColor": {
"type": "string",
"default": "rgba(64,128,128,0.5)",
"description": "Color in the rgba format to use to highlight covered code."
},
"uncoveredHighlightColor": {
"type": "string",
"default": "rgba(128,64,64,0.25)",
"description": "Color in the rgba format to use to highlight uncovered code."
},
"coveredGutterStyle": {
"type": "string",
"default": "blockblue",
"enum": [
"blockblue",
"blockred",
"blockgreen",
"blockyellow",
"slashred",
"slashgreen",
"slashblue",
"slashyellow",
"verticalred",
"verticalgreen",
"verticalblue",
"verticalyellow"
],
"description": "Gutter style to indicate covered code."
},
"uncoveredGutterStyle": {
"type": "string",
"default": "blockblue",
"enum": [
"blockblue",
"blockred",
"blockgreen",
"blockyellow",
"slashred",
"slashgreen",
"slashblue",
"slashyellow",
"verticalred",
"verticalgreen",
"verticalblue",
"verticalyellow"
],
"description": "Gutter style to indicate covered code."
}
"type": "object",
"properties": {
"type": {
"type": "string",
"default": "highlight",
"enum": [
"highlight",
"gutter"
]
},
"coveredHighlightColor": {
"type": "string",
"default": "rgba(64,128,128,0.5)",
"description": "Color in the rgba format to use to highlight covered code."
},
"uncoveredHighlightColor": {
"type": "string",
"default": "rgba(128,64,64,0.25)",
"description": "Color in the rgba format to use to highlight uncovered code."
},
"coveredGutterStyle": {
"type": "string",
"default": "blockblue",
"enum": [
"blockblue",
"blockred",
"blockgreen",
"blockyellow",
"slashred",
"slashgreen",
"slashblue",
"slashyellow",
"verticalred",
"verticalgreen",
"verticalblue",
"verticalyellow"
],
"description": "Gutter style to indicate covered code."
},
"uncoveredGutterStyle": {
"type": "string",
"default": "blockblue",
"enum": [
"blockblue",
"blockred",
"blockgreen",
"blockyellow",
"slashred",
"slashgreen",
"slashblue",
"slashyellow",
"verticalred",
"verticalgreen",
"verticalblue",
"verticalyellow"
],
"description": "Gutter style to indicate covered code."
}
},
"default": {
"type": "highlight",
"coveredHighlightColor": "rgba(64,128,128,0.5)",
"uncoveredHighlightColor": "rgba(128,64,64,0.25)",
"coveredGutterStyle": "blockblue",
"uncoveredGutterStyle": "slashyellow"
"uncoveredGutterStyle": "slashyellow"
},
"description": "This option lets you choose the way to display code coverage. Choose either to highlight the complete line or to show a decorator in the gutter. You can customize the color for the former and the style for the latter.",
"scope": "resource"
Expand Down Expand Up @@ -1064,6 +1064,55 @@
"description": "Folder names (not paths) to ignore while using Go to Symbol in Workspace feature",
"scope": "resource"
},
"go.delveConfig": {
"type": "object",
"properties": {
"dlvLoadConfig": {
"type": "object",
"properties": {
"followPointers": {
"type": "boolean",
"description": "FollowPointers requests pointers to be automatically dereferenced",
"default": true
},
"maxVariableRecurse": {
"type": "number",
"description": "MaxVariableRecurse is how far to recurse when evaluating nested types",
"default": 1
},
"maxStringLen": {
"type": "number",
"description": "MaxStringLen is the maximum number of bytes read from a string",
"default": 64
},
"maxArrayValues": {
"type": "number",
"description": "MaxArrayValues is the maximum number of elements read from an array, a slice or a map",
"default": 64
},
"maxStructFields": {
"type": "number",
"description": "MaxStructFields is the maximum number of fields read from a struct, -1 will read all fields",
"default": -1
}
},
"description": "LoadConfig describes to delve, how to load values from target's memory",
"default": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 64,
"maxArrayValues": 64,
"maxStructFields": -1
}
},
"useApiV1": {
"type": "boolean",
"description": "If true, the v1 of delve apis will be used, else v2 will be used",
"default": true
}
},
"scope": "resource"
},
"go.alternateTools": {
"type": "object",
"default": {},
Expand Down
31 changes: 27 additions & 4 deletions src/goRunTestCodelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getCurrentGoPath } from './util';
import { GoBaseCodeLensProvider } from './goBaseCodelens';

export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
private readonly debugConfig: any = {
private readonly defaultDebugConfig: any = {
'name': 'Launch',
'type': 'go',
'request': 'launch',
Expand All @@ -28,6 +28,7 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
if (!this.enabled) {
return [];
}

let config = vscode.workspace.getConfiguration('go', document.uri);
let codeLensConfig = config.get('enableCodeLens');
let codelensEnabled = codeLensConfig ? codeLensConfig['runtest'] : false;
Expand Down Expand Up @@ -73,16 +74,16 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {

private getCodeLensForFunctions(vsConfig: vscode.WorkspaceConfiguration, document: TextDocument, token: CancellationToken): Thenable<CodeLens[]> {
const codelens: CodeLens[] = [];

const debugConfig = this.getDebugConfig(vsConfig);
const program = path.dirname(document.fileName);
const env = Object.assign({}, this.debugConfig.env, vsConfig['testEnvVars']);
const env = Object.assign({}, debugConfig.env, vsConfig['testEnvVars']);
const envFile = vsConfig['testEnvFile'];
const buildFlags = getTestFlags(vsConfig, null);
if (vsConfig['buildTags'] && buildFlags.indexOf('-tags') === -1) {
buildFlags.push('-tags');
buildFlags.push(`${vsConfig['buildTags']}`);
}
const currentDebugConfig = Object.assign({}, this.debugConfig, { program, env, envFile, buildFlags: buildFlags.map(x => `'${x}'`).join(' ') });
const currentDebugConfig = Object.assign({}, debugConfig, { program, env, envFile, buildFlags: buildFlags.map(x => `'${x}'`).join(' ') });

const testPromise = getTestFunctions(document, token).then(testFunctions => {
testFunctions.forEach(func => {
Expand Down Expand Up @@ -139,4 +140,26 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {

return Promise.all([testPromise, benchmarkPromise]).then(() => codelens);
}

private getDebugConfig(vsConfig: vscode.WorkspaceConfiguration): any {
let debugConfig: any = this.defaultDebugConfig;
let delveConfig: any = vsConfig.get('delveConfig');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same needs to be done in the resolveDebugConfiguration method at https://github.com/Microsoft/vscode-go/blob/master/src/goDebugConfiguration.ts. So we should probably move this to the util.ts file

This is what is used when we debug "main" programs without any launch.json files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I unified the default configurations for both normal and test codelens debug. This should get rid of the confusion caused by this difference, plus being configurable for delve


if (delveConfig !== undefined) {
if (delveConfig.useApiV1 !== undefined) {
debugConfig.useApiV1 = delveConfig.useApiV1;
}
if (delveConfig.dlvLoadConfig !== undefined) {
debugConfig.dlvLoadConfig = {
followPointers: delveConfig.dlvLoadConfig.followPointers,
maxVariableRecurse: delveConfig.dlvLoadConfig.maxVariableRecurse,
maxStringLen: delveConfig.dlvLoadConfig.maxStringLen,
maxArrayValues: delveConfig.dlvLoadConfig.maxArrayValues,
maxStructFields: delveConfig.dlvLoadConfig.maxStructFields
};
}
}

return debugConfig;
}
}