package.json: embed autogenerated gopls settings

Gopls v0.5.4-pre.1

Generated by `go run ./tools/goplssetting -in ./package.json -out ./package.json

Changes in src/goLanguageServer.ts are to filter out the
setting values that came from the default values and send only
the properties users have explicitly specified. Gopls will honor
the default upon receiving empty, omitted properties, so this will
help us avoid version-skew issues when gopls versions used to
auto-generate vscode-go settings and used by users do not match.

Fixes golang/vscode-go#197

Change-Id: I3e1e42ba7d64dcd271cdb48713168bbfce16730b
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/270803
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
diff --git a/docs/settings.md b/docs/settings.md
index a6c533d..e86556e 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -414,3 +414,301 @@
 Allowed Values:`[package workspace off]`
 
 Default: `package`
+
+### `gopls.analyses`
+
+(Experimental) 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.
+}
+...
+```
+
+
+### `gopls.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.
+
+
+### `gopls.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`.
+
+
+### `gopls.codelens`
+
+(Experimental) codelens 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.
+  }
+...
+}
+```
+
+
+Default:{<br/>
+&nbsp;&nbsp;`"gc_details": false`,<br/>
+&nbsp;&nbsp;`"generate": true`,<br/>
+&nbsp;&nbsp;`"regenerate_cgo": true`,<br/>
+&nbsp;&nbsp;`"tidy": true`,<br/>
+&nbsp;&nbsp;`"upgrade_dependency": true`,<br/>
+&nbsp;&nbsp;`"vendor": true`,<br/>
+    }
+
+
+### `gopls.completeUnimported`
+
+(Experimental) completeUnimported enables completion for packages that you do not currently import.
+
+
+Default: `true`
+
+### `gopls.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.
+
+
+Default: `100ms`
+
+### `gopls.completionDocumentation`
+
+(Experimental) completionDocumentation enables documentation with completion results.
+
+
+Default: `true`
+
+### `gopls.deepCompletion`
+
+(Experimental) deepCompletion enables the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones.
+
+Consider this example:
+
+```go
+package main
+
+import "fmt"
+
+type wrapString struct {
+    str string
+}
+
+func main() {
+    x := wrapString{"hello world"}
+    fmt.Printf(<>)
+}
+```
+
+At the location of the `<>` in this program, deep completion would suggest the result `x.str`.
+
+
+Default: `true`
+
+### `gopls.env`
+
+env adds environment variables to external commands run by `gopls`, most notably `go list`.
+
+
+### `gopls.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
+the scope to that directory if it exists. If no viable parent directory is
+found, gopls will check if there is exactly one child directory containing
+a go.mod file, narrowing the scope to that directory if it exists.
+
+
+Default: `true`
+
+### `gopls.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"`.
+
+
+Default: `0s`
+
+### `gopls.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
+key, which should be a safe change as all relevant inputs into the type
+checking pass are already hashed into the key. This is temporarily guarded
+by an experiment because caching behavior is subtle and difficult to
+comprehensively test.
+
+
+Default: `true`
+
+### `gopls.experimentalWorkspaceModule`
+
+(Experimental) experimentalWorkspaceModule opts a user into the experimental support
+for multi-module workspaces.
+
+
+Default: `false`
+
+### `gopls.gofumpt`
+
+gofumpt indicates if we should run gofumpt formatting.
+
+
+Default: `false`
+
+### `gopls.hoverKind`
+
+hoverKind controls the information that appears in the hover text.
+SingleLine and Structured are intended for use only by authors of editor plugins.
+
+
+Allowed Values:`[FullDocumentation NoDocumentation SingleLine Structured SynopsisDocumentation]`
+
+Default: `FullDocumentation`
+
+### `gopls.importShortcut`
+
+(Experimental) importShortcut specifies whether import statements should link to
+documentation or go to definitions.
+
+
+Allowed Values:`[Both Definition Link]`
+
+Default: `Both`
+
+### `gopls.linkTarget`
+
+linkTarget controls where documentation links go.
+It might be one of:
+
+* `"godoc.org"`
+* `"pkg.go.dev"`
+
+If company chooses to use its own `godoc.org`, its address can be used as well.
+
+
+Default: `pkg.go.dev`
+
+### `gopls.linksInHover`
+
+(Experimental) linksInHover toggles the presence of links to documentation in hover.
+
+
+Default: `true`
+
+### `gopls.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.
+
+
+Default: ``
+
+### `gopls.matcher`
+
+(Experimental) matcher sets the algorithm that is used when calculating completion candidates.
+
+
+Allowed Values:`[CaseInsensitive CaseSensitive Fuzzy]`
+
+Default: `Fuzzy`
+
+### `gopls.semanticTokens`
+
+(Experimental) semanticTokens controls whether the LSP server will send
+semantic tokens to the client.
+
+
+Default: `false`
+
+### `gopls.staticcheck`
+
+(Experimental) staticcheck enables additional analyses from staticcheck.io.
+
+
+Default: `false`
+
+### `gopls.symbolMatcher`
+
+(Experimental) symbolMatcher sets the algorithm that is used when finding workspace symbols.
+
+
+Allowed Values:`[CaseInsensitive CaseSensitive Fuzzy]`
+
+Default: `Fuzzy`
+
+### `gopls.symbolStyle`
+
+(Experimental) symbolStyle controls how symbols are qualified in symbol responses.
+
+Example Usage:
+```json5
+"gopls": {
+...
+  "symbolStyle": "dynamic",
+...
+}
+```
+
+
+Allowed Values:`[Dynamic Full Package]`
+
+Default: `Package`
+
+### `gopls.tempModfile`
+
+(Experimental) tempModfile controls the use of the -modfile flag in Go 1.14.
+
+
+Default: `true`
+
+### `gopls.usePlaceholders`
+
+placeholders enables placeholders for function parameters or struct fields in completion responses.
+
+
+Default: `false`
+
+### `gopls.verboseOutput`
+
+(For Debugging) verboseOutput enables additional debug logging.
+
+
+Default: `false`
+
+### `gopls.verboseWorkDoneProgress`
+
+(Experimental) verboseWorkDoneProgress controls whether the LSP server should send
+progress reports for all work done outside the scope of an RPC.
+
+
+Default: `false`
diff --git a/package.json b/package.json
index 1890bdb..d4130c5 100644
--- a/package.json
+++ b/package.json
@@ -2002,6 +2002,235 @@
             }
           },
           "additionalProperties": true
+        },
+        "gopls.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",
+          "default": [],
+          "scope": "resource"
+        },
+        "gopls.env": {
+          "type": "object",
+          "markdownDescription": "env adds environment variables to external commands run by `gopls`, most notably `go list`.\n",
+          "default": {},
+          "scope": "resource"
+        },
+        "gopls.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": [
+            "FullDocumentation",
+            "NoDocumentation",
+            "SingleLine",
+            "Structured",
+            "SynopsisDocumentation"
+          ],
+          "markdownEnumDescriptions": [
+            "",
+            "",
+            "",
+            "`\"Structured\"` is an experimental setting that returns a structured hover format.\nThis format separates the signature from the documentation, so that the client\ncan do more manipulation of these fields.\n\nThis should only be used by clients that support this behavior.\n",
+            ""
+          ],
+          "default": "FullDocumentation",
+          "scope": "resource"
+        },
+        "gopls.usePlaceholders": {
+          "type": "boolean",
+          "markdownDescription": "placeholders enables placeholders for function parameters or struct fields in completion responses.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.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"
+        },
+        "gopls.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"
+        },
+        "gopls.gofumpt": {
+          "type": "boolean",
+          "markdownDescription": "gofumpt indicates if we should run gofumpt formatting.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.analyses": {
+          "type": "object",
+          "markdownDescription": "(Experimental) 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"
+        },
+        "gopls.codelens": {
+          "type": "object",
+          "markdownDescription": "(Experimental) codelens 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"
+        },
+        "gopls.completionDocumentation": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) completionDocumentation enables documentation with completion results.\n",
+          "default": true,
+          "scope": "resource"
+        },
+        "gopls.completeUnimported": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) completeUnimported enables completion for packages that you do not currently import.\n",
+          "default": true,
+          "scope": "resource"
+        },
+        "gopls.deepCompletion": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) deepCompletion enables the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones.\n\nConsider this example:\n\n```go\npackage main\n\nimport \"fmt\"\n\ntype wrapString struct {\n    str string\n}\n\nfunc main() {\n    x := wrapString{\"hello world\"}\n    fmt.Printf(<>)\n}\n```\n\nAt the location of the `<>` in this program, deep completion would suggest the result `x.str`.\n",
+          "default": true,
+          "scope": "resource"
+        },
+        "gopls.matcher": {
+          "type": "string",
+          "markdownDescription": "(Experimental) matcher sets the algorithm that is used when calculating completion candidates.\n",
+          "enum": [
+            "CaseInsensitive",
+            "CaseSensitive",
+            "Fuzzy"
+          ],
+          "markdownEnumDescriptions": [
+            "",
+            "",
+            ""
+          ],
+          "default": "Fuzzy",
+          "scope": "resource"
+        },
+        "gopls.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"
+        },
+        "gopls.staticcheck": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) staticcheck enables additional analyses from staticcheck.io.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.symbolMatcher": {
+          "type": "string",
+          "markdownDescription": "(Experimental) symbolMatcher sets the algorithm that is used when finding workspace symbols.\n",
+          "enum": [
+            "CaseInsensitive",
+            "CaseSensitive",
+            "Fuzzy"
+          ],
+          "markdownEnumDescriptions": [
+            "",
+            "",
+            ""
+          ],
+          "default": "Fuzzy",
+          "scope": "resource"
+        },
+        "gopls.symbolStyle": {
+          "type": "string",
+          "markdownDescription": "(Experimental) symbolStyle controls how symbols are qualified in symbol responses.\n\nExample Usage:\n```json5\n\"gopls\": {\n...\n  \"symbolStyle\": \"dynamic\",\n...\n}\n```\n",
+          "enum": [
+            "Dynamic",
+            "Full",
+            "Package"
+          ],
+          "markdownEnumDescriptions": [
+            "`\"Dynamic\"` uses whichever qualifier results in the highest scoring\nmatch for the given symbol query. Here a \"qualifier\" is any \"/\" or \".\"\ndelimited suffix of the fully qualified symbol. i.e. \"to/pkg.Foo.Field\" or\njust \"Foo.Field\".\n",
+            "`\"Full\"` is fully qualified symbols, i.e.\n\"path/to/pkg.Foo.Field\".\n",
+            "`\"Package\"` is package qualified symbols i.e.\n\"pkg.Foo.Field\".\n"
+          ],
+          "default": "Package",
+          "scope": "resource"
+        },
+        "gopls.linksInHover": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) linksInHover toggles the presence of links to documentation in hover.\n",
+          "default": true,
+          "scope": "resource"
+        },
+        "gopls.tempModfile": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) tempModfile controls the use of the -modfile flag in Go 1.14.\n",
+          "default": true,
+          "scope": "resource"
+        },
+        "gopls.importShortcut": {
+          "type": "string",
+          "markdownDescription": "(Experimental) importShortcut specifies whether import statements should link to\ndocumentation or go to definitions.\n",
+          "enum": [
+            "Both",
+            "Definition",
+            "Link"
+          ],
+          "markdownEnumDescriptions": [
+            "",
+            "",
+            ""
+          ],
+          "default": "Both",
+          "scope": "resource"
+        },
+        "gopls.verboseWorkDoneProgress": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) verboseWorkDoneProgress controls whether the LSP server should send\nprogress reports for all work done outside the scope of an RPC.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.semanticTokens": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) semanticTokens controls whether the LSP server will send\nsemantic tokens to the client.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.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"
+        },
+        "gopls.experimentalWorkspaceModule": {
+          "type": "boolean",
+          "markdownDescription": "(Experimental) experimentalWorkspaceModule opts a user into the experimental support\nfor multi-module workspaces.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.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": "0s",
+          "scope": "resource"
+        },
+        "gopls.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"
+        },
+        "gopls.verboseOutput": {
+          "type": "boolean",
+          "markdownDescription": "(For Debugging) verboseOutput enables additional debug logging.\n",
+          "default": false,
+          "scope": "resource"
+        },
+        "gopls.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 763097c..f62fa4a 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -233,7 +233,8 @@
 // buildLanguageClient returns a language client built using the given language server config.
 // The returned language client need to be started before use.
 export async function buildLanguageClient(cfg: BuildLanguageClientOption): Promise<LanguageClient> {
-	let goplsWorkspaceConfig = getGoplsConfig();
+	let goplsWorkspaceConfig = getGoplsConfig() as any;
+	goplsWorkspaceConfig = filterDefaultConfigValues(goplsWorkspaceConfig, 'gopls',  undefined);
 	goplsWorkspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, goplsWorkspaceConfig);
 	const c = new LanguageClient(
 		'go',  // id
@@ -437,13 +438,22 @@
 				workspace: {
 					configuration: async (params: ConfigurationParams, token: CancellationToken, next: ConfigurationRequest.HandlerSignature): Promise<any[] | ResponseError<void>> => {
 						const configs = await next(params, token);
-						if (!Array.isArray(configs)) {
+						if (!configs || !Array.isArray(configs)) {
 							return configs;
 						}
-						for (let workspaceConfig of configs) {
-							workspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, workspaceConfig);
+						const ret = [] as any[];
+						for (let i = 0; i < configs.length; i++) {
+							let workspaceConfig = configs[i];
+							if (!!workspaceConfig && typeof workspaceConfig === 'object') {
+								const scopeUri = params.items[i].scopeUri;
+								const resource = scopeUri ? vscode.Uri.parse(scopeUri) : undefined;
+								const section = params.items[i].section;
+								workspaceConfig = filterDefaultConfigValues(workspaceConfig, section, resource);
+								workspaceConfig = await adjustGoplsWorkspaceConfiguration(cfg, workspaceConfig);
+							}
+							ret.push(workspaceConfig);
 						}
-						return configs;
+						return ret;
 					},
 				},
 			}
@@ -452,6 +462,43 @@
 	return c;
 }
 
+// filterDefaultConfigValues removes the entries filled based on the default values
+// and selects only those the user explicitly specifies in their settings.
+// This assumes workspaceConfig is a non-null(undefined) object type.
+// Exported for testing.
+export function filterDefaultConfigValues(workspaceConfig: any, section: string, resource: vscode.Uri): any {
+	if (!workspaceConfig) {
+		return workspaceConfig;
+	}
+
+	const dot = section?.lastIndexOf('.') || -1;
+	const sectionKey = dot >= 0 ? section.substr(0, dot) : section;  // e.g. 'gopls'
+
+	const cfg = vscode.workspace.getConfiguration(sectionKey, resource);
+	const filtered = {} as { [key: string]: any };
+	for (const [key, value] of Object.entries(workspaceConfig)) {
+		if (typeof value === 'function') {
+			continue;
+		}
+		const c = cfg.inspect(key);
+		// select only the field whose current value comes from non-default setting.
+		if (!c || !deepEqual(c.defaultValue, value) ||
+			// c.defaultValue !== value would be most likely sufficient, except
+			// when gopls' default becomes different from extension's default.
+			// So, we also forward the key if ever explicitely stated in one of the
+			// settings layers.
+			c.globalLanguageValue !== undefined ||
+			c.globalValue !== undefined ||
+			c.workspaceFolderLanguageValue !== undefined ||
+			c.workspaceFolderValue !== undefined ||
+			c.workspaceLanguageValue !== undefined ||
+			c.workspaceValue !== undefined) {
+			filtered[key] = value;
+		}
+	}
+	return filtered;
+}
+
 // adjustGoplsWorkspaceConfiguration adds any extra options to the gopls
 // config. Right now, the only extra option is enabling experiments for the
 // Nightly extension.
diff --git a/test/gopls/configuration.test.ts b/test/gopls/configuration.test.ts
new file mode 100644
index 0000000..e2adea4
--- /dev/null
+++ b/test/gopls/configuration.test.ts
@@ -0,0 +1,79 @@
+/*---------------------------------------------------------
+ * Copyright (C) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------*/
+
+import * as assert from 'assert';
+import moment = require('moment');
+import semver = require('semver');
+import sinon = require('sinon');
+import * as vscode from 'vscode';
+import * as lsp from '../../src/goLanguageServer';
+import { getTool, Tool } from '../../src/goTools';
+
+suite('gopls configuration tests', () => {
+	test('configuration', async () => {
+		const defaultGoplsConfig = vscode.workspace.getConfiguration('gopls');
+		const defaultGoplsAnalysesConfig = vscode.workspace.getConfiguration('gopls.analyses');
+
+		interface TestCase {
+			name: string;
+			section: string;
+			base: any;
+			want: any;
+		}
+		const testCases: TestCase[] = [
+			{
+				name: 'user set no gopls settings',
+				section: 'gopls',
+				base: defaultGoplsConfig,
+				want: {}
+			},
+			{
+				name: 'user set some gopls settings',
+				section: 'gopls',
+				base: defaultGoplsConfig,
+				want: {
+					buildFlags: ['-something'],
+					env: { foo: 'bar' },
+					hoverKind: 'NoDocumentation',
+					usePlaceholders: true,
+					linkTarget: 'godoc.org',
+				},
+			},
+			{
+				name: 'gopls asks analyses section, user set no analysis',
+				section: 'gopls.analyses',
+				base: defaultGoplsAnalysesConfig,
+				want: {},
+			},
+			{
+				name: 'gopls asks analyses section, user set some',
+				section: 'gopls.analyses',
+				base: defaultGoplsAnalysesConfig,
+				want: {
+					coolAnalysis: true,
+				},
+			},
+			{
+				name: 'user set extra gopls settings',
+				section: 'gopls',
+				base: defaultGoplsConfig,
+				want: {
+					undefinedGoplsSetting: true,
+				},
+			},
+			{
+				name: 'gopls asks undefined config section',
+				section: 'undefined.section',
+				base: undefined,
+				want: {},
+			}
+		];
+		testCases.map((tc: TestCase) => {
+			const input = Object.assign({}, tc.base, tc.want);
+			const actual = lsp.filterDefaultConfigValues(input, tc.section, undefined);
+			assert.deepStrictEqual(actual, tc.want, `Failed: ${tc.name}`);
+		});
+	});
+});