Suzy Mueller has uploaded this change for review.
src/goDebugConfiguration: use fileWorkspaceFolder in multi root workspace
In multi folder workspaces, it is not allowed to use `${workspaceFolder}`.
If we detect that it is a multi folder workspace, we instead use
`${fileWorkspaceFolder}` which will get the folder of the current open
file.
Fixes golang/vscode-go#1499
Change-Id: Ibbe6e869cb0e5093c1bcd9f55d8f7057bceeed9f
---
M docs/debugging.md
M src/goDebugConfiguration.ts
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/docs/debugging.md b/docs/debugging.md
index 4b55ced..9b2dc46 100644
--- a/docs/debugging.md
+++ b/docs/debugging.md
@@ -69,8 +69,7 @@
* `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`).
- * `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: `[]`).
+ * `showGlobalVariables`: Show global variables in the Debug view (default: `false`).
There are some common cases when you might want to tweak the Delve configurations.
@@ -162,7 +161,8 @@
Any property in the launch configuration that requires a file path can be specified in terms of [VS Code variables]. Here are some useful ones to know:
-* `${workspaceFolder}` refers to the root of the workspace opened in VS Code.
+* `${workspaceFolder}` refers to the root of the workspace opened in VS Code. If using a multi root workspace, you must specify the folder name `${workspaceFolder:folderName}`
+* `${fileWorkspaceFolder}` refers to the the current opened file's workspace folder.
* `${file}` refers to the currently opened file.
* `${fileDirname}` refers to the directory containing the currently opened file. This is typically also the name of the Go package containing this file, and as such, can be used to debug the currently opened package.
diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts
index 2923793..ca42792 100644
--- a/src/goDebugConfiguration.ts
+++ b/src/goDebugConfiguration.ts
@@ -188,6 +188,9 @@
}
if (debugConfiguration.request === 'attach' && !debugConfiguration['cwd']) {
debugConfiguration['cwd'] = '${workspaceFolder}';
+ if (vscode.workspace.workspaceFolders?.length > 1) {
+ debugConfiguration['cwd'] = '${fileWorkspaceFolder}';
+ }
}
if (debugConfiguration['cwd']) {
// expand 'cwd' folder path containing '~', which would cause dlv to fail
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
Kokoro presubmit build finished with status: SUCCESS
Logs at: https://source.cloud.google.com/results/invocations/db8e3918-43d2-455f-9dab-0794e8480734
Patch set 1:TryBot-Result +1
Attention is currently required from: Suzy Mueller.
1 comment:
File src/goDebugConfiguration.ts:
if (vscode.workspace.workspaceFolders?.length > 1) {
debugConfiguration['cwd'] = '${fileWorkspaceFolder}';
What will happen if there is no opened file or a wrong file is open?
Another alternative to consider is the 'folder' parameter passed into the resolveDebugConfiguration. According to the API, it is the workspace folder from which this configuration originates from.
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim.
1 comment:
File src/goDebugConfiguration.ts:
if (vscode.workspace.workspaceFolders?.length > 1) {
debugConfiguration['cwd'] = '${fileWorkspaceFolder}';
What will happen if there is no opened file or a wrong file is open? […]
folder is undefined if the workspace that the configuration is originated from is not tied to a folder.
If no file is open, I'm not sure how we could correctly identify which folder to choose. Before the last change, we would arbitrarily pick the first folder in the list of folders. I could add the code back in to do that again if there are multiple workspace folders.
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Suzy Mueller.
Patch set 1:Code-Review +2
2 comments:
File docs/debugging.md:
Patch Set #1, Line 119: cwd | The working directory to be used in running the program. If remote debugging (`mode`: `remote`), this should be the absolute path to the working directory being debugged on the local machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
Let's mention that if not specified, we default to the fileWorkspaceFolder that is determined by the currently open file.
File src/goDebugConfiguration.ts:
if (vscode.workspace.workspaceFolders?.length > 1) {
debugConfiguration['cwd'] = '${fileWorkspaceFolder}';
folder is undefined if the workspace that the configuration is originated from is not tied to a fold […]
I think we are dealing with a misconfiguration case, so maybe anything is ok.
Since we got only one report and the user is happy with `${fileWorkspaceFolder}`, let's go with it then.
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
File docs/debugging.md:
Patch Set #1, Line 119: cwd | The working directory to be used in running the program. If remote debugging (`mode`: `remote`), this should be the absolute path to the working directory being debugged on the local machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
Let's mention that if not specified, we default to the fileWorkspaceFolder that is determined by the […]
Done
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Hyang-Ah Hana Kim.
Suzy Mueller uploaded patch set #2 to this change.
src/goDebugConfiguration: use fileWorkspaceFolder in multi root workspace
In multi folder workspaces, it is not allowed to use `${workspaceFolder}`.
If we detect that it is a multi folder workspace, we instead use
`${fileWorkspaceFolder}` which will get the folder of the current open
file.
Fixes golang/vscode-go#1499
Change-Id: Ibbe6e869cb0e5093c1bcd9f55d8f7057bceeed9f
---
M docs/debugging.md
M src/goDebugConfiguration.ts
2 files changed, 7 insertions(+), 2 deletions(-)
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: Suzy Mueller, Hyang-Ah Hana Kim.
Kokoro presubmit build finished with status: FAILURE
Logs at: https://source.cloud.google.com/results/invocations/bee3405e-9060-4e0f-a95c-e2aebe52f8d3
Patch set 2:TryBot-Result -1
Patchset:
unrelated failure. Need to update the tests to reflect the merged exception change.
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.
Suzy Mueller submitted this change.
src/goDebugConfiguration: use fileWorkspaceFolder in multi root workspace
In multi folder workspaces, it is not allowed to use `${workspaceFolder}`.
If we detect that it is a multi folder workspace, we instead use
`${fileWorkspaceFolder}` which will get the folder of the current open
file.
Fixes golang/vscode-go#1499
Change-Id: Ibbe6e869cb0e5093c1bcd9f55d8f7057bceeed9f
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/319809
Trust: Suzy Mueller <suz...@golang.org>
Run-TryBot: Suzy Mueller <suz...@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hya...@gmail.com>
---
M docs/debugging.md
M src/goDebugConfiguration.ts
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/docs/debugging.md b/docs/debugging.md
index de0ca9c..d800dfd 100644
--- a/docs/debugging.md
+++ b/docs/debugging.md
@@ -69,6 +69,7 @@
* `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: `[]`).
@@ -117,7 +118,7 @@
dlvFlags | Extra flags passed to `dlv`. See `dlv help` for the full list of supported flags. This is useful when users need to pass less commonly used or new flags such as `--only-same-user`, `--check-go-version`. Note that some flags such as `--log-output`, `--log`, `--log-dest`, `--api-version` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.
remotePath | If remote debugging (`mode`: `remote`), this should be the absolute path to the package being debugged on the remote machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant. Becomes the first mapping in substitutePath.
substitutePath | An array of mappings from an absolute local path to an absolute 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. The mappings are applied in order, and the first matching mapping is used. This can be used to map files that have moved since the program was built, different remote paths, and symlinked files or directories. This is intended to be equivalent to the [substitute-path](https://github.com/go-delve/delve/tree/master/Documentation/cli#config) configuration, and will eventually configure substitute-path in Delve directly.
-cwd | The working directory to be used in running the program. If remote debugging (`mode`: `remote`), this should be the absolute path to the working directory being debugged on the local machine. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
+cwd | The working directory to be used in running the program. If remote debugging (`mode`: `remote`), this should be the absolute path to the working directory being debugged on the local machine. The extension defaults to the workspace folder, or the workspace folder of the open file in multi root workspaces. See the section on [Remote Debugging](#remote-debugging) for further details. [golang/vscode-go#45](https://github.com/golang/vscode-go/issues/45) is also relevant.
processId | This is the process ID of the executable you want to debug. Applicable only when using the `attach` request in `local` mode. By setting this to the command name of the process, `${command:pickProcess}`, or`${command:pickGoProcess}` a quick pick menu will show a list of processes to choose from.
### Specifying [build tags](https://golang.org/pkg/go/build/#hdr-Build_Constraints)
@@ -162,7 +163,8 @@
Any property in the launch configuration that requires a file path can be specified in terms of [VS Code variables]. Here are some useful ones to know:
-* `${workspaceFolder}` refers to the root of the workspace opened in VS Code.
+* `${workspaceFolder}` refers to the root of the workspace opened in VS Code. If using a multi root workspace, you must specify the folder name `${workspaceFolder:folderName}`
+* `${fileWorkspaceFolder}` refers to the the current opened file's workspace folder.
* `${file}` refers to the currently opened file.
* `${fileDirname}` refers to the directory containing the currently opened file. This is typically also the name of the Go package containing this file, and as such, can be used to debug the currently opened package.
diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts
index 2923793..ca42792 100644
--- a/src/goDebugConfiguration.ts
+++ b/src/goDebugConfiguration.ts
@@ -188,6 +188,9 @@
}
if (debugConfiguration.request === 'attach' && !debugConfiguration['cwd']) {
debugConfiguration['cwd'] = '${workspaceFolder}';
+ if (vscode.workspace.workspaceFolders?.length > 1) {
+ debugConfiguration['cwd'] = '${fileWorkspaceFolder}';
+ }
}
if (debugConfiguration['cwd']) {
// expand 'cwd' folder path containing '~', which would cause dlv to fail
To view, visit change 319809. To unsubscribe, or for help writing mail filters, visit settings.