Skip to content

Commit ee683d7

Browse files
committed
vscode-go: add inlay hint settings to extension config
Adding the inlay hint settings to the go configuration allows for toggling inlay hints from settings.json or the settings UI. For #1631. Change-Id: Iccf2ff3db89d195f694883403d4a25160d66e7ff Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/413678 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Jamal Carvalho <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 0848778 commit ee683d7

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

docs/settings.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,41 @@ Default: `false`
277277

278278
Infer GOPATH from the workspace root. This is ignored when using Go Modules.
279279

280+
Default: `false`
281+
### `go.inlayHints.assignVariableTypes`
282+
283+
Enable/disable inlay hints for variable types in assign statements.
284+
285+
Default: `false`
286+
### `go.inlayHints.compositeLiteralFields`
287+
288+
Enable/disable inlay hints for composite literal field names.
289+
290+
Default: `false`
291+
### `go.inlayHints.compositeLiteralTypes`
292+
293+
Enable/disable inlay hints for composite literal types.
294+
295+
Default: `false`
296+
### `go.inlayHints.constantValues`
297+
298+
Enable/disable inlay hints for constant values.
299+
300+
Default: `false`
301+
### `go.inlayHints.functionTypeParameters`
302+
303+
Enable/disable inlay hints for implicit type parameters on generic functions.
304+
305+
Default: `false`
306+
### `go.inlayHints.parameterNames`
307+
308+
Enable/disable inlay hints for parameter names.
309+
310+
Default: `false`
311+
### `go.inlayHints.rangeVariableTypes`
312+
313+
Enable/disable inlay hints for variable types in range statements.
314+
280315
Default: `false`
281316
### `go.installDependenciesWhenBuilding`
282317

package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,41 @@
20432043
"scope": "resource",
20442044
"type": "boolean"
20452045
},
2046+
"go.inlayHints.assignVariableTypes": {
2047+
"type": "boolean",
2048+
"description": "Enable/disable inlay hints for variable types in assign statements.",
2049+
"default": false
2050+
},
2051+
"go.inlayHints.compositeLiteralFields": {
2052+
"type": "boolean",
2053+
"description": "Enable/disable inlay hints for composite literal field names.",
2054+
"default": false
2055+
},
2056+
"go.inlayHints.compositeLiteralTypes": {
2057+
"type": "boolean",
2058+
"description": "Enable/disable inlay hints for composite literal types.",
2059+
"default": false
2060+
},
2061+
"go.inlayHints.constantValues": {
2062+
"type": "boolean",
2063+
"description": "Enable/disable inlay hints for constant values.",
2064+
"default": false
2065+
},
2066+
"go.inlayHints.functionTypeParameters": {
2067+
"type": "boolean",
2068+
"description": "Enable/disable inlay hints for implicit type parameters on generic functions.",
2069+
"default": false
2070+
},
2071+
"go.inlayHints.parameterNames": {
2072+
"type": "boolean",
2073+
"description": "Enable/disable inlay hints for parameter names.",
2074+
"default": false
2075+
},
2076+
"go.inlayHints.rangeVariableTypes": {
2077+
"type": "boolean",
2078+
"description": "Enable/disable inlay hints for variable types in range statements.",
2079+
"default": false
2080+
},
20462081
"gopls": {
20472082
"type": "object",
20482083
"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.",

src/language/goLanguageServer.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ export function passGoConfigToGoplsConfigValues(goplsWorkspaceConfig: any, goWor
664664
if (buildFlags.length > 0 && goplsWorkspaceConfig['build.buildFlags'] === undefined) {
665665
goplsWorkspaceConfig['build.buildFlags'] = buildFlags;
666666
}
667+
667668
return goplsWorkspaceConfig;
668669
}
669670

@@ -684,6 +685,7 @@ async function adjustGoplsWorkspaceConfiguration(
684685
workspaceConfig = filterGoplsDefaultConfigValues(workspaceConfig, resource);
685686
// note: workspaceConfig is a modifiable, valid object.
686687
workspaceConfig = passGoConfigToGoplsConfigValues(workspaceConfig, getGoConfig(resource));
688+
workspaceConfig = await passInlayHintConfigToGopls(cfg, workspaceConfig, getGoConfig(resource));
687689

688690
// Only modify the user's configurations for the Nightly.
689691
if (!extensionInfo.isPreview) {
@@ -695,6 +697,19 @@ async function adjustGoplsWorkspaceConfiguration(
695697
return workspaceConfig;
696698
}
697699

700+
async function passInlayHintConfigToGopls(cfg: LanguageServerConfig, goplsConfig: any, goConfig: any) {
701+
const goplsVersion = await getLocalGoplsVersion(cfg);
702+
if (!goplsVersion) return;
703+
const version = semver.parse(goplsVersion.version);
704+
if ((version?.compare('0.8.4') ?? 1) > 0) {
705+
const { inlayHints } = goConfig;
706+
if (inlayHints) {
707+
goplsConfig['ui.inlayhint.hints'] = { ...inlayHints };
708+
}
709+
}
710+
return goplsConfig;
711+
}
712+
698713
// createTestCodeLens adds the go.test.cursor and go.debug.cursor code lens
699714
function createTestCodeLens(lens: vscode.CodeLens): vscode.CodeLens[] {
700715
// CodeLens argument signature in gopls is [fileName: string, testFunctions: string[], benchFunctions: string[]],

0 commit comments

Comments
 (0)