[release] prepare v0.20.0 release (2)
6c7bfb3 src/debugAdapter: report that next is automatically cancelled if interrupted
f38e348 src/goLanguageServer: propagate go.buildFlags,buildTags to gopls
dbc8da9 src/goDebug: fix drive casing when substituting paths
2f72921 test/integration/goDebug: disable a substitutePath test that times out
Change-Id: I1f808808aca0160ad51f1b8a0f809365d3f8513d
diff --git a/docs/settings.md b/docs/settings.md
index 80cf4bf..5d6b577 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -79,7 +79,7 @@
### `go.buildFlags`
-Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"])
+Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if `gopls.buildFlags` is not specified.
### `go.buildOnSave`
@@ -91,7 +91,7 @@
### `go.buildTags`
-The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set.
+The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set. This is propagated to the language server if `gopls.buildFlags` is not specified.
Default: ``
@@ -617,6 +617,8 @@
It is applied to queries like `go list`, which is used when discovering files.
The most common use is to set `-tags`.
+If unspecified, values of `go.buildFlags, go.buildTags` will be propagated.
+
#### `codelenses`
codelenses overrides the enabled/disabled state of code lenses. See the "Code Lenses"
@@ -626,7 +628,7 @@
```json5
"gopls": {
...
- "codelenses": {
+ "codelens": {
"generate": false, // Don't show the `go generate` lens.
"gc_details": true // Show a code lens toggling the display of gc's choices.
}
diff --git a/package.json b/package.json
index df096e0..c311d06 100644
--- a/package.json
+++ b/package.json
@@ -847,13 +847,13 @@
"type": "string"
},
"default": [],
- "description": "Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. [\"-ldflags='-s'\"])",
+ "description": "Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. [\"-ldflags='-s'\"]) This is propagated to the language server if `gopls.buildFlags` is not specified.",
"scope": "resource"
},
"go.buildTags": {
"type": "string",
"default": "",
- "description": "The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set.",
+ "description": "The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set. This is propagated to the language server if `gopls.buildFlags` is not specified.",
"scope": "resource"
},
"go.testTags": {
@@ -1693,7 +1693,7 @@
"properties": {
"buildFlags": {
"type": "array",
- "markdownDescription": "buildFlags is the set of flags passed on to the build system when invoked.\nIt is applied to queries like `go list`, which is used when discovering files.\nThe most common use is to set `-tags`.\n",
+ "markdownDescription": "buildFlags is the set of flags passed on to the build system when invoked.\nIt is applied to queries like `go list`, which is used when discovering files.\nThe most common use is to set `-tags`.\n\nIf unspecified, values of `go.buildFlags, go.buildTags` will be propagated.\n",
"default": [],
"scope": "resource"
},
@@ -1755,7 +1755,7 @@
},
"codelenses": {
"type": "object",
- "markdownDescription": "codelenses overrides the enabled/disabled state of code lenses. See the \"Code Lenses\"\nsection of settings.md for the list of supported lenses.\n\nExample Usage:\n```json5\n\"gopls\": {\n...\n \"codelenses\": {\n \"generate\": false, // Don't show the `go generate` lens.\n \"gc_details\": true // Show a code lens toggling the display of gc's choices.\n }\n...\n}\n```\n",
+ "markdownDescription": "codelenses overrides the enabled/disabled state of code lenses. See the \"Code Lenses\"\nsection of settings.md for the list of supported lenses.\n\nExample Usage:\n```json5\n\"gopls\": {\n...\n \"codelens\": {\n \"generate\": false, // Don't show the `go generate` lens.\n \"gc_details\": true // Show a code lens toggling the display of gc's choices.\n }\n...\n}\n```\n",
"default": {
"gc_details": false,
"generate": true,
diff --git a/src/debugAdapter/goDebug.ts b/src/debugAdapter/goDebug.ts
index 788af3d..72d1772 100644
--- a/src/debugAdapter/goDebug.ts
+++ b/src/debugAdapter/goDebug.ts
@@ -90,6 +90,7 @@
currentGoroutine: DebugGoroutine;
Running: boolean;
Threads: DebugThread[];
+ NextInProgress: boolean;
}
export interface PackageBuildInfo {
@@ -371,7 +372,18 @@
return filePath;
}
-function normalizeSeparators(filePath: string): string {
+// normalizeSeparators will prepare the filepath for comparison in mapping from
+// local to debugger path and from debugger path to local path. All separators are
+// replaced with '/', and the drive name is capitalized for windows paths.
+// Exported for testing
+export function normalizeSeparators(filePath: string): string {
+ // Although the current machine may not be running windows,
+ // the remote machine may be and we need to fix the drive
+ // casing.
+ // This is a workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
+ if (filePath.indexOf(':') === 1) {
+ filePath = filePath.substr(0, 1).toUpperCase() + filePath.substr(1);
+ }
return filePath.replace(/\/|\\/g, '/');
}
@@ -846,6 +858,7 @@
private breakpoints: Map<string, DebugBreakpoint[]>;
// Editing breakpoints requires halting delve, skip sending Stop Event to VS Code in such cases
private skipStopEventOnce: boolean;
+ private overrideStopReason: string;
private debugState: DebuggerState;
private delve: Delve;
private localPathSeparator: string;
@@ -866,6 +879,8 @@
private continueEpoch = 0;
private continueRequestRunning = false;
+ private nextEpoch = 0;
+ private nextRequestRunning = false;
public constructor(
debuggerLinesStartAt1: boolean,
isServer: boolean = false,
@@ -873,6 +888,7 @@
super('', debuggerLinesStartAt1, isServer);
this.variableHandles = new Handles<DebugVariable>();
this.skipStopEventOnce = false;
+ this.overrideStopReason = '';
this.stopOnEntry = false;
this.debugState = null;
this.delve = null;
@@ -1292,11 +1308,25 @@
log('Debuggee is not running. Setting breakpoints without halting.');
await this.setBreakPoints(response, args);
} else {
+ // Skip stop event if a continue request is running.
this.skipStopEventOnce = this.continueRequestRunning;
+ const haltedDuringNext = this.nextRequestRunning;
+ if (haltedDuringNext) {
+ this.overrideStopReason = 'next cancelled';
+ }
+
log(`Halting before setting breakpoints. SkipStopEventOnce is ${this.skipStopEventOnce}.`);
this.delve.callPromise('Command', [{ name: 'halt' }]).then(
() => {
return this.setBreakPoints(response, args).then(() => {
+ // We do not want to continue if it was running a next request, since the
+ // request was automatically cancelled.
+ if (haltedDuringNext) {
+ // Send an output event containing a warning that next was cancelled.
+ const warning = `Setting breakpoints during 'next', 'step in' or 'step out' halted delve and cancelled the next request`;
+ this.sendEvent(new OutputEvent(warning, 'stderr'));
+ return;
+ }
return this.continue(true).then(null, (err) => {
this.logDelveError(err, 'Failed to continue delve after halting it to set breakpoints');
});
@@ -1676,8 +1706,16 @@
}
protected nextRequest(response: DebugProtocol.NextResponse): void {
+ this.nextEpoch++;
+ const closureEpoch = this.nextEpoch;
+ this.nextRequestRunning = true;
+
log('NextRequest');
this.delve.call<DebuggerState | CommandOut>('Command', [{ name: 'next' }], (err, out) => {
+ if (closureEpoch === this.continueEpoch) {
+ this.nextRequestRunning = false;
+ }
+
if (err) {
this.logDelveError(err, 'Failed to next');
}
@@ -1691,8 +1729,16 @@
}
protected stepInRequest(response: DebugProtocol.StepInResponse): void {
+ this.nextEpoch++;
+ const closureEpoch = this.nextEpoch;
+ this.nextRequestRunning = true;
+
log('StepInRequest');
this.delve.call<DebuggerState | CommandOut>('Command', [{ name: 'step' }], (err, out) => {
+ if (closureEpoch === this.continueEpoch) {
+ this.nextRequestRunning = false;
+ }
+
if (err) {
this.logDelveError(err, 'Failed to step in');
}
@@ -1706,8 +1752,16 @@
}
protected stepOutRequest(response: DebugProtocol.StepOutResponse): void {
+ this.nextEpoch++;
+ const closureEpoch = this.nextEpoch;
+ this.nextRequestRunning = true;
+
log('StepOutRequest');
this.delve.call<DebuggerState | CommandOut>('Command', [{ name: 'stepOut' }], (err, out) => {
+ if (closureEpoch === this.continueEpoch) {
+ this.nextRequestRunning = false;
+ }
+
if (err) {
this.logDelveError(err, 'Failed to step out');
}
@@ -2341,6 +2395,11 @@
return;
}
+ if (this.overrideStopReason?.length > 0) {
+ reason = this.overrideStopReason;
+ this.overrideStopReason = '';
+ }
+
const stoppedEvent = new StoppedEvent(reason, this.debugState.currentGoroutine.id);
(<any>stoppedEvent.body).allThreadsStopped = true;
this.sendEvent(stoppedEvent);
@@ -2364,7 +2423,7 @@
} catch (error) {
this.logDelveError(error, 'Failed to get state');
// Fall back to the internal tracking.
- return this.continueRequestRunning;
+ return this.continueRequestRunning || this.nextRequestRunning;
}
}
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 8ef78b9..9d4db9d 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -290,9 +290,7 @@
// buildLanguageClient returns a language client built using the given language server config.
// The returned language client need to be started before use.
export async function buildLanguageClient(cfg: BuildLanguageClientOption): Promise<LanguageClient> {
- let goplsWorkspaceConfig = getGoplsConfig() as any;
- goplsWorkspaceConfig = filterDefaultConfigValues(goplsWorkspaceConfig, 'gopls', undefined);
- goplsWorkspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, goplsWorkspaceConfig);
+ const goplsWorkspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, getGoplsConfig(), 'gopls', undefined);
const c = new LanguageClient(
'go', // id
cfg.serverName, // name e.g. gopls
@@ -505,8 +503,7 @@
const scopeUri = params.items[i].scopeUri;
const resource = scopeUri ? vscode.Uri.parse(scopeUri) : undefined;
const section = params.items[i].section;
- workspaceConfig = filterDefaultConfigValues(workspaceConfig, section, resource);
- workspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, workspaceConfig);
+ workspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, workspaceConfig, section, resource);
}
ret.push(workspaceConfig);
}
@@ -519,19 +516,15 @@
return c;
}
-// filterDefaultConfigValues removes the entries filled based on the default values
+// filterGoplsDefaultConfigValues removes the entries filled based on the default values
// and selects only those the user explicitly specifies in their settings.
-// This assumes workspaceConfig is a non-null(undefined) object type.
+// This returns a new object created based on the filtered properties of workspaceConfig.
// Exported for testing.
-export function filterDefaultConfigValues(workspaceConfig: any, section: string, resource: vscode.Uri): any {
+export function filterGoplsDefaultConfigValues(workspaceConfig: any, resource: vscode.Uri): any {
if (!workspaceConfig) {
- return workspaceConfig;
+ workspaceConfig = {};
}
-
- const dot = section?.lastIndexOf('.') || -1;
- const sectionKey = dot >= 0 ? section.substr(0, dot) : section; // e.g. 'gopls'
-
- const cfg = vscode.workspace.getConfiguration(sectionKey, resource);
+ const cfg = getGoplsConfig(resource);
const filtered = {} as { [key: string]: any };
for (const [key, value] of Object.entries(workspaceConfig)) {
if (typeof value === 'function') {
@@ -556,31 +549,63 @@
return filtered;
}
-// adjustGoplsWorkspaceConfiguration adds any extra options to the gopls
-// config. Right now, the only extra option is enabling experiments for the
-// Nightly extension.
-async function adjustGoplsWorkspaceConfiguration(cfg: LanguageServerConfig, config: any): Promise<any> {
- if (!config) {
- return config;
+// passGoConfigToGoplsConfigValues passes some of the relevant 'go.' settings to gopls settings.
+// This assumes `goplsWorkspaceConfig` is an output of filterGoplsDefaultConfigValues,
+// so it is modifiable and doesn't contain properties that are not explicitly set.
+// - go.buildTags and go.buildFlags are passed as gopls.buildFlags
+// if goplsWorkspaceConfig doesn't explicitly set it yet.
+// Exported for testing.
+export function passGoConfigToGoplsConfigValues(goplsWorkspaceConfig: any, goWorkspaceConfig: any): any {
+ if (!goplsWorkspaceConfig) {
+ goplsWorkspaceConfig = {};
}
+
+ // If gopls.buildFlags is set, don't touch it.
+ if (goplsWorkspaceConfig.buildFlags === undefined) {
+ const buildFlags = [] as string[];
+ if (goWorkspaceConfig?.buildFlags) {
+ buildFlags.push(...goWorkspaceConfig?.buildFlags);
+ }
+ if (goWorkspaceConfig?.buildTags && buildFlags.indexOf('-tags') === -1) {
+ buildFlags.push('-tags', goWorkspaceConfig?.buildTags);
+ }
+ if (buildFlags.length > 0) {
+ goplsWorkspaceConfig.buildFlags = buildFlags;
+ }
+ }
+ return goplsWorkspaceConfig;
+}
+
+// adjustGoplsWorkspaceConfiguration filters unnecessary options and adds any necessary, additional
+// options to the gopls config. See filterGoplsDefaultConfigValues, passGoConfigToGoplsConfigValues.
+// If this is for the nightly extension, we also request to activate features under experiments.
+async function adjustGoplsWorkspaceConfiguration(cfg: LanguageServerConfig, workspaceConfig: any, section: string, resource: vscode.Uri): Promise<any> {
+ // We process only gopls config
+ if (section !== 'gopls') {
+ return workspaceConfig;
+ }
+
+ workspaceConfig = filterGoplsDefaultConfigValues(workspaceConfig, resource);
+ // note: workspaceConfig is a modifiable, valid object.
+ workspaceConfig = passGoConfigToGoplsConfigValues(workspaceConfig, getGoConfig(resource));
+
// Only modify the user's configurations for the Nightly.
if (extensionId !== 'golang.go-nightly') {
- return config;
+ return workspaceConfig;
}
// allExperiments is only available with gopls/v0.5.2 and above.
const version = await getLocalGoplsVersion(cfg);
if (!version) {
- return config;
+ return workspaceConfig;
}
const sv = semver.parse(version, true);
if (!sv || semver.lt(sv, 'v0.5.2')) {
- return config;
+ return workspaceConfig;
}
- const newConfig = Object.assign({}, config);
- if (!config['allExperiments']) {
- newConfig['allExperiments'] = true;
+ if (!workspaceConfig['allExperiments']) {
+ workspaceConfig['allExperiments'] = true;
}
- return newConfig;
+ return workspaceConfig;
}
// createTestCodeLens adds the go.test.cursor and go.debug.cursor code lens
diff --git a/src/util.ts b/src/util.ts
index 248d569..6211b57 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -158,12 +158,12 @@
// getGoConfig is declared as an exported const rather than a function, so it can be stubbbed in testing.
export const getGoConfig = (uri?: vscode.Uri) => {
- return getConfig('go');
+ return getConfig('go', uri);
};
// getGoplsConfig returns the user's gopls configuration.
-export function getGoplsConfig() {
- return getConfig('gopls');
+export function getGoplsConfig(uri?: vscode.Uri) {
+ return getConfig('gopls', uri);
}
// getCheckForToolsUpdatesConfig returns go.toolsManagement.checkForUpdates configuration.
diff --git a/test/gopls/configuration.test.ts b/test/gopls/configuration.test.ts
index e2adea4..5d68043 100644
--- a/test/gopls/configuration.test.ts
+++ b/test/gopls/configuration.test.ts
@@ -12,27 +12,33 @@
import { getTool, Tool } from '../../src/goTools';
suite('gopls configuration tests', () => {
- test('configuration', async () => {
+ test('filterGoplsDefaultConfigValues', async () => {
const defaultGoplsConfig = vscode.workspace.getConfiguration('gopls');
const defaultGoplsAnalysesConfig = vscode.workspace.getConfiguration('gopls.analyses');
interface TestCase {
name: string;
section: string;
- base: any;
+ input: any;
want: any;
}
const testCases: TestCase[] = [
{
name: 'user set no gopls settings',
section: 'gopls',
- base: defaultGoplsConfig,
+ input: defaultGoplsConfig,
want: {}
},
{
name: 'user set some gopls settings',
section: 'gopls',
- base: defaultGoplsConfig,
+ input: Object.assign({}, defaultGoplsConfig, {
+ buildFlags: ['-something'],
+ env: { foo: 'bar' },
+ hoverKind: 'NoDocumentation',
+ usePlaceholders: true,
+ linkTarget: 'godoc.org'
+ }),
want: {
buildFlags: ['-something'],
env: { foo: 'bar' },
@@ -42,37 +48,119 @@
},
},
{
- name: 'gopls asks analyses section, user set no analysis',
- section: 'gopls.analyses',
- base: defaultGoplsAnalysesConfig,
- want: {},
- },
- {
- name: 'gopls asks analyses section, user set some',
- section: 'gopls.analyses',
- base: defaultGoplsAnalysesConfig,
- want: {
- coolAnalysis: true,
- },
- },
- {
name: 'user set extra gopls settings',
section: 'gopls',
- base: defaultGoplsConfig,
+ input: Object.assign({}, defaultGoplsConfig, {
+ undefinedGoplsSetting: true
+ }),
want: {
undefinedGoplsSetting: true,
},
},
{
- name: 'gopls asks undefined config section',
+ name: 'never returns undefined',
section: 'undefined.section',
- base: undefined,
+ input: undefined,
want: {},
- }
+ },
];
testCases.map((tc: TestCase) => {
- const input = Object.assign({}, tc.base, tc.want);
- const actual = lsp.filterDefaultConfigValues(input, tc.section, undefined);
+ const actual = lsp.filterGoplsDefaultConfigValues(tc.input, undefined);
+ assert.deepStrictEqual(actual, tc.want, `Failed: ${tc.name}`);
+ });
+ });
+
+ test('passGoConfigToGoplsConfigValues', async () => {
+ interface TestCase {
+ name: string;
+ goplsConfig: any;
+ goConfig: any;
+ want: any;
+ }
+ const testCases: TestCase[] = [
+ {
+ name: 'undefined gopls, go configs result in an empty config',
+ goplsConfig: undefined,
+ goConfig: undefined,
+ want: {}
+ },
+ {
+ name: 'empty gopls, go configs result in an empty config',
+ goplsConfig: {},
+ goConfig: {},
+ want: {}
+ },
+ {
+ name: 'empty gopls, default go configs result in an empty config',
+ goplsConfig: {},
+ goConfig: {
+ buildFlags: [],
+ buildTags: '',
+ },
+ want: {}
+ },
+ {
+ name: 'pass go config buildFlags to gopls config',
+ goplsConfig: {},
+ goConfig: { buildFlags: ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw'] },
+ want: { buildFlags: ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw']}
+ },
+ {
+ name: 'pass go config buildTags to gopls config',
+ goplsConfig: {},
+ goConfig: { buildTags: 'tag1,tag2' },
+ want: { buildFlags: ['-tags', 'tag1,tag2']}
+ },
+ {
+ name: 'do not pass go config buildTags if buildFlags already have tags',
+ goplsConfig: {},
+ goConfig: {
+ buildFlags: ['-tags', 'tag0'],
+ buildTags: 'tag1,tag2'
+ },
+ want: { buildFlags: ['-tags', 'tag0']}
+ },
+ {
+ name: 'do not mutate other gopls config but gopls.buildFlags',
+ goplsConfig: {
+ env: {GOPROXY: 'direct'}
+ },
+ goConfig: { buildFlags: ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw'] },
+ want: {
+ env: { GOPROXY : 'direct' },
+ buildFlags: ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw']}
+ },
+
+ {
+ name: 'do not mutate misconfigured gopls.buildFlags',
+ goplsConfig: {
+ buildFlags: '-modfile gopls.mod', // misconfiguration
+ },
+ goConfig: {
+ buildFlags: '-modfile go.mod -tags tag1 -modcacherw',
+ },
+ want: { buildFlags: '-modfile gopls.mod' }
+ },
+ {
+ name: 'do not overwrite gopls config if it is explicitly set',
+ goplsConfig: {
+ env: {GOPROXY: 'direct'},
+ buildFlags: [], // empty
+ },
+ goConfig: {
+ // expect only non-conflicting flags (tags, modcacherw) passing.
+ buildFlags: ['-modfile go.mod -tags tag1 -modcacherw'],
+ buildTags: 'tag3',
+ },
+ want: {
+ env: {GOPROXY: 'direct'},
+ buildFlags: [],
+ } // gopls.buildFlags untouched.
+ },
+
+ ];
+ testCases.map((tc: TestCase) => {
+ const actual = lsp.passGoConfigToGoplsConfigValues(tc.goplsConfig, tc.goConfig);
assert.deepStrictEqual(actual, tc.want, `Failed: ${tc.name}`);
});
});
diff --git a/test/integration/goDebug.test.ts b/test/integration/goDebug.test.ts
index 272e4d8..fbf775b 100644
--- a/test/integration/goDebug.test.ts
+++ b/test/integration/goDebug.test.ts
@@ -880,6 +880,117 @@
await killProcessTree(remoteProgram);
await new Promise((resolve) => setTimeout(resolve, 2_000));
});
+
+ test('stopped for a breakpoint set during initialization (remote attach)', async () => {
+ const FILE = path.join(DATA_ROOT, 'helloWorldServer', 'main.go');
+ const BREAKPOINT_LINE = 29;
+ const remoteProgram = await setUpRemoteProgram(remoteAttachConfig.port, server);
+
+ const breakpointLocation = getBreakpointLocation(FILE, BREAKPOINT_LINE, false);
+
+ // Setup attach with a breakpoint.
+ await setUpRemoteAttach(remoteAttachDebugConfig, [breakpointLocation]);
+
+ // Calls the helloworld server to make the breakpoint hit.
+ await waitForBreakpoint(
+ () => http.get(`http://localhost:${server}`).on('error', (data) => console.log(data)),
+ breakpointLocation);
+
+ await dc.disconnectRequest({restart: false});
+ await killProcessTree(remoteProgram);
+ await new Promise((resolve) => setTimeout(resolve, 2_000));
+ });
+
+ test('should set breakpoints during continue', async () => {
+ const PROGRAM = path.join(DATA_ROOT, 'sleep');
+
+ const FILE = path.join(DATA_ROOT, 'sleep', 'sleep.go');
+ const HELLO_LINE = 10;
+ const helloLocation = getBreakpointLocation(FILE, HELLO_LINE);
+
+ const config = {
+ name: 'Launch file',
+ type: 'go',
+ request: 'launch',
+ mode: 'auto',
+ program: PROGRAM
+ };
+ const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config);
+
+ await Promise.all([
+ dc.configurationSequence(),
+ dc.launch(debugConfig),
+ ]);
+
+ return Promise.all([
+ dc.setBreakpointsRequest({
+ lines: [ helloLocation.line ],
+ breakpoints: [ { line: helloLocation.line, column: 0 } ],
+ source: { path: helloLocation.path }
+ }),
+ dc.assertStoppedLocation('breakpoint', helloLocation)
+ ]);
+ });
+
+ async function setBreakpointsDuringStep(nextFunc: () => void) {
+ const PROGRAM = path.join(DATA_ROOT, 'sleep');
+
+ const FILE = path.join(DATA_ROOT, 'sleep', 'sleep.go');
+ const SLEEP_LINE = 11;
+ const setupBreakpoint = getBreakpointLocation(FILE, SLEEP_LINE);
+
+ const HELLO_LINE = 10;
+ const onNextBreakpoint = getBreakpointLocation(FILE, HELLO_LINE);
+
+ const config = {
+ name: 'Launch file',
+ type: 'go',
+ request: 'launch',
+ mode: 'auto',
+ program: PROGRAM
+ };
+ const debugConfig = debugConfigProvider.resolveDebugConfiguration(undefined, config);
+
+ await dc.hitBreakpoint(debugConfig, setupBreakpoint);
+
+ // The program is now stopped at the line containing time.Sleep().
+ // Issue a next request, followed by a setBreakpointsRequest.
+ nextFunc();
+
+ // Note: the current behavior of setting a breakpoint during a next
+ // request will cause the step to be interrupted, so it may not be
+ // stopped on the next line.
+ await Promise.all([
+ dc.setBreakpointsRequest({
+ lines: [ onNextBreakpoint.line ],
+ breakpoints: [ { line: onNextBreakpoint.line, column: 0 } ],
+ source: { path: onNextBreakpoint.path }
+ }),
+ dc.assertStoppedLocation('next cancelled', {})
+ ]);
+
+ // Once the 'step' has completed, continue the program and
+ // make sure the breakpoint set while the program was nexting
+ // is succesfully hit.
+ await Promise.all([
+ dc.continueRequest({threadId: 1}),
+ dc.assertStoppedLocation('breakpoint', onNextBreakpoint)
+ ]);
+ }
+
+ test('should set breakpoints during next', async () => {
+ setBreakpointsDuringStep(async () => {
+ const nextResponse = await dc.nextRequest({threadId: 1});
+ assert.ok(nextResponse.success);
+ });
+ });
+
+ test('should set breakpoints during step out', async () => {
+ setBreakpointsDuringStep(async () => {
+ const stepOutResponse = await dc.stepOutRequest({threadId: 1});
+ assert.ok(stepOutResponse.success);
+ });
+ });
});
suite('conditionalBreakpoints', () => {
@@ -1404,7 +1515,9 @@
await new Promise((resolve) => setTimeout(resolve, 2_000));
});
- test('stopped for a breakpoint set during initialization using remotePath (remote attach)', async () => {
+ // Skip because it times out in nightly release workflow.
+ // BUG(https://github.com/golang/vscode-go/issues/1043)
+ test.skip('stopped for a breakpoint set during initialization using remotePath (remote attach)', async () => {
const FILE = path.join(helloWorldLocal, 'main.go');
const BREAKPOINT_LINE = 29;
const remoteProgram = await setUpRemoteProgram(remoteAttachConfig.port, server);
diff --git a/test/unit/goDebug.test.ts b/test/unit/goDebug.test.ts
new file mode 100644
index 0000000..686b5bb
--- /dev/null
+++ b/test/unit/goDebug.test.ts
@@ -0,0 +1,98 @@
+/*---------------------------------------------------------
+ * Copyright (C) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See LICENSE in the project root for license information.
+ *--------------------------------------------------------*/
+
+import * as assert from 'assert';
+import { normalizeSeparators } from '../../src/debugAdapter/goDebug';
+
+suite('NormalizeSeparators Tests', () => {
+ test('fix separator', () => {
+ const tt = [
+ {
+ input: 'path/to/file',
+ want: 'path/to/file',
+ },
+ {
+ input: '\\path\\to\\file',
+ want: '/path/to/file',
+ },
+ {
+ input: '/path/to\\file',
+ want: '/path/to/file',
+ },
+ ];
+
+ for (const tc of tt) {
+ const got = normalizeSeparators(tc.input);
+ assert.strictEqual(got, tc.want);
+ }
+ });
+ test('fix drive casing', () => {
+ const tt = [
+ {
+ input: 'C:/path/to/file',
+ want: 'C:/path/to/file',
+ },
+ {
+ input: 'c:/path/to/file',
+ want: 'C:/path/to/file',
+ },
+ {
+ input: 'C:/path/to/file',
+ want: 'C:/path/to/file',
+ },
+ {
+ input: 'C:\\path\\to\\file',
+ want: 'C:/path/to/file',
+ },
+ {
+ input: 'c:\\path\\to\\file',
+ want: 'C:/path/to/file',
+ },
+ {
+ input: 'c:\\path\\to\\file',
+ want: 'C:/path/to/file',
+ }
+ ];
+
+ for (const tc of tt) {
+ const got = normalizeSeparators(tc.input);
+ assert.strictEqual(got, tc.want);
+ }
+ });
+ test('relative paths', () => {
+ const tt = [
+ {
+ input: '../path/to/file',
+ want: '../path/to/file',
+ },
+ {
+ input: './path/to/file',
+ want: './path/to/file',
+ },
+ {
+ input: '..\\path\\to\\file',
+ want: '../path/to/file',
+ },
+ {
+ input: '.\\path\\to\\file',
+ want: './path/to/file',
+ },
+ {
+ input: '/path/to/../file',
+ want: '/path/to/../file',
+ },
+ {
+ input: 'c:\\path\\to\\..\\file',
+ want: 'C:/path/to/../file',
+ }
+ ];
+
+ for (const tc of tt) {
+ const got = normalizeSeparators(tc.input);
+ assert.strictEqual(got, tc.want);
+ }
+ });
+
+});
diff --git a/tools/goplssetting/main.go b/tools/goplssetting/main.go
index 868a027..e10955f 100644
--- a/tools/goplssetting/main.go
+++ b/tools/goplssetting/main.go
@@ -194,7 +194,11 @@
line(` "type": %q,`, typ)
// TODO: consider 'additionalProperties' if gopls api-json outputs acceptable peoperties.
- line(` "markdownDescription": %q,`, o.Doc)
+ doc := o.Doc
+ if mappedTo, ok := associatedToExtensionProperties[o.Name]; ok {
+ doc = fmt.Sprintf("%v\nIf unspecified, values of `%v` will be propagated.\n", doc, strings.Join(mappedTo, ", "))
+ }
+ line(` "markdownDescription": %q,`, doc)
var enums, enumDocs []string
for _, v := range o.EnumValues {
@@ -226,6 +230,10 @@
line(`}`) // {
}
+var associatedToExtensionProperties = map[string][]string{
+ "buildFlags": []string{"go.buildFlags", "go.buildTags"},
+}
+
func propertyType(t string) string {
switch t {
case "string":