Skip to content

Commit c6c97b9

Browse files
committed
tools/generate: generate debug configuration table
Ignores properties whose description fields include 'Not applicable when using `dlv-dap` mode.' Change-Id: Ibc3d9ff44462baaba9c27e7afebd92cc03282e1c Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/328492 Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Suzy Mueller <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
1 parent b2119e2 commit c6c97b9

File tree

2 files changed

+195
-34
lines changed

2 files changed

+195
-34
lines changed

docs/dlv-dap.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,17 @@ $ mv /tmp/dlv $GOPATH/bin/dlv-dap
6464
* Robust `call` evaluation.
6565
* Good test coverage.
6666

67-
6867
Most of all, the new adapter is written in Go and integrated in `dlv`. That will make it easier for the Go community to contribute. </br>
6968
Because it is native, we hope for improvement in speed and reliability.
7069

71-
⚒️ The following features are still under development.
72-
73-
* Pause/restart while the debugged program is running does not work yet.
74-
* Setting breakpoints while the debugged program is running does not work yet.
75-
* `SetVariable` does not work yet.
76-
* `dlvLoadConfig` to configure max string/bytes length in [`"go.delveConfig"`](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#configuration) does not work.
77-
* Traditional [remote debugging](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#remote-debugging) is not supported.
70+
💡 Notes:
7871

79-
Follow along with [golang/vscode-go#23](https://github.com/golang/vscode-go/issues/23) and the [project dashboard](https://github.com/golang/vscode-go/projects/3) for updates on the implementation.
72+
* `dlvLoadConfig` to configure max string/bytes length in [`"go.delveConfig"`](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#configuration) does not work. For large strings, use `DEBUG CONSOLE`, "Copy Value", or hover in editor. The new debug adapter supports [paging of large arrays, bytes, and maps](https://github.com/go-delve/delve/pull/2512#issuecomment-849021775) instead.
73+
* Traditional [remote debugging](https://github.com/golang/vscode-go/blob/master/docs/debugging.md#remote-debugging) is not supported yet (Work-In-Progress).
8074

8175
## Reporting issues
8276

83-
The VS Code Go maintainers are reachable via the issue tracker and the #vscode-dev channel in the Gophers Slack. </br>
77+
The VS Code Go maintainers are reachable via the issue tracker and the `#vscode-dev` channel in the Gophers Slack. </br>
8478
Please reach out on Slack with questions, suggestions, or ideas. If you have trouble getting started on an issue, we'd be happy to give pointers and advice.
8579

8680
When you are having issues in `dlv-dap` mode, first check if the problems are reproducible after updating `dlv-dap`. It's possible that the issues are already fixed. Follow the instruction for [updating dlv-dap](#updating-dlv-dap)) and [updating extension](https://code.visualstudio.com/docs/editor/extension-gallery#_extension-autoupdate).
@@ -92,6 +86,35 @@ Please report issues in [our issue tracker](https://github.com/golang/vscode-go/
9286
* VS Code and VS Code Go version.
9387
* Instruction to reproduce the issue (code snippets, your `launch.json`, screenshot)
9488

89+
## Configuration
90+
<!-- DO NOT EDIT: Auto-generated by go run tools/generate -->
91+
<!-- SETTINGS BEGIN -->
92+
| Property | Launch | Attach |
93+
| --- | --- | --- |
94+
| `args` | Command line arguments passed to the debugged program.<br/> | <center>_n/a_</center> |
95+
| `backend` | Backend used by delve. Maps to `dlv`'s `--backend` flag.<br/><p>Allowed Values: `"default"`, `"native"`, `"lldb"`<br/> | <center>_same as Launch_</center>|
96+
| `buildFlags` | Build flags, to be passed to the Go compiler. Maps to dlv's `--build-flags` flag.<br/>(Default: `""`)<br/> | <center>_n/a_</center> |
97+
| `cwd` | Workspace relative or absolute path to the working directory of the program being debugged if a non-empty value is specified. The `program` folder is used as the working directory if `cwd` is omitted or empty.<br/>(Default: `""`)<br/> | Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.<br/>(Default: `"${workspaceFolder}"`)<br/> |
98+
| `debugAdapter` | Select which debug adapter to use with this launch configuration.<br/><p>Allowed Values: `"legacy"`, `"dlv-dap"`<br/>(Default: `legacy`)<br/> | <center>_same as Launch_</center>|
99+
| `dlvFlags` | Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` 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.<br/> | <center>_same as Launch_</center>|
100+
| `env` | Environment variables passed to the program.<br/> | <center>_n/a_</center> |
101+
| `envFile` | Absolute path to a file containing environment variable definitions. Multiple files can be specified by provided an array of absolute paths<br/>(Default: `${workspaceFolder}/.env`)<br/> | <center>_n/a_</center> |
102+
| `host` | The host name of the machine the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.<br/>(Default: `"127.0.0.1"`)<br/> | <center>_same as Launch_</center>|
103+
| `logDest` | dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only in `dlv-dap` mode, and on Linux and Mac OS.<br/> | dlv's `--log-dest` flag. See `dlv log` for details. Number argument is not allowed. Supported only in `dlv-dap` mode and on Linux and Mac OS.<br/> |
104+
| `logOutput` | Comma separated list of components that should produce debug output. Maps to dlv's `--log-output` flag. Check `dlv log` for details.<br/><p>Allowed Values: `"debugger"`, `"gdbwire"`, `"lldbout"`, `"debuglineerr"`, `"rpc"`, `"dap"`<br/>(Default: `"debugger"`)<br/> | <center>_same as Launch_</center>|
105+
| `mode` | One of `auto`, `debug`, `test`, `exec`. In `auto` mode, the extension will choose either `debug` or `test` depending on active editor window.<br/><p>Allowed Values: `"auto"`, `"debug"`, `"test"`, `"exec"`<br/>(Default: `auto`)<br/> | Indicates local or remote debugging. Local maps to the `dlv attach` command, remote maps to `connect`. `remote` is not supported in `dlv-dap` mode currently. Use `host` and `port` instead.<br/><p>Allowed Values: `"local"`, `"remote"`<br/>(Default: `local`)<br/> |
106+
| `output` | Output path for the binary of the debugee.<br/>(Default: `"debug"`)<br/> | <center>_n/a_</center> |
107+
| `port` | The port that the delve debugger will be listening on. In `dlv-dap` mode, the extension will look for a delve DAP server running on the specified host:port so users are responsible for starting the server.<br/>(Default: `2345`)<br/> | <center>_same as Launch_</center>|
108+
| `processId` | <center>_n/a_</center> | <br/><p><b>Option 1:</b> Use process picker to select a process to attach, or Process ID as integer.<br/><p>Allowed Values: `"${command:pickProcess}"`, `"${command:pickGoProcess}"`<br/><br/><p><b>Option 2:</b> Attach to a process by name. If more than one process matches the name, use the process picker to select a process.<br/><br/><p><b>Option 3:</b> The numeric ID of the process to be debugged. If 0, use the process picker to select a process.<br/><br/>(Default: `0`)<br/> |
109+
| `program` | Path to the program folder (or any go file within that folder) when in `debug` or `test` mode, and to the pre-built binary file to debug in `exec` mode. If it is not an absolute path, the extension interpretes it as a workspace relative path.<br/>(Default: `"${workspaceFolder}"`)<br/> | <center>_n/a_</center> |
110+
| `remotePath` | <center>_n/a_</center> | (Deprecated) *Use `substitutePath` instead.*<br/>The path to the source code on the remote machine, when the remote path is different from the local machine. If specified, becomes the first entry in substitutePath.<br/>(Default: `""`)<br/> |
111+
| `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not.<br/>(Default: `false`)<br/> | <center>_same as Launch_</center>|
112+
| `showLog` | Show log output from the delve debugger. Maps to dlv's `--log` flag.<br/>(Default: `false`)<br/> | <center>_same as Launch_</center>|
113+
| `stackTraceDepth` | Maximum depth of stack trace collected from Delve.<br/>(Default: `50`)<br/> | <center>_same as Launch_</center>|
114+
| `stopOnEntry` | Automatically stop program after launch.<br/>(Default: `false`)<br/> | Automatically stop program after attach.<br/>(Default: `false`)<br/> |
115+
| `substitutePath` | An array of mappings from a local path (editor) to the remote path (debugee). This setting is useful when working in a file system with symbolic links, running remote debugging, or debugging an executable compiled externally. The debug adapter will replace the local path with the remote path in all of the calls.<br/><p><br/><ul><li>`"from"`: The absolute local path to be replaced when passing paths to the debugger.<br/>(Default: `""`)<br/></li><li>`"to"`: The absolute remote path to be replaced when passing paths back to the client.<br/>(Default: `""`)<br/></li></ul><br/> | An array of mappings from a local path (editor) to the remote path (debugee). This setting is useful when working in a file system with symbolic links, running remote debugging, or debugging an executable compiled externally. The debug adapter will replace the local path with the remote path in all of the calls. Overriden by `remotePath`.<br/><p><br/><ul><li>`"from"`: The absolute local path to be replaced when passing paths to the debugger.<br/>(Default: `""`)<br/></li><li>`"to"`: The absolute remote path to be replaced when passing paths back to the client.<br/>(Default: `""`)<br/></li></ul><br/> |
116+
| `trace` | Various levels of logging shown in the debug console & 'Go Debug' output channel. When using the `legacy` debug adapter, the logs will also be written to a file if it is set to a value other than `error`.<br/><p>Allowed Values: `"verbose"`, `"trace"`, `"log"`, `"info"`, `"warn"`, `"error"`<br/>(Default: `"error"`)<br/> | <center>_same as Launch_</center>|
117+
<!-- SETTINGS END -->
95118
## Developing
96119

97120
### Code location

tools/generate.go

Lines changed: 162 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"encoding/json"
1818
"flag"
1919
"fmt"
20+
"io"
2021
"io/ioutil"
2122
"log"
2223
"os"
@@ -36,12 +37,34 @@ var (
3637
debugFlag = flag.Bool("debug", false, "If true, enable extra logging and skip deletion of intermediate files.")
3738
)
3839

40+
func checkAndWrite(filename string, oldContent, newContent []byte) {
41+
// Return early if the contents are unchanged.
42+
if bytes.Equal(oldContent, newContent) {
43+
return
44+
}
45+
46+
// Either write out new contents or report an error (if in CI).
47+
if *writeFlag {
48+
if err := ioutil.WriteFile(filename, newContent, 0644); err != nil {
49+
log.Fatal(err)
50+
}
51+
fmt.Printf("updated %s\n", filename)
52+
} else {
53+
base := filepath.Join("docs", filepath.Base(filename))
54+
fmt.Printf(`%s have changed in the package.json, but documentation in %s was not updated.
55+
To update the settings, run "go run tools/generate.go -w".
56+
`, strings.TrimSuffix(base, ".md"), base)
57+
os.Exit(1) // causes CI to break.
58+
}
59+
}
60+
3961
type PackageJSON struct {
4062
Contributes struct {
4163
Commands []Command `json:"commands,omitempty"`
4264
Configuration struct {
4365
Properties map[string]*Property `json:"properties,omitempty"`
4466
} `json:"configuration,omitempty"`
67+
Debuggers []Debugger `json:"debuggers,omitempty"`
4568
} `json:"contributes,omitempty"`
4669
}
4770

@@ -69,6 +92,19 @@ type Property struct {
6992
Items *Property `json:"items,omitempty"`
7093
}
7194

95+
type Debugger struct {
96+
Type string `json:"type,omitempty"`
97+
Label string `json:"label,omitempty"`
98+
ConfigurationAttributes struct {
99+
Launch Configuration
100+
Attach Configuration
101+
} `json:"configurationAttributes,omitempty"`
102+
}
103+
104+
type Configuration struct {
105+
Properties map[string]*Property `json:"properties,omitempty"`
106+
}
107+
72108
type moduleVersion struct {
73109
Path string `json:",omitempty"`
74110
Version string `json:",omitempty"`
@@ -132,26 +168,9 @@ func main() {
132168
}, []byte("\n\n"))
133169
}
134170
newContent := append(s, '\n')
135-
136-
// Return early if the contents are unchanged.
137-
if bytes.Equal(oldContent, newContent) {
138-
return
139-
}
140-
141-
// Either write out new contents or report an error (if in CI).
142-
if *writeFlag {
143-
if err := ioutil.WriteFile(filename, newContent, 0644); err != nil {
144-
log.Fatal(err)
145-
}
146-
fmt.Printf("updated %s\n", filename)
147-
} else {
148-
base := filepath.Join("docs", filepath.Base(filename))
149-
fmt.Printf(`%s have changed in the package.json, but documentation in %s was not updated.
150-
To update the settings, run "go run tools/generate.go -w".
151-
`, strings.TrimSuffix(base, ".md"), base)
152-
os.Exit(1) // causes CI to break.
153-
}
171+
checkAndWrite(filename, oldContent, newContent)
154172
}
173+
155174
b := &bytes.Buffer{}
156175
for i, c := range pkgJSON.Contributes.Commands {
157176
fmt.Fprintf(b, "### `%s`\n\n%s", c.Title, c.Description)
@@ -199,6 +218,10 @@ To update the settings, run "go run tools/generate.go -w".
199218

200219
rewrite(filepath.Join(dir, "docs", "settings.md"), b.Bytes())
201220

221+
b.Reset()
222+
generateDebugConfigTable(b, pkgJSON)
223+
rewriteDebugDoc(filepath.Join(dir, "docs", "dlv-dap.md"), b.Bytes())
224+
202225
// Only update the latest tool versions if the flag is set.
203226
if !*updateLatestToolVersionsFlag {
204227
return
@@ -336,11 +359,7 @@ func defaultDescriptionSnippet(p *Property) string {
336359
fmt.Fprintf(b, "%v", p.Default)
337360
}
338361
default:
339-
if _, ok := p.Type.([]interface{}); ok {
340-
fmt.Fprintf(b, "%v", p.Default)
341-
break
342-
}
343-
log.Fatalf("implement default when p.Type is %q in %#v %T", p.Type, p, p.Default)
362+
fmt.Fprintf(b, "%v", p.Default)
344363
}
345364
return b.String()
346365
}
@@ -539,3 +558,122 @@ func updateGoplsSettings(oldData []byte, packageJSONFile string, debug bool) (ne
539558
}
540559
return newData, nil
541560
}
561+
562+
func rewriteDebugDoc(filename string, toAdd []byte) {
563+
oldContent, err := ioutil.ReadFile(filename)
564+
if err != nil {
565+
log.Fatal(err)
566+
}
567+
startSep := []byte(`<!-- SETTINGS BEGIN -->`)
568+
endSep := []byte(`<!-- SETTINGS END -->`)
569+
startIdx := bytes.Index(oldContent, startSep)
570+
endIdx := bytes.Index(oldContent, endSep)
571+
if startIdx <= 0 || endIdx <= startIdx {
572+
log.Fatalf("Missing valid SETTINGS BEGIN/END markers in %v", filename)
573+
}
574+
part1 := oldContent[:startIdx+len(startSep)+1]
575+
part3 := oldContent[endIdx:]
576+
577+
newContent := bytes.Join([][]byte{
578+
part1,
579+
toAdd,
580+
part3,
581+
}, []byte{})
582+
checkAndWrite(filename, oldContent, newContent)
583+
}
584+
585+
func generateDebugConfigTable(w io.Writer, pkgJSON *PackageJSON) {
586+
for _, d := range pkgJSON.Contributes.Debuggers {
587+
table := map[string]bool{}
588+
589+
for k := range d.ConfigurationAttributes.Attach.Properties {
590+
table[k] = true
591+
}
592+
for k := range d.ConfigurationAttributes.Launch.Properties {
593+
table[k] = true
594+
}
595+
596+
keys := make([]string, 0, len(table))
597+
for k := range table {
598+
keys = append(keys, k)
599+
}
600+
sort.Strings(keys)
601+
602+
fmt.Fprintln(w, "| Property | Launch | Attach |")
603+
fmt.Fprintln(w, "| --- | --- | --- |")
604+
605+
for _, k := range keys {
606+
launch := describeDebugProperty(d.ConfigurationAttributes.Launch.Properties[k])
607+
attach := describeDebugProperty(d.ConfigurationAttributes.Attach.Properties[k])
608+
609+
if launch != "" && attach != "" {
610+
if launch != attach {
611+
fmt.Fprintf(w, "| `%v` | %v | %v |\n", k, launch, attach)
612+
} else {
613+
fmt.Fprintf(w, "| `%v` | %v | <center>_same as Launch_</center>|\n", k, launch)
614+
}
615+
} else if launch != "" {
616+
fmt.Fprintf(w, "| `%v` | %v | <center>_n/a_</center> |\n", k, launch)
617+
} else if attach != "" {
618+
fmt.Fprintf(w, "| `%v` | <center>_n/a_</center> | %v |\n", k, attach)
619+
}
620+
}
621+
}
622+
}
623+
624+
func describeDebugProperty(p *Property) string {
625+
if p == nil {
626+
return ""
627+
}
628+
b := &bytes.Buffer{}
629+
630+
desc := p.Description
631+
if p.MarkdownDescription != "" {
632+
desc = p.MarkdownDescription
633+
}
634+
if p == nil || strings.Contains(desc, "Not applicable when using `dlv-dap` mode.") {
635+
return ""
636+
}
637+
638+
deprecation := p.DeprecationMessage
639+
if p.MarkdownDeprecationMessage != "" {
640+
deprecation = p.MarkdownDeprecationMessage
641+
}
642+
643+
if deprecation != "" {
644+
fmt.Fprintf(b, "(Deprecated) *%v*<br/>", deprecation)
645+
}
646+
fmt.Fprintf(b, "%v<br/>", desc)
647+
648+
if len(p.AnyOf) > 0 {
649+
for i, a := range p.AnyOf {
650+
fmt.Fprintf(b, "<p><b>Option %d:</b> %v<br/>", i+1, describeDebugProperty(&a))
651+
}
652+
}
653+
654+
if len(p.Enum) > 0 {
655+
var enums []string
656+
for _, i := range p.Enum {
657+
enums = append(enums, fmt.Sprintf("`%#v`", i))
658+
}
659+
fmt.Fprintf(b, "<p>Allowed Values: %v<br/>", strings.Join(enums, ", "))
660+
}
661+
662+
if p.Type == "object" && len(p.Properties) > 0 {
663+
fmt.Fprintf(b, "<ul>")
664+
for k, v := range p.Properties {
665+
fmt.Fprintf(b, "<li>`%q`: %v</li>", k, describeDebugProperty(v))
666+
}
667+
fmt.Fprintf(b, "</ul>")
668+
}
669+
670+
if p.Type == "array" && p.Items != nil && p.Items.Type == "object" {
671+
fmt.Fprintf(b, "<p>%v<br/>", describeDebugProperty(p.Items))
672+
}
673+
674+
// Default
675+
if d := defaultDescriptionSnippet(p); d != "" {
676+
fmt.Fprintf(b, "(Default: `%v`)<br/>", d)
677+
}
678+
return b.String()
679+
}

0 commit comments

Comments
 (0)