[release] tools/goplssetting: handle changes in gopls setting structure

This CL handles the various changes in my current stack of gopls CLs
and it shouldn't be merged until CL 280355 is merged. It handles the
new gopls settings hierarchies, maps keyed by enums, and changes to
default values.

I was struggling to work with the method writing out the lines directly,
so I switched to a JSON struct. This works fine in most cases, except
when writing out the default values. I think gopls should probably
produce interface{} for default values, but that will need to be dealt
with later. For now, I added a relatively basic work-around.

Change-Id: Ie4b69074f1bf02023fa39488ebc1c5c9660a03fc
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/279728
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
(cherry picked from commit de64eaa241f501fbf3c8561bd1380a1349f3105e)
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/282372
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/docs/settings.md b/docs/settings.md
index 5d6b577..15c2ccf 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'"]) This is propagated to the language server if `gopls.buildFlags` is not specified.
+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.build.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. This is propagated to the language server if `gopls.buildFlags` is not specified.
+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.build.buildFlags` is not specified.
 
 Default: ``
 
@@ -576,43 +576,18 @@
 
 Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.
 
-#### `allowImplicitNetworkAccess`
+#### `build.allowImplicitNetworkAccess`
 (Experimental) allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module
 downloads rather than requiring user action. This option will eventually
 be removed.
 
 
-#### `allowModfileModifications`
+#### `build.allowModfileModifications`
 (Experimental) allowModfileModifications disables -mod=readonly, allowing imports from
 out-of-scope modules. This option will eventually be removed.
 
 
-#### `analyses`
-analyses specify analyses that the user would like to enable or disable.
-A map of the names of analysis passes that should be enabled/disabled.
-A full list of analyzers that gopls uses can be found [here](analyzers.md)
-
-Example Usage:
-```json5
-...
-"analyses": {
-  "unreachable": false, // Disable the unreachable analyzer.
-  "unusedparams": true  // Enable the unusedparams analyzer.
-}
-...
-```
-
-
-#### `annotations`
-(Experimental) annotations suppress various kinds of optimization diagnostics
-that would be reported by the gc_details command.
- * noNilcheck suppresses display of nilchecks.
- * noEscape suppresses escape choices.
- * noInline suppresses inlining choices.
- * noBounds suppresses bounds checking diagnostics.
-
-
-#### `buildFlags`
+#### `build.buildFlags`
 buildFlags is the set of flags passed on to the build system when invoked.
 It is applied to queries like `go list`, which is used when discovering files.
 The most common use is to set `-tags`.
@@ -620,32 +595,7 @@
 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"
-section of settings.md for the list of supported lenses.
-
-Example Usage:
-```json5
-"gopls": {
-...
-  "codelens": {
-    "generate": false,  // Don't show the `go generate` lens.
-    "gc_details": true  // Show a code lens toggling the display of gc's choices.
-  }
-...
-}
-```
-
-
-#### `completionBudget`
-(For Debugging) completionBudget is the soft latency goal for completion requests. Most
-requests finish in a couple milliseconds, but in some cases deep
-completions can take much longer. As we use up our budget we
-dynamically reduce the search scope to ensure we return timely
-results. Zero means unlimited.
-
-
-#### `directoryFilters`
+#### `build.directoryFilters`
 directoryFilters can be used to exclude unwanted directories from the
 workspace. By default, all directories are included. Filters are an
 operator, `+` to include and `-` to exclude, followed by a path prefix
@@ -659,11 +609,11 @@
 Include only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`
 
 
-#### `env`
+#### `build.env`
 env adds environment variables to external commands run by `gopls`, most notably `go list`.
 
 
-#### `expandWorkspaceToModule`
+#### `build.expandWorkspaceToModule`
 (Experimental) expandWorkspaceToModule instructs `gopls` to adjust the scope of the
 workspace to find the best available module root. `gopls` first looks for
 a go.mod file in any parent directory of the workspace folder, expanding
@@ -672,16 +622,7 @@
 a go.mod file, narrowing the scope to that directory if it exists.
 
 
-#### `experimentalDiagnosticsDelay`
-(Experimental) experimentalDiagnosticsDelay controls the amount of time that gopls waits
-after the most recent file modification before computing deep diagnostics.
-Simple diagnostics (parsing and type-checking) are always run immediately
-on recently modified packages.
-
-This option must be set to a valid duration string, for example `"250ms"`.
-
-
-#### `experimentalPackageCacheKey`
+#### `build.experimentalPackageCacheKey`
 (Experimental) experimentalPackageCacheKey controls whether to use a coarser cache key
 for package type information to increase cache hits. This setting removes
 the user's environment, build flags, and working directory from the cache
@@ -691,26 +632,102 @@
 comprehensively test.
 
 
-#### `experimentalWorkspaceModule`
+#### `build.experimentalWorkspaceModule`
 (Experimental) experimentalWorkspaceModule opts a user into the experimental support
 for multi-module workspaces.
 
 
-#### `gofumpt`
+#### `formatting.gofumpt`
 gofumpt indicates if we should run gofumpt formatting.
 
 
-#### `hoverKind`
+#### `formatting.local`
+local is the equivalent of the `goimports -local` flag, which puts
+imports beginning with this string after third-party packages. It should
+be the prefix of the import path whose imports should be grouped
+separately.
+
+
+#### `ui.codelenses`
+codelenses overrides the enabled/disabled state of code lenses. See the
+"Code Lenses" section of the
+[Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md)
+for the list of supported lenses.
+
+Example Usage:
+
+```json5
+"gopls": {
+...
+  "codelens": {
+    "generate": false,  // Don't show the `go generate` lens.
+    "gc_details": true  // Show a code lens toggling the display of gc's choices.
+  }
+...
+}
+```
+
+
+#### `ui.completion.completionBudget`
+(For Debugging) completionBudget is the soft latency goal for completion requests. Most
+requests finish in a couple milliseconds, but in some cases deep
+completions can take much longer. As we use up our budget we
+dynamically reduce the search scope to ensure we return timely
+results. Zero means unlimited.
+
+
+#### `ui.completion.matcher`
+(Advanced) matcher sets the algorithm that is used when calculating completion
+candidates.
+
+
+#### `ui.completion.usePlaceholders`
+placeholders enables placeholders for function parameters or struct
+fields in completion responses.
+
+
+#### `ui.diagnostic.analyses`
+analyses specify analyses that the user would like to enable or disable.
+A map of the names of analysis passes that should be enabled/disabled.
+A full list of analyzers that gopls uses can be found
+[here](https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md).
+
+Example Usage:
+
+```json5
+...
+"analyses": {
+  "unreachable": false, // Disable the unreachable analyzer.
+  "unusedparams": true  // Enable the unusedparams analyzer.
+}
+...
+```
+
+
+#### `ui.diagnostic.annotations`
+(Experimental) annotations specifies the various kinds of optimization diagnostics
+that should be reported by the gc_details command.
+
+
+#### `ui.diagnostic.experimentalDiagnosticsDelay`
+(Experimental) experimentalDiagnosticsDelay controls the amount of time that gopls waits
+after the most recent file modification before computing deep diagnostics.
+Simple diagnostics (parsing and type-checking) are always run immediately
+on recently modified packages.
+
+This option must be set to a valid duration string, for example `"250ms"`.
+
+
+#### `ui.diagnostic.staticcheck`
+(Experimental) staticcheck enables additional analyses from staticcheck.io.
+
+
+#### `ui.documentation.hoverKind`
 hoverKind controls the information that appears in the hover text.
 SingleLine and Structured are intended for use only by authors of editor plugins.
 
 
-#### `importShortcut`
-importShortcut specifies whether import statements should link to
-documentation or go to definitions.
-
-
-#### `linkTarget`
+#### `ui.documentation.linkTarget`
 linkTarget controls where documentation links go.
 It might be one of:
 
@@ -720,36 +737,24 @@
 If company chooses to use its own `godoc.org`, its address can be used as well.
 
 
-#### `linksInHover`
+#### `ui.documentation.linksInHover`
 linksInHover toggles the presence of links to documentation in hover.
 
 
-#### `local`
-local is the equivalent of the `goimports -local` flag, which puts imports beginning with this string after 3rd-party packages.
-It should be the prefix of the import path whose imports should be grouped separately.
+#### `ui.navigation.importShortcut`
+importShortcut specifies whether import statements should link to
+documentation or go to definitions.
 
 
-#### `matcher`
-matcher sets the algorithm that is used when calculating completion candidates.
+#### `ui.navigation.symbolMatcher`
+(Advanced) symbolMatcher sets the algorithm that is used when finding workspace symbols.
 
 
-#### `semanticTokens`
-(Experimental) semanticTokens controls whether the LSP server will send
-semantic tokens to the client.
-
-
-#### `staticcheck`
-(Experimental) staticcheck enables additional analyses from staticcheck.io.
-
-
-#### `symbolMatcher`
-symbolMatcher sets the algorithm that is used when finding workspace symbols.
-
-
-#### `symbolStyle`
-symbolStyle controls how symbols are qualified in symbol responses.
+#### `ui.navigation.symbolStyle`
+(Advanced) symbolStyle controls how symbols are qualified in symbol responses.
 
 Example Usage:
+
 ```json5
 "gopls": {
 ...
@@ -759,8 +764,9 @@
 ```
 
 
-#### `usePlaceholders`
-placeholders enables placeholders for function parameters or struct fields in completion responses.
+#### `ui.semanticTokens`
+(Experimental) semanticTokens controls whether the LSP server will send
+semantic tokens to the client.
 
 
 #### `verboseOutput`
diff --git a/package.json b/package.json
index 6597929..0a68a9a 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'\"]) This is propagated to the language server if `gopls.buildFlags` is not specified.",
+          "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.build.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. This is propagated to the language server if `gopls.buildFlags` is not specified.",
+          "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.build.buildFlags` is not specified.",
           "scope": "resource"
         },
         "go.testTags": {
@@ -1689,21 +1689,376 @@
           "type": "object",
           "markdownDescription": "Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.",
           "scope": "resource",
-          "additionalProperties": false,
           "properties": {
-            "buildFlags": {
+            "build.allowImplicitNetworkAccess": {
+              "type": "boolean",
+              "markdownDescription": "(Experimental) allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module\ndownloads rather than requiring user action. This option will eventually\nbe removed.\n",
+              "default": false,
+              "scope": "resource"
+            },
+            "build.allowModfileModifications": {
+              "type": "boolean",
+              "markdownDescription": "(Experimental) allowModfileModifications disables -mod=readonly, allowing imports from\nout-of-scope modules. This option will eventually be removed.\n",
+              "default": false,
+              "scope": "resource"
+            },
+            "build.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\nIf unspecified, values of `go.buildFlags, go.buildTags` will be propagated.\n",
-              "default": [],
               "scope": "resource"
             },
-            "env": {
+            "build.directoryFilters": {
+              "type": "array",
+              "markdownDescription": "directoryFilters can be used to exclude unwanted directories from the\nworkspace. By default, all directories are included. Filters are an\noperator, `+` to include and `-` to exclude, followed by a path prefix\nrelative to the workspace folder. They are evaluated in order, and\nthe last filter that applies to a path controls whether it is included.\nThe path prefix can be empty, so an initial `-` excludes everything.\n\nExamples:\nExclude node_modules: `-node_modules`\nInclude only project_a: `-` (exclude everything), `+project_a`\nInclude only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`\n",
+              "scope": "resource"
+            },
+            "build.env": {
               "type": "object",
               "markdownDescription": "env adds environment variables to external commands run by `gopls`, most notably `go list`.\n",
-              "default": {},
               "scope": "resource"
             },
-            "hoverKind": {
+            "build.expandWorkspaceToModule": {
+              "type": "boolean",
+              "markdownDescription": "(Experimental) expandWorkspaceToModule instructs `gopls` to adjust the scope of the\nworkspace to find the best available module root. `gopls` first looks for\na go.mod file in any parent directory of the workspace folder, expanding\nthe scope to that directory if it exists. If no viable parent directory is\nfound, gopls will check if there is exactly one child directory containing\na go.mod file, narrowing the scope to that directory if it exists.\n",
+              "default": true,
+              "scope": "resource"
+            },
+            "build.experimentalPackageCacheKey": {
+              "type": "boolean",
+              "markdownDescription": "(Experimental) experimentalPackageCacheKey controls whether to use a coarser cache key\nfor package type information to increase cache hits. This setting removes\nthe user's environment, build flags, and working directory from the cache\nkey, which should be a safe change as all relevant inputs into the type\nchecking pass are already hashed into the key. This is temporarily guarded\nby an experiment because caching behavior is subtle and difficult to\ncomprehensively test.\n",
+              "default": true,
+              "scope": "resource"
+            },
+            "build.experimentalWorkspaceModule": {
+              "type": "boolean",
+              "markdownDescription": "(Experimental) experimentalWorkspaceModule opts a user into the experimental support\nfor multi-module workspaces.\n",
+              "default": false,
+              "scope": "resource"
+            },
+            "formatting.gofumpt": {
+              "type": "boolean",
+              "markdownDescription": "gofumpt indicates if we should run gofumpt formatting.\n",
+              "default": false,
+              "scope": "resource"
+            },
+            "formatting.local": {
+              "type": "string",
+              "markdownDescription": "local is the equivalent of the `goimports -local` flag, which puts\nimports beginning with this string after third-party packages. It should\nbe the prefix of the import path whose imports should be grouped\nseparately.\n",
+              "default": "",
+              "scope": "resource"
+            },
+            "ui.codelenses": {
+              "type": "object",
+              "markdownDescription": "codelenses overrides the enabled/disabled state of code lenses. See the\n\"Code Lenses\" section of the\n[Settings page](https://github.com/golang/tools/blob/master/gopls/doc/settings.md)\nfor the list of supported lenses.\n\nExample Usage:\n\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",
+              "scope": "resource",
+              "properties": {
+                "gc_details": {
+                  "type": "boolean",
+                  "markdownDescription": "gc_details controls calculation of gc annotations.\n",
+                  "default": false
+                },
+                "generate": {
+                  "type": "boolean",
+                  "markdownDescription": "generate runs `go generate` for a given directory.\n",
+                  "default": true
+                },
+                "regenerate_cgo": {
+                  "type": "boolean",
+                  "markdownDescription": "regenerate_cgo regenerates cgo definitions.\n",
+                  "default": true
+                },
+                "test": {
+                  "type": "boolean",
+                  "markdownDescription": "test runs `go test` for a specific test function.\n",
+                  "default": false
+                },
+                "tidy": {
+                  "type": "boolean",
+                  "markdownDescription": "tidy runs `go mod tidy` for a module.\n",
+                  "default": true
+                },
+                "upgrade_dependency": {
+                  "type": "boolean",
+                  "markdownDescription": "upgrade_dependency upgrades a dependency.\n",
+                  "default": true
+                },
+                "vendor": {
+                  "type": "boolean",
+                  "markdownDescription": "vendor runs `go mod vendor` for a module.\n",
+                  "default": true
+                }
+              }
+            },
+            "ui.completion.completionBudget": {
+              "type": "string",
+              "markdownDescription": "(For Debugging) completionBudget is the soft latency goal for completion requests. Most\nrequests finish in a couple milliseconds, but in some cases deep\ncompletions can take much longer. As we use up our budget we\ndynamically reduce the search scope to ensure we return timely\nresults. Zero means unlimited.\n",
+              "default": "100ms",
+              "scope": "resource"
+            },
+            "ui.completion.matcher": {
+              "type": "string",
+              "markdownDescription": "(Advanced) matcher sets the algorithm that is used when calculating completion\ncandidates.\n",
+              "enum": [
+                "CaseInsensitive",
+                "CaseSensitive",
+                "Fuzzy"
+              ],
+              "markdownEnumDescriptions": [
+                "",
+                "",
+                ""
+              ],
+              "default": "Fuzzy",
+              "scope": "resource"
+            },
+            "ui.completion.usePlaceholders": {
+              "type": "boolean",
+              "markdownDescription": "placeholders enables placeholders for function parameters or struct\nfields in completion responses.\n",
+              "default": false,
+              "scope": "resource"
+            },
+            "ui.diagnostic.analyses": {
+              "type": "object",
+              "markdownDescription": "analyses specify analyses that the user would like to enable or disable.\nA map of the names of analysis passes that should be enabled/disabled.\nA full list of analyzers that gopls uses can be found\n[here](https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md).\n\nExample Usage:\n\n```json5\n...\n\"analyses\": {\n  \"unreachable\": false, // Disable the unreachable analyzer.\n  \"unusedparams\": true  // Enable the unusedparams analyzer.\n}\n...\n```\n",
+              "scope": "resource",
+              "properties": {
+                "asmdecl": {
+                  "type": "boolean",
+                  "markdownDescription": "report mismatches between assembly files and Go declarations",
+                  "default": true
+                },
+                "assign": {
+                  "type": "boolean",
+                  "markdownDescription": "check for useless assignments\n\nThis checker reports assignments of the form x = x or a[i] = a[i].\nThese are almost always useless, and even when they aren't they are\nusually a mistake.",
+                  "default": true
+                },
+                "atomic": {
+                  "type": "boolean",
+                  "markdownDescription": "check for common mistakes using the sync/atomic package\n\nThe atomic checker looks for assignment statements of the form:\n\n\tx = atomic.AddUint64(&x, 1)\n\nwhich are not atomic.",
+                  "default": true
+                },
+                "atomicalign": {
+                  "type": "boolean",
+                  "markdownDescription": "check for non-64-bits-aligned arguments to sync/atomic functions",
+                  "default": true
+                },
+                "bools": {
+                  "type": "boolean",
+                  "markdownDescription": "check for common mistakes involving boolean operators",
+                  "default": true
+                },
+                "buildtag": {
+                  "type": "boolean",
+                  "markdownDescription": "check that +build tags are well-formed and correctly located",
+                  "default": true
+                },
+                "cgocall": {
+                  "type": "boolean",
+                  "markdownDescription": "detect some violations of the cgo pointer passing rules\n\nCheck for invalid cgo pointer passing.\nThis looks for code that uses cgo to call C code passing values\nwhose types are almost always invalid according to the cgo pointer\nsharing rules.\nSpecifically, it warns about attempts to pass a Go chan, map, func,\nor slice to C, either directly, or via a pointer, array, or struct.",
+                  "default": true
+                },
+                "composites": {
+                  "type": "boolean",
+                  "markdownDescription": "check for unkeyed composite literals\n\nThis analyzer reports a diagnostic for composite literals of struct\ntypes imported from another package that do not use the field-keyed\nsyntax. Such literals are fragile because the addition of a new field\n(even if unexported) to the struct will cause compilation to fail.\n\nAs an example,\n\n\terr = &net.DNSConfigError{err}\n\nshould be replaced by:\n\n\terr = &net.DNSConfigError{Err: err}\n",
+                  "default": true
+                },
+                "copylocks": {
+                  "type": "boolean",
+                  "markdownDescription": "check for locks erroneously passed by value\n\nInadvertently copying a value containing a lock, such as sync.Mutex or\nsync.WaitGroup, may cause both copies to malfunction. Generally such\nvalues should be referred to through a pointer.",
+                  "default": true
+                },
+                "deepequalerrors": {
+                  "type": "boolean",
+                  "markdownDescription": "check for calls of reflect.DeepEqual on error values\n\nThe deepequalerrors checker looks for calls of the form:\n\n    reflect.DeepEqual(err1, err2)\n\nwhere err1 and err2 are errors. Using reflect.DeepEqual to compare\nerrors is discouraged.",
+                  "default": true
+                },
+                "errorsas": {
+                  "type": "boolean",
+                  "markdownDescription": "report passing non-pointer or non-error values to errors.As\n\nThe errorsas analysis reports calls to errors.As where the type\nof the second argument is not a pointer to a type implementing error.",
+                  "default": true
+                },
+                "fieldalignment": {
+                  "type": "boolean",
+                  "markdownDescription": "find structs that would take less memory if their fields were sorted\n\nThis analyzer find structs that can be rearranged to take less memory, and provides\na suggested edit with the optimal order.\n",
+                  "default": false
+                },
+                "fillreturns": {
+                  "type": "boolean",
+                  "markdownDescription": "suggested fixes for \"wrong number of return values (want %d, got %d)\"\n\nThis checker provides suggested fixes for type errors of the\ntype \"wrong number of return values (want %d, got %d)\". For example:\n\tfunc m() (int, string, *bool, error) {\n\t\treturn\n\t}\nwill turn into\n\tfunc m() (int, string, *bool, error) {\n\t\treturn 0, \"\", nil, nil\n\t}\n\nThis functionality is similar to https://github.com/sqs/goreturns.\n",
+                  "default": true
+                },
+                "fillstruct": {
+                  "type": "boolean",
+                  "markdownDescription": "note incomplete struct initializations\n\nThis analyzer provides diagnostics for any struct literals that do not have\nany fields initialized. Because the suggested fix for this analysis is\nexpensive to compute, callers should compute it separately, using the\nSuggestedFix function below.\n",
+                  "default": true
+                },
+                "httpresponse": {
+                  "type": "boolean",
+                  "markdownDescription": "check for mistakes using HTTP responses\n\nA common mistake when using the net/http package is to defer a function\ncall to close the http.Response Body before checking the error that\ndetermines whether the response is valid:\n\n\tresp, err := http.Head(url)\n\tdefer resp.Body.Close()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// (defer statement belongs here)\n\nThis checker helps uncover latent nil dereference bugs by reporting a\ndiagnostic for such mistakes.",
+                  "default": true
+                },
+                "ifaceassert": {
+                  "type": "boolean",
+                  "markdownDescription": "detect impossible interface-to-interface type assertions\n\nThis checker flags type assertions v.(T) and corresponding type-switch cases\nin which the static type V of v is an interface that cannot possibly implement\nthe target interface T. This occurs when V and T contain methods with the same\nname but different signatures. Example:\n\n\tvar v interface {\n\t\tRead()\n\t}\n\t_ = v.(io.Reader)\n\nThe Read method in v has a different signature than the Read method in\nio.Reader, so this assertion cannot succeed.\n",
+                  "default": true
+                },
+                "loopclosure": {
+                  "type": "boolean",
+                  "markdownDescription": "check references to loop variables from within nested functions\n\nThis analyzer checks for references to loop variables from within a\nfunction literal inside the loop body. It checks only instances where\nthe function literal is called in a defer or go statement that is the\nlast statement in the loop body, as otherwise we would need whole\nprogram analysis.\n\nFor example:\n\n\tfor i, v := range s {\n\t\tgo func() {\n\t\t\tprintln(i, v) // not what you might expect\n\t\t}()\n\t}\n\nSee: https://golang.org/doc/go_faq.html#closures_and_goroutines",
+                  "default": true
+                },
+                "lostcancel": {
+                  "type": "boolean",
+                  "markdownDescription": "check cancel func returned by context.WithCancel is called\n\nThe cancellation function returned by context.WithCancel, WithTimeout,\nand WithDeadline must be called or the new context will remain live\nuntil its parent context is cancelled.\n(The background context is never cancelled.)",
+                  "default": true
+                },
+                "nilfunc": {
+                  "type": "boolean",
+                  "markdownDescription": "check for useless comparisons between functions and nil\n\nA useless comparison is one like f == nil as opposed to f() == nil.",
+                  "default": true
+                },
+                "nonewvars": {
+                  "type": "boolean",
+                  "markdownDescription": "suggested fixes for \"no new vars on left side of :=\"\n\nThis checker provides suggested fixes for type errors of the\ntype \"no new vars on left side of :=\". For example:\n\tz := 1\n\tz := 2\nwill turn into\n\tz := 1\n\tz = 2\n",
+                  "default": true
+                },
+                "noresultvalues": {
+                  "type": "boolean",
+                  "markdownDescription": "suggested fixes for \"no result values expected\"\n\nThis checker provides suggested fixes for type errors of the\ntype \"no result values expected\". For example:\n\tfunc z() { return nil }\nwill turn into\n\tfunc z() { return }\n",
+                  "default": true
+                },
+                "printf": {
+                  "type": "boolean",
+                  "markdownDescription": "check consistency of Printf format strings and arguments\n\nThe check applies to known functions (for example, those in package fmt)\nas well as any detected wrappers of known functions.\n\nA function that wants to avail itself of printf checking but is not\nfound by this analyzer's heuristics (for example, due to use of\ndynamic calls) can insert a bogus call:\n\n\tif false {\n\t\t_ = fmt.Sprintf(format, args...) // enable printf checking\n\t}\n\nThe -funcs flag specifies a comma-separated list of names of additional\nknown formatting functions or methods. If the name contains a period,\nit must denote a specific function using one of the following forms:\n\n\tdir/pkg.Function\n\tdir/pkg.Type.Method\n\t(*dir/pkg.Type).Method\n\nOtherwise the name is interpreted as a case-insensitive unqualified\nidentifier such as \"errorf\". Either way, if a listed name ends in f, the\nfunction is assumed to be Printf-like, taking a format string before the\nargument list. Otherwise it is assumed to be Print-like, taking a list\nof arguments with no format string.\n",
+                  "default": true
+                },
+                "shadow": {
+                  "type": "boolean",
+                  "markdownDescription": "check for possible unintended shadowing of variables\n\nThis analyzer check for shadowed variables.\nA shadowed variable is a variable declared in an inner scope\nwith the same name and type as a variable in an outer scope,\nand where the outer variable is mentioned after the inner one\nis declared.\n\n(This definition can be refined; the module generates too many\nfalse positives and is not yet enabled by default.)\n\nFor example:\n\n\tfunc BadRead(f *os.File, buf []byte) error {\n\t\tvar err error\n\t\tfor {\n\t\t\tn, err := f.Read(buf) // shadows the function variable 'err'\n\t\t\tif err != nil {\n\t\t\t\tbreak // causes return of wrong value\n\t\t\t}\n\t\t\tfoo(buf)\n\t\t}\n\t\treturn err\n\t}\n",
+                  "default": false
+                },
+                "shift": {
+                  "type": "boolean",
+                  "markdownDescription": "check for shifts that equal or exceed the width of the integer",
+                  "default": true
+                },
+                "simplifycompositelit": {
+                  "type": "boolean",
+                  "markdownDescription": "check for composite literal simplifications\n\nAn array, slice, or map composite literal of the form:\n\t[]T{T{}, T{}}\nwill be simplified to:\n\t[]T{{}, {}}\n\nThis is one of the simplifications that \"gofmt -s\" applies.",
+                  "default": true
+                },
+                "simplifyrange": {
+                  "type": "boolean",
+                  "markdownDescription": "check for range statement simplifications\n\nA range of the form:\n\tfor x, _ = range v {...}\nwill be simplified to:\n\tfor x = range v {...}\n\nA range of the form:\n\tfor _ = range v {...}\nwill be simplified to:\n\tfor range v {...}\n\nThis is one of the simplifications that \"gofmt -s\" applies.",
+                  "default": true
+                },
+                "simplifyslice": {
+                  "type": "boolean",
+                  "markdownDescription": "check for slice simplifications\n\nA slice expression of the form:\n\ts[a:len(s)]\nwill be simplified to:\n\ts[a:]\n\nThis is one of the simplifications that \"gofmt -s\" applies.",
+                  "default": true
+                },
+                "sortslice": {
+                  "type": "boolean",
+                  "markdownDescription": "check the argument type of sort.Slice\n\nsort.Slice requires an argument of a slice type. Check that\nthe interface{} value passed to sort.Slice is actually a slice.",
+                  "default": true
+                },
+                "stdmethods": {
+                  "type": "boolean",
+                  "markdownDescription": "check signature of methods of well-known interfaces\n\nSometimes a type may be intended to satisfy an interface but may fail to\ndo so because of a mistake in its method signature.\nFor example, the result of this WriteTo method should be (int64, error),\nnot error, to satisfy io.WriterTo:\n\n\ttype myWriterTo struct{...}\n        func (myWriterTo) WriteTo(w io.Writer) error { ... }\n\nThis check ensures that each method whose name matches one of several\nwell-known interface methods from the standard library has the correct\nsignature for that interface.\n\nChecked method names include:\n\tFormat GobEncode GobDecode MarshalJSON MarshalXML\n\tPeek ReadByte ReadFrom ReadRune Scan Seek\n\tUnmarshalJSON UnreadByte UnreadRune WriteByte\n\tWriteTo\n",
+                  "default": true
+                },
+                "stringintconv": {
+                  "type": "boolean",
+                  "markdownDescription": "check for string(int) conversions\n\nThis checker flags conversions of the form string(x) where x is an integer\n(but not byte or rune) type. Such conversions are discouraged because they\nreturn the UTF-8 representation of the Unicode code point x, and not a decimal\nstring representation of x as one might expect. Furthermore, if x denotes an\ninvalid code point, the conversion cannot be statically rejected.\n\nFor conversions that intend on using the code point, consider replacing them\nwith string(rune(x)). Otherwise, strconv.Itoa and its equivalents return the\nstring representation of the value in the desired base.\n",
+                  "default": true
+                },
+                "structtag": {
+                  "type": "boolean",
+                  "markdownDescription": "check that struct field tags conform to reflect.StructTag.Get\n\nAlso report certain struct tags (json, xml) used with unexported fields.",
+                  "default": true
+                },
+                "testinggoroutine": {
+                  "type": "boolean",
+                  "markdownDescription": "report calls to (*testing.T).Fatal from goroutines started by a test.\n\nFunctions that abruptly terminate a test, such as the Fatal, Fatalf, FailNow, and\nSkip{,f,Now} methods of *testing.T, must be called from the test goroutine itself.\nThis checker detects calls to these functions that occur within a goroutine\nstarted by the test. For example:\n\nfunc TestFoo(t *testing.T) {\n    go func() {\n        t.Fatal(\"oops\") // error: (*T).Fatal called from non-test goroutine\n    }()\n}\n",
+                  "default": true
+                },
+                "tests": {
+                  "type": "boolean",
+                  "markdownDescription": "check for common mistaken usages of tests and examples\n\nThe tests checker walks Test, Benchmark and Example functions checking\nmalformed names, wrong signatures and examples documenting non-existent\nidentifiers.\n\nPlease see the documentation for package testing in golang.org/pkg/testing\nfor the conventions that are enforced for Tests, Benchmarks, and Examples.",
+                  "default": true
+                },
+                "undeclaredname": {
+                  "type": "boolean",
+                  "markdownDescription": "suggested fixes for \"undeclared name: <>\"\n\nThis checker provides suggested fixes for type errors of the\ntype \"undeclared name: <>\". It will insert a new statement:\n\"<> := \".",
+                  "default": true
+                },
+                "unmarshal": {
+                  "type": "boolean",
+                  "markdownDescription": "report passing non-pointer or non-interface values to unmarshal\n\nThe unmarshal analysis reports calls to functions such as json.Unmarshal\nin which the argument type is not a pointer or an interface.",
+                  "default": true
+                },
+                "unreachable": {
+                  "type": "boolean",
+                  "markdownDescription": "check for unreachable code\n\nThe unreachable analyzer finds statements that execution can never reach\nbecause they are preceded by an return statement, a call to panic, an\ninfinite loop, or similar constructs.",
+                  "default": true
+                },
+                "unsafeptr": {
+                  "type": "boolean",
+                  "markdownDescription": "check for invalid conversions of uintptr to unsafe.Pointer\n\nThe unsafeptr analyzer reports likely incorrect uses of unsafe.Pointer\nto convert integers to pointers. A conversion from uintptr to\nunsafe.Pointer is invalid if it implies that there is a uintptr-typed\nword in memory that holds a pointer value, because that word will be\ninvisible to stack copying and to the garbage collector.",
+                  "default": true
+                },
+                "unusedparams": {
+                  "type": "boolean",
+                  "markdownDescription": "check for unused parameters of functions\n\nThe unusedparams analyzer checks functions to see if there are\nany parameters that are not being used.\n\nTo reduce false positives it ignores:\n- methods\n- parameters that do not have a name or are underscored\n- functions in test files\n- functions with empty bodies or those with just a return stmt",
+                  "default": false
+                },
+                "unusedresult": {
+                  "type": "boolean",
+                  "markdownDescription": "check for unused results of calls to some functions\n\nSome functions like fmt.Errorf return a result and have no side effects,\nso it is always a mistake to discard the result. This analyzer reports\ncalls to certain functions in which the result of the call is ignored.\n\nThe set of functions may be controlled using flags.",
+                  "default": true
+                }
+              }
+            },
+            "ui.diagnostic.annotations": {
+              "type": "object",
+              "markdownDescription": "(Experimental) annotations specifies the various kinds of optimization diagnostics\nthat should be reported by the gc_details command.\n",
+              "scope": "resource",
+              "properties": {
+                "bounds": {
+                  "type": "boolean",
+                  "markdownDescription": "`\"bounds\"` controls bounds checking diagnostics.\n",
+                  "default": true
+                },
+                "escape": {
+                  "type": "boolean",
+                  "markdownDescription": "`\"escape\"` controls diagnostics about escape choices.\n",
+                  "default": true
+                },
+                "inline": {
+                  "type": "boolean",
+                  "markdownDescription": "`\"inline\"` controls diagnostics about inlining choices.\n",
+                  "default": true
+                },
+                "nil": {
+                  "type": "boolean",
+                  "markdownDescription": "`\"nil\"` controls nil checks.\n",
+                  "default": true
+                }
+              }
+            },
+            "ui.diagnostic.experimentalDiagnosticsDelay": {
+              "type": "string",
+              "markdownDescription": "(Experimental) experimentalDiagnosticsDelay controls the amount of time that gopls waits\nafter the most recent file modification before computing deep diagnostics.\nSimple diagnostics (parsing and type-checking) are always run immediately\non recently modified packages.\n\nThis option must be set to a valid duration string, for example `\"250ms\"`.\n",
+              "default": "250ms",
+              "scope": "resource"
+            },
+            "ui.diagnostic.staticcheck": {
+              "type": "boolean",
+              "markdownDescription": "(Experimental) staticcheck enables additional analyses from staticcheck.io.\n",
+              "default": false,
+              "scope": "resource"
+            },
+            "ui.documentation.hoverKind": {
               "type": "string",
               "markdownDescription": "hoverKind controls the information that appears in the hover text.\nSingleLine and Structured are intended for use only by authors of editor plugins.\n",
               "enum": [
@@ -1723,56 +2078,19 @@
               "default": "FullDocumentation",
               "scope": "resource"
             },
-            "usePlaceholders": {
-              "type": "boolean",
-              "markdownDescription": "placeholders enables placeholders for function parameters or struct fields in completion responses.\n",
-              "default": false,
-              "scope": "resource"
-            },
-            "linkTarget": {
+            "ui.documentation.linkTarget": {
               "type": "string",
               "markdownDescription": "linkTarget controls where documentation links go.\nIt might be one of:\n\n* `\"godoc.org\"`\n* `\"pkg.go.dev\"`\n\nIf company chooses to use its own `godoc.org`, its address can be used as well.\n",
               "default": "pkg.go.dev",
               "scope": "resource"
             },
-            "local": {
-              "type": "string",
-              "markdownDescription": "local is the equivalent of the `goimports -local` flag, which puts imports beginning with this string after 3rd-party packages.\nIt should be the prefix of the import path whose imports should be grouped separately.\n",
-              "default": "",
-              "scope": "resource"
-            },
-            "gofumpt": {
-              "type": "boolean",
-              "markdownDescription": "gofumpt indicates if we should run gofumpt formatting.\n",
-              "default": false,
-              "scope": "resource"
-            },
-            "analyses": {
-              "type": "object",
-              "markdownDescription": "analyses specify analyses that the user would like to enable or disable.\nA map of the names of analysis passes that should be enabled/disabled.\nA full list of analyzers that gopls uses can be found [here](analyzers.md)\n\nExample Usage:\n```json5\n...\n\"analyses\": {\n  \"unreachable\": false, // Disable the unreachable analyzer.\n  \"unusedparams\": true  // Enable the unusedparams analyzer.\n}\n...\n```\n",
-              "default": {},
-              "scope": "resource"
-            },
-            "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  \"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,
-                "regenerate_cgo": true,
-                "tidy": true,
-                "upgrade_dependency": true,
-                "vendor": true
-              },
-              "scope": "resource"
-            },
-            "linksInHover": {
+            "ui.documentation.linksInHover": {
               "type": "boolean",
               "markdownDescription": "linksInHover toggles the presence of links to documentation in hover.\n",
               "default": true,
               "scope": "resource"
             },
-            "importShortcut": {
+            "ui.navigation.importShortcut": {
               "type": "string",
               "markdownDescription": "importShortcut specifies whether import statements should link to\ndocumentation or go to definitions.\n",
               "enum": [
@@ -1788,9 +2106,9 @@
               "default": "Both",
               "scope": "resource"
             },
-            "matcher": {
+            "ui.navigation.symbolMatcher": {
               "type": "string",
-              "markdownDescription": "matcher sets the algorithm that is used when calculating completion candidates.\n",
+              "markdownDescription": "(Advanced) symbolMatcher sets the algorithm that is used when finding workspace symbols.\n",
               "enum": [
                 "CaseInsensitive",
                 "CaseSensitive",
@@ -1804,25 +2122,9 @@
               "default": "Fuzzy",
               "scope": "resource"
             },
-            "symbolMatcher": {
+            "ui.navigation.symbolStyle": {
               "type": "string",
-              "markdownDescription": "symbolMatcher sets the algorithm that is used when finding workspace symbols.\n",
-              "enum": [
-                "CaseInsensitive",
-                "CaseSensitive",
-                "Fuzzy"
-              ],
-              "markdownEnumDescriptions": [
-                "",
-                "",
-                ""
-              ],
-              "default": "Fuzzy",
-              "scope": "resource"
-            },
-            "symbolStyle": {
-              "type": "string",
-              "markdownDescription": "symbolStyle controls how symbols are qualified in symbol responses.\n\nExample Usage:\n```json5\n\"gopls\": {\n...\n  \"symbolStyle\": \"dynamic\",\n...\n}\n```\n",
+              "markdownDescription": "(Advanced) symbolStyle controls how symbols are qualified in symbol responses.\n\nExample Usage:\n\n```json5\n\"gopls\": {\n...\n  \"symbolStyle\": \"dynamic\",\n...\n}\n```\n",
               "enum": [
                 "Dynamic",
                 "Full",
@@ -1836,77 +2138,17 @@
               "default": "Dynamic",
               "scope": "resource"
             },
-            "directoryFilters": {
-              "type": "array",
-              "markdownDescription": "directoryFilters can be used to exclude unwanted directories from the\nworkspace. By default, all directories are included. Filters are an\noperator, `+` to include and `-` to exclude, followed by a path prefix\nrelative to the workspace folder. They are evaluated in order, and\nthe last filter that applies to a path controls whether it is included.\nThe path prefix can be empty, so an initial `-` excludes everything.\n\nExamples:\nExclude node_modules: `-node_modules`\nInclude only project_a: `-` (exclude everything), `+project_a`\nInclude only project_a, but not node_modules inside it: `-`, `+project_a`, `-project_a/node_modules`\n",
-              "default": [],
-              "scope": "resource"
-            },
-            "annotations": {
-              "type": "object",
-              "markdownDescription": "(Experimental) annotations suppress various kinds of optimization diagnostics\nthat would be reported by the gc_details command.\n * noNilcheck suppresses display of nilchecks.\n * noEscape suppresses escape choices.\n * noInline suppresses inlining choices.\n * noBounds suppresses bounds checking diagnostics.\n",
-              "default": {},
-              "scope": "resource"
-            },
-            "staticcheck": {
-              "type": "boolean",
-              "markdownDescription": "(Experimental) staticcheck enables additional analyses from staticcheck.io.\n",
-              "default": false,
-              "scope": "resource"
-            },
-            "semanticTokens": {
+            "ui.semanticTokens": {
               "type": "boolean",
               "markdownDescription": "(Experimental) semanticTokens controls whether the LSP server will send\nsemantic tokens to the client.\n",
               "default": false,
               "scope": "resource"
             },
-            "expandWorkspaceToModule": {
-              "type": "boolean",
-              "markdownDescription": "(Experimental) expandWorkspaceToModule instructs `gopls` to adjust the scope of the\nworkspace to find the best available module root. `gopls` first looks for\na go.mod file in any parent directory of the workspace folder, expanding\nthe scope to that directory if it exists. If no viable parent directory is\nfound, gopls will check if there is exactly one child directory containing\na go.mod file, narrowing the scope to that directory if it exists.\n",
-              "default": true,
-              "scope": "resource"
-            },
-            "experimentalWorkspaceModule": {
-              "type": "boolean",
-              "markdownDescription": "(Experimental) experimentalWorkspaceModule opts a user into the experimental support\nfor multi-module workspaces.\n",
-              "default": false,
-              "scope": "resource"
-            },
-            "experimentalDiagnosticsDelay": {
-              "type": "string",
-              "markdownDescription": "(Experimental) experimentalDiagnosticsDelay controls the amount of time that gopls waits\nafter the most recent file modification before computing deep diagnostics.\nSimple diagnostics (parsing and type-checking) are always run immediately\non recently modified packages.\n\nThis option must be set to a valid duration string, for example `\"250ms\"`.\n",
-              "default": "250ms",
-              "scope": "resource"
-            },
-            "experimentalPackageCacheKey": {
-              "type": "boolean",
-              "markdownDescription": "(Experimental) experimentalPackageCacheKey controls whether to use a coarser cache key\nfor package type information to increase cache hits. This setting removes\nthe user's environment, build flags, and working directory from the cache\nkey, which should be a safe change as all relevant inputs into the type\nchecking pass are already hashed into the key. This is temporarily guarded\nby an experiment because caching behavior is subtle and difficult to\ncomprehensively test.\n",
-              "default": true,
-              "scope": "resource"
-            },
-            "allowModfileModifications": {
-              "type": "boolean",
-              "markdownDescription": "(Experimental) allowModfileModifications disables -mod=readonly, allowing imports from\nout-of-scope modules. This option will eventually be removed.\n",
-              "default": false,
-              "scope": "resource"
-            },
-            "allowImplicitNetworkAccess": {
-              "type": "boolean",
-              "markdownDescription": "(Experimental) allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module\ndownloads rather than requiring user action. This option will eventually\nbe removed.\n",
-              "default": false,
-              "scope": "resource"
-            },
             "verboseOutput": {
               "type": "boolean",
               "markdownDescription": "(For Debugging) verboseOutput enables additional debug logging.\n",
               "default": false,
               "scope": "resource"
-            },
-            "completionBudget": {
-              "type": "string",
-              "markdownDescription": "(For Debugging) completionBudget is the soft latency goal for completion requests. Most\nrequests finish in a couple milliseconds, but in some cases deep\ncompletions can take much longer. As we use up our budget we\ndynamically reduce the search scope to ensure we return timely\nresults. Zero means unlimited.\n",
-              "default": "100ms",
-              "scope": "resource"
             }
           }
         }
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 9d4db9d..e34a462 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -52,7 +52,7 @@
 import { outputChannel, updateLanguageServerIconGoStatusBar } from './goStatus';
 import { GoCompletionItemProvider } from './goSuggest';
 import { GoWorkspaceSymbolProvider } from './goSymbol';
-import { getTool, Tool, ToolAtVersion } from './goTools';
+import { getTool, Tool } from './goTools';
 import { GoTypeDefinitionProvider } from './goTypeDefinition';
 import { getFromGlobalState, updateGlobalState } from './stateUtils';
 import {
@@ -552,7 +552,7 @@
 // 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
+//   - go.buildTags and go.buildFlags are passed as gopls.build.buildFlags
 //     if goplsWorkspaceConfig doesn't explicitly set it yet.
 // Exported for testing.
 export function passGoConfigToGoplsConfigValues(goplsWorkspaceConfig: any, goWorkspaceConfig: any): any {
@@ -560,18 +560,16 @@
 		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;
-		}
+	const buildFlags = [] as string[];
+	if (goWorkspaceConfig?.buildFlags) {
+		buildFlags.push(...goWorkspaceConfig?.buildFlags);
+	}
+	if (goWorkspaceConfig?.buildTags && buildFlags.indexOf('-tags') === -1) {
+		buildFlags.push('-tags', goWorkspaceConfig?.buildTags);
+	}
+	// If gopls.build.buildFlags is set, don't touch it.
+	if (buildFlags.length > 0 && goplsWorkspaceConfig['build.buildFlags'] === undefined) {
+		goplsWorkspaceConfig['build.buildFlags'] = buildFlags;
 	}
 	return goplsWorkspaceConfig;
 }
diff --git a/test/gopls/configuration.test.ts b/test/gopls/configuration.test.ts
index 5d68043..daccdfb 100644
--- a/test/gopls/configuration.test.ts
+++ b/test/gopls/configuration.test.ts
@@ -103,13 +103,13 @@
 				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']}
+				want: { 'build.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']}
+				want: { 'build.buildFlags': ['-tags', 'tag1,tag2'] }
 			},
 			{
 				name: 'do not pass go config buildTags if buildFlags already have tags',
@@ -118,34 +118,35 @@
 					buildFlags: ['-tags', 'tag0'],
 					buildTags: 'tag1,tag2'
 				},
-				want: { buildFlags: ['-tags', 'tag0']}
+				want: { 'build.buildFlags': ['-tags', 'tag0'] }
 			},
 			{
 				name: 'do not mutate other gopls config but gopls.buildFlags',
 				goplsConfig: {
-					env: {GOPROXY: 'direct'}
+					'build.env': { GOPROXY: 'direct' }
 				},
 				goConfig: { buildFlags: ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw'] },
 				want: {
-					env: { GOPROXY : 'direct' },
-					buildFlags: ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw']}
+					'build.env': { GOPROXY: 'direct' },
+					'build.buildFlags': ['-modfile', 'gopls.mod', '-tags', 'tag1,tag2', '-modcacherw']
+				}
 			},
 
 			{
 				name: 'do not mutate misconfigured gopls.buildFlags',
 				goplsConfig: {
-					buildFlags: '-modfile gopls.mod',  // misconfiguration
+					'build.buildFlags': '-modfile gopls.mod',  // misconfiguration
 				},
 				goConfig: {
 					buildFlags: '-modfile go.mod -tags tag1 -modcacherw',
 				},
-				want: { buildFlags: '-modfile gopls.mod' }
+				want: { 'build.buildFlags': '-modfile gopls.mod' }
 			},
 			{
 				name: 'do not overwrite gopls config if it is explicitly set',
 				goplsConfig: {
-					env: {GOPROXY: 'direct'},
-					buildFlags: [],  // empty
+					'build.env': { GOPROXY: 'direct' },
+					'build.buildFlags': [],  // empty
 				},
 				goConfig: {
 					// expect only non-conflicting flags (tags, modcacherw) passing.
@@ -153,8 +154,8 @@
 					buildTags: 'tag3',
 				},
 				want: {
-					env: {GOPROXY: 'direct'},
-					buildFlags: [],
+					'build.env': { GOPROXY: 'direct' },
+					'build.buildFlags': [],
 				}  // gopls.buildFlags untouched.
 			},
 
diff --git a/tools/generate.go b/tools/generate.go
index 940d1eb..3352f7c 100644
--- a/tools/generate.go
+++ b/tools/generate.go
@@ -3,6 +3,8 @@
 // See LICENSE in the project root for license information.
 
 // Command generate is used to generate documentation from the package.json.
+// To run:
+// go run tools/generate.go -w
 package main
 
 import (
@@ -100,6 +102,7 @@
 		} else {
 			base := filepath.Join("docs", filepath.Base(filename))
 			fmt.Printf(`%s have changed in the package.json, but documentation in %s was not updated.
+To update the settings, run "go run tools/generate.go -w".
 `, strings.TrimSuffix(base, ".md"), base)
 			os.Exit(1) // causes CI to break.
 		}
@@ -156,7 +159,7 @@
 					keys = append(keys, k)
 				}
 				sort.Strings(keys)
-				b.WriteString(fmt.Sprintf("\n\nDefault:{<br/>\n"))
+				b.WriteString("\n\nDefault:{<br/>\n")
 				for _, k := range keys {
 					v := x[k]
 					output := fmt.Sprintf("%v", v)
diff --git a/tools/goplssetting/main.go b/tools/goplssetting/main.go
index e10955f..fc465ba 100644
--- a/tools/goplssetting/main.go
+++ b/tools/goplssetting/main.go
@@ -5,7 +5,7 @@
 // This command updates the gopls.* configurations in vscode-go package.json.
 //
 //   Usage: from the project root directory,
-//      $ go run tools/goplssetting -in ./package.json -out ./package.json
+//      $ go run tools/goplssetting/main.go -in ./package.json -out ./package.json
 package main
 
 import (
@@ -13,12 +13,12 @@
 	"encoding/json"
 	"flag"
 	"fmt"
-	"io"
 	"io/ioutil"
 	"log"
 	"os"
 	"os/exec"
 	"sort"
+	"strconv"
 	"strings"
 )
 
@@ -68,19 +68,21 @@
 	if err != nil {
 		return nil, err
 	}
-
 	options, err := extractOptions(api)
 	if err != nil {
 		return nil, err
 	}
-
+	b, err := asVSCodeSettings(options)
+	if err != nil {
+		return nil, err
+	}
 	f, err := ioutil.TempFile(workDir, "gopls.settings")
 	if err != nil {
 		return nil, err
 	}
-
-	writeAsVSCodeSettings(f, options)
-
+	if _, err := f.Write(b); err != nil {
+		return nil, err
+	}
 	if err := f.Close(); err != nil {
 		return nil, err
 	}
@@ -122,12 +124,17 @@
 		}
 	}
 	sort.SliceStable(options, func(i, j int) bool {
-		return priority(options[i].section) < priority(options[j].section)
+		pi := priority(options[i].OptionJSON)
+		pj := priority(options[j].OptionJSON)
+		if pi == pj {
+			return options[i].Name < options[j].Name
+		}
+		return pi < pj
 	})
 
 	opts := []*OptionJSON{}
 	for _, v := range options {
-		if name := sectionName(v.section); name != "" {
+		if name := statusName(v.OptionJSON); name != "" {
 			v.OptionJSON.Doc = name + " " + v.OptionJSON.Doc
 		}
 		opts = append(opts, v.OptionJSON)
@@ -135,28 +142,43 @@
 	return opts, nil
 }
 
-func priority(section string) int {
-	switch section {
-	case "User":
-		return 0
-	case "Experimental":
+func priority(opt *OptionJSON) int {
+	switch toStatus(opt.Status) {
+	case Experimental:
 		return 10
-	case "Debugging":
+	case Debug:
 		return 100
 	}
 	return 1000
 }
 
-func sectionName(section string) string {
-	switch section {
-	case "Experimental":
+func statusName(opt *OptionJSON) string {
+	switch toStatus(opt.Status) {
+	case Experimental:
 		return "(Experimental)"
-	case "Debugging":
+	case Advanced:
+		return "(Advanced)"
+	case Debug:
 		return "(For Debugging)"
 	}
 	return ""
 }
 
+func toStatus(s string) Status {
+	switch s {
+	case "experimental":
+		return Experimental
+	case "debug":
+		return Debug
+	case "advanced":
+		return Advanced
+	case "":
+		return None
+	default:
+		panic(fmt.Sprintf("unexpected status: %s", s))
+	}
+}
+
 // rewritePackageJSON rewrites the input package.json by running `jq`
 // to update all existing gopls settings with the ones from the newSettings
 // file.
@@ -173,65 +195,138 @@
 	return stdout.Bytes(), nil
 }
 
-// convertToVSCodeSettings converts the options to the vscode setting format.
-func writeAsVSCodeSettings(f io.Writer, options []*OptionJSON) {
-	line := func(format string, args ...interface{}) {
-		fmt.Fprintf(f, format, args...)
-		fmt.Fprintln(f)
+// asVSCodeSettings converts the given options to match the VS Code settings
+// format.
+func asVSCodeSettings(options []*OptionJSON) ([]byte, error) {
+	seen := map[string][]*OptionJSON{}
+	for _, opt := range options {
+		seen[opt.Hierarchy] = append(seen[opt.Hierarchy], opt)
 	}
+	for _, v := range seen {
+		sort.Slice(v, func(i, j int) bool {
+			return v[i].Name < v[j].Name
+		})
+	}
+	properties, err := collectProperties(seen)
+	if err != nil {
+		return nil, err
+	}
+	return json.Marshal(map[string]*Object{
+		"gopls": {
+			Type:                 "object",
+			MarkdownDescription:  "Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.",
+			Scope:                "resource",
+			AdditionalProperties: false,
+			Properties:           properties,
+		},
+	})
+}
 
-	line(`{`)
-	line(`"gopls": {`)
-	line(`    "type": "object",`)
-	line(`    "markdownDescription": "Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.",`)
-	line(`    "scope": "resource",`)
-	line(`    "additionalProperties": false,`)
-	line(`    "properties": {`)
-	for i, o := range options {
-		line(`    "%v" : {`, o.Name)
-
-		typ := propertyType(o.Type)
-		line(`      "type": %q,`, typ)
-		// TODO: consider 'additionalProperties' if gopls api-json outputs acceptable peoperties.
-
-		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, ", "))
+func collectProperties(m map[string][]*OptionJSON) (map[string]*Object, error) {
+	var sorted []string
+	var containsEmpty bool
+	for k := range m {
+		if k == "" {
+			containsEmpty = true
+			continue
 		}
-		line(`      "markdownDescription": %q,`, doc)
+		sorted = append(sorted, k)
+	}
+	sort.Strings(sorted)
+	if containsEmpty {
+		sorted = append(sorted, "")
+	}
+	properties := map[string]*Object{}
+	for _, hierarchy := range sorted {
+		for _, opt := range m[hierarchy] {
+			doc := opt.Doc
+			if mappedTo, ok := associatedToExtensionProperties[opt.Name]; ok {
+				doc = fmt.Sprintf("%v\nIf unspecified, values of `%v` will be propagated.\n", doc, strings.Join(mappedTo, ", "))
+			}
+			obj := &Object{
+				MarkdownDescription: doc,
+				// TODO: are all gopls settings in the resource scope?
+				Scope: "resource",
+				// TODO: consider 'additionalProperties' if gopls api-json
+				// outputs acceptable properties.
+				// TODO: deprecation attribute
+			}
+			// Handle any enum types.
+			if opt.Type == "enum" {
+				for _, v := range opt.EnumValues {
+					unquotedName, err := strconv.Unquote(v.Value)
+					if err != nil {
+						return nil, err
+					}
+					obj.Enum = append(obj.Enum, unquotedName)
+					obj.MarkdownEnumDescriptions = append(obj.MarkdownEnumDescriptions, v.Doc)
+				}
+			}
+			// Handle any objects whose keys are enums.
+			if len(opt.EnumKeys.Keys) > 0 {
+				if obj.Properties == nil {
+					obj.Properties = map[string]*Object{}
+				}
+				for _, k := range opt.EnumKeys.Keys {
+					unquotedName, err := strconv.Unquote(k.Name)
+					if err != nil {
+						return nil, err
+					}
+					obj.Properties[unquotedName] = &Object{
+						Type:                propertyType(opt.EnumKeys.ValueType),
+						MarkdownDescription: k.Doc,
+						Default:             formatDefault(k.Default),
+					}
+				}
+			}
+			obj.Type = propertyType(opt.Type)
+			obj.Default = formatOptionDefault(opt)
 
-		var enums, enumDocs []string
-		for _, v := range o.EnumValues {
-			enums = append(enums, v.Value)
-			enumDocs = append(enumDocs, fmt.Sprintf("%q", v.Doc))
-		}
-		if len(enums) > 0 {
-			line(`      "enum": [%v],`, strings.Join(enums, ","))
-			line(`      "markdownEnumDescriptions": [%v],`, strings.Join(enumDocs, ","))
-		}
-
-		if len(o.Default) > 0 {
-			line(`      "default": %v,`, o.Default)
-		}
-
-		// TODO: are all gopls settings in the resource scope?
-		line(`      "scope": "resource"`)
-		// TODO: deprecation attribute
-
-		// "%v" : {
-		if i == len(options)-1 {
-			line(`    }`)
-		} else {
-			line(`    },`)
+			key := opt.Name
+			if hierarchy != "" {
+				key = hierarchy + "." + key
+			}
+			properties[key] = obj
 		}
 	}
-	line(`    }`) //  "properties": {
-	line(`  }`)   // "gopls": {
-	line(`}`)     // {
+	return properties, nil
+}
+
+func formatOptionDefault(opt *OptionJSON) interface{} {
+	// Each key will have its own default value, instead of one large global
+	// one. (Alternatively, we can build the default from the keys.)
+	if len(opt.EnumKeys.Keys) > 0 {
+		return nil
+	}
+	def := opt.Default
+	switch opt.Type {
+	case "enum", "string", "time.Duration":
+		unquote, err := strconv.Unquote(def)
+		if err == nil {
+			def = unquote
+		}
+	}
+	return formatDefault(def)
+}
+
+// formatDefault converts a string-based default value to an actual value that
+// can be marshaled to JSON. Right now, gopls generates default values as
+// strings, but perhaps that will change.
+func formatDefault(def string) interface{} {
+	switch def {
+	case "{}", "[]":
+		return nil
+	case "true":
+		return true
+	case "false":
+		return false
+	default:
+		return def
+	}
 }
 
 var associatedToExtensionProperties = map[string][]string{
-	"buildFlags": []string{"go.buildFlags", "go.buildTags"},
+	"buildFlags": {"go.buildFlags", "go.buildTags"},
 }
 
 func propertyType(t string) string {
@@ -262,20 +357,56 @@
 	os.Exit(1)
 }
 
+// Object represents a VS Code settings object.
+type Object struct {
+	Type                     string             `json:"type,omitempty"`
+	MarkdownDescription      string             `json:"markdownDescription,omitempty"`
+	AdditionalProperties     bool               `json:"additionalProperties,omitempty"`
+	Enum                     []string           `json:"enum,omitempty"`
+	MarkdownEnumDescriptions []string           `json:"markdownEnumDescriptions,omitempty"`
+	Default                  interface{}        `json:"default,omitempty"`
+	Scope                    string             `json:"scope,omitempty"`
+	Properties               map[string]*Object `json:"properties,omitempty"`
+}
+
+type Status int
+
+const (
+	Experimental = Status(iota)
+	Debug
+	Advanced
+	None
+)
+
 // APIJSON is the output json type of `gopls api-json`.
 // Types copied from golang.org/x/tools/internal/lsp/source/options.go.
 type APIJSON struct {
-	Options  map[string][]*OptionJSON
-	Commands []*CommandJSON
-	Lenses   []*LensJSON
+	Options   map[string][]*OptionJSON
+	Commands  []*CommandJSON
+	Lenses    []*LensJSON
+	Analyzers []*AnalyzerJSON
 }
 
 type OptionJSON struct {
 	Name       string
 	Type       string
 	Doc        string
+	EnumKeys   EnumKeys
 	EnumValues []EnumValue
 	Default    string
+	Status     string
+	Hierarchy  string
+}
+
+type EnumKeys struct {
+	ValueType string
+	Keys      []EnumKey
+}
+
+type EnumKey struct {
+	Name    string
+	Doc     string
+	Default string
 }
 
 type EnumValue struct {
@@ -294,3 +425,9 @@
 	Title string
 	Doc   string
 }
+
+type AnalyzerJSON struct {
+	Name    string
+	Doc     string
+	Default bool
+}
diff --git a/tools/goplssetting/main_test.go b/tools/goplssetting/main_test.go
index a135f2c..7147347 100644
--- a/tools/goplssetting/main_test.go
+++ b/tools/goplssetting/main_test.go
@@ -60,7 +60,6 @@
 			},
 			out: `"completionBudget": {
 					"type": "string",
-					"markdownDescription": "",
 					"default": "100ms",
 					"scope": "resource"
 				}`,
@@ -74,10 +73,8 @@
 			},
 			out: `"analyses":{
 					"type": "object",
-					"markdownDescription": "",
-					"default": {},
 					"scope": "resource"
-		  		}`,
+				}`,
 		},
 		{
 			name: "enum",
@@ -102,7 +99,6 @@
 			},
 			out: `"matcher": {
  					"type": "string",
-					"markdownDescription": "",
 					"enum": [ "CaseInsensitive", "CaseSensitive", "Fuzzy" ],
 					"markdownEnumDescriptions": [ "","","" ],
 					"default": "Fuzzy",
@@ -114,15 +110,16 @@
 	for _, tc := range testCases {
 		t.Run(tc.name, func(t *testing.T) {
 			options := []*OptionJSON{tc.in}
-			buf := &bytes.Buffer{}
-			writeAsVSCodeSettings(buf, options)
-			if got, want := normalize(t, buf.String()), normalize(t, `
-			{ 
+			b, err := asVSCodeSettings(options)
+			if err != nil {
+				t.Fatal(err)
+			}
+			if got, want := normalize(t, string(b)), normalize(t, `
+			{
 				"gopls": {
 					"type": "object",
 					"markdownDescription": "Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.",
 					"scope": "resource",
-					"additionalProperties": false,
 					"properties": {
 				       `+tc.out+`
 					}