Skip to content

Commit ed978a6

Browse files
hashedhyphenhyangah
authored andcommitted
src/goDebugConfiguration: infer default mode property
The mode property in launch.json defaults to local for attach requests. However, if mode property for attach requests is omitted, configs returned by resolveDebugConfiguration() have undefined mode. This leads to cannot unmarshal string into processId to type int error due to skipping parseInt in resolveDebugConfigurationWithSubstitutedVariables hook when using command:pickGoProcess. This change fixes the issue by setting the default value. Fixes #1929 Change-Id: Ifa6501d1db9727aacad1368a93d10e941a3de17e GitHub-Last-Rev: 6bcf535 GitHub-Pull-Request: #1932 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/370454 Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Peter Weinberger <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent f5d1004 commit ed978a6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/goDebugConfiguration.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
141141
debugConfiguration['type'] = this.defaultDebugAdapterType;
142142
}
143143

144+
if (!debugConfiguration['mode']) {
145+
if (debugConfiguration.request === 'launch') {
146+
// 'auto' will decide mode by checking file extensions later
147+
debugConfiguration['mode'] = 'auto';
148+
} else if (debugConfiguration.request === 'attach') {
149+
debugConfiguration['mode'] = 'local';
150+
}
151+
}
152+
144153
debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;
145154

146155
const goConfig = getGoConfig(folder && folder.uri);

test/integration/goDebugConfiguration.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,45 @@ suite('Debug Configuration Default DebugAdapter', () => {
920920
assert.strictEqual(resolvedConfig['debugAdapter'], want);
921921
});
922922
});
923+
924+
suite('Debug Configuration Infers Default Mode Property', () => {
925+
const debugConfigProvider = new GoDebugConfigurationProvider();
926+
test("default mode for launch requests and test Go programs should be 'test'", () => {
927+
const config = {
928+
name: 'Launch',
929+
type: 'go',
930+
request: 'launch',
931+
program: '/path/to/main_test.go'
932+
};
933+
934+
debugConfigProvider.resolveDebugConfiguration(undefined, config);
935+
const resolvedConfig = config as any;
936+
assert.strictEqual(resolvedConfig['mode'], 'test');
937+
});
938+
939+
test("default mode for launch requests and non-test Go programs should be 'debug'", () => {
940+
const config = {
941+
name: 'Launch',
942+
type: 'go',
943+
request: 'launch',
944+
program: '/path/to/main.go'
945+
};
946+
947+
debugConfigProvider.resolveDebugConfiguration(undefined, config);
948+
const resolvedConfig = config as any;
949+
assert.strictEqual(resolvedConfig['mode'], 'debug');
950+
});
951+
952+
test("default mode for attach requests should be 'local'", () => {
953+
const config = {
954+
name: 'Attach',
955+
type: 'go',
956+
request: 'attach',
957+
program: '/path/to/main.go'
958+
};
959+
960+
debugConfigProvider.resolveDebugConfiguration(undefined, config);
961+
const resolvedConfig = config as any;
962+
assert.strictEqual(resolvedConfig['mode'], 'local');
963+
});
964+
});

0 commit comments

Comments
 (0)