Skip to content

Commit

Permalink
internal/lsp: update inlay hints documentation to include go snippets
Browse files Browse the repository at this point in the history
Update the markdown documentation for inlay hints and fix a couple
of typos in the examples.

Change-Id: I114502a81999bc5e4f25384ab619888f3e31a731
Reviewed-on: https://go-review.googlesource.com/c/tools/+/419496
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
gopls-CI: kokoro <[email protected]>
Run-TryBot: Suzy Mueller <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
suzmue committed Jul 26, 2022
1 parent 8b47d4e commit c83f42d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 63 deletions.
27 changes: 17 additions & 10 deletions gopls/doc/inlayHints.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,74 @@ This document describes the inlay hints that `gopls` uses inside the editor.
## **assignVariableTypes**

Enable/disable inlay hints for variable types in assign statements:

i/* int/*, j/* int/* := 0, len(r)-1
```go
i/* int*/, j/* int*/ := 0, len(r)-1
```

**Disabled by default. Enable it by setting `"hints": {"assignVariableTypes": true}`.**

## **compositeLiteralFields**

Enable/disable inlay hints for composite literal field names:

{in: "Hello, world", want: "dlrow ,olleH"}
```go
{/*in: */"Hello, world", /*want: */"dlrow ,olleH"}
```

**Disabled by default. Enable it by setting `"hints": {"compositeLiteralFields": true}`.**

## **compositeLiteralTypes**

Enable/disable inlay hints for composite literal types:

```go
for _, c := range []struct {
in, want string
}{
/*struct{ in string; want string }*/{"Hello, world", "dlrow ,olleH"},
}
```

**Disabled by default. Enable it by setting `"hints": {"compositeLiteralTypes": true}`.**

## **constantValues**

Enable/disable inlay hints for constant values:

```go
const (
KindNone Kind = iota/* = 0*/
KindPrint/* = 1*/
KindPrintf/* = 2*/
KindErrorf/* = 3*/
)
```

**Disabled by default. Enable it by setting `"hints": {"constantValues": true}`.**

## **functionTypeParameters**

Enable/disable inlay hints for implicit type parameters on generic functions:

```go
myFoo/*[int, string]*/(1, "hello")
```

**Disabled by default. Enable it by setting `"hints": {"functionTypeParameters": true}`.**

## **parameterNames**

Enable/disable inlay hints for parameter names:

```go
parseInt(/* str: */ "123", /* radix: */ 8)
```

**Disabled by default. Enable it by setting `"hints": {"parameterNames": true}`.**

## **rangeVariableTypes**

Enable/disable inlay hints for variable types in range statements:

for k/* int*/, v/* string/* := range []string{} {
```go
for k/* int*/, v/* string*/ := range []string{} {
fmt.Println(k, v)
}
```

**Disabled by default. Enable it by setting `"hints": {"rangeVariableTypes": true}`.**

Expand Down
28 changes: 14 additions & 14 deletions internal/lsp/source/api_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 14 additions & 39 deletions internal/lsp/source/inlay_hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,63 +44,38 @@ const (
var AllInlayHints = map[string]*Hint{
AssignVariableTypes: {
Name: AssignVariableTypes,
Doc: `Enable/disable inlay hints for variable types in assign statements:
i/* int/*, j/* int/* := 0, len(r)-1`,
Run: assignVariableTypes,
Doc: "Enable/disable inlay hints for variable types in assign statements:\n```go\n\ti/* int*/, j/* int*/ := 0, len(r)-1\n```",
Run: assignVariableTypes,
},
ParameterNames: {
Name: ParameterNames,
Doc: `Enable/disable inlay hints for parameter names:
parseInt(/* str: */ "123", /* radix: */ 8)`,
Run: parameterNames,
Doc: "Enable/disable inlay hints for parameter names:\n```go\n\tparseInt(/* str: */ \"123\", /* radix: */ 8)\n```",
Run: parameterNames,
},
ConstantValues: {
Name: ConstantValues,
Doc: `Enable/disable inlay hints for constant values:
const (
KindNone Kind = iota/* = 0*/
KindPrint/* = 1*/
KindPrintf/* = 2*/
KindErrorf/* = 3*/
)`,
Run: constantValues,
Doc: "Enable/disable inlay hints for constant values:\n```go\n\tconst (\n\t\tKindNone Kind = iota/* = 0*/\n\t\tKindPrint/* = 1*/\n\t\tKindPrintf/* = 2*/\n\t\tKindErrorf/* = 3*/\n\t)\n```",
Run: constantValues,
},
RangeVariableTypes: {
Name: RangeVariableTypes,
Doc: `Enable/disable inlay hints for variable types in range statements:
for k/* int*/, v/* string/* := range []string{} {
fmt.Println(k, v)
}`,
Run: rangeVariableTypes,
Doc: "Enable/disable inlay hints for variable types in range statements:\n```go\n\tfor k/* int*/, v/* string*/ := range []string{} {\n\t\tfmt.Println(k, v)\n\t}\n```",
Run: rangeVariableTypes,
},
CompositeLiteralTypes: {
Name: CompositeLiteralTypes,
Doc: `Enable/disable inlay hints for composite literal types:
for _, c := range []struct {
in, want string
}{
/*struct{ in string; want string }*/{"Hello, world", "dlrow ,olleH"},
}`,
Run: compositeLiteralTypes,
Doc: "Enable/disable inlay hints for composite literal types:\n```go\n\tfor _, c := range []struct {\n\t\tin, want string\n\t}{\n\t\t/*struct{ in string; want string }*/{\"Hello, world\", \"dlrow ,olleH\"},\n\t}\n```",
Run: compositeLiteralTypes,
},
CompositeLiteralFieldNames: {
Name: CompositeLiteralFieldNames,
Doc: `Enable/disable inlay hints for composite literal field names:
{in: "Hello, world", want: "dlrow ,olleH"}`,
Run: compositeLiteralFields,
Doc: "Enable/disable inlay hints for composite literal field names:\n```go\n\t{/*in: */\"Hello, world\", /*want: */\"dlrow ,olleH\"}\n```",
Run: compositeLiteralFields,
},
FunctionTypeParameters: {
Name: FunctionTypeParameters,
Doc: `Enable/disable inlay hints for implicit type parameters on generic functions:
myFoo/*[int, string]*/(1, "hello")`,
Run: funcTypeParams,
Doc: "Enable/disable inlay hints for implicit type parameters on generic functions:\n```go\n\tmyFoo/*[int, string]*/(1, \"hello\")\n```",
Run: funcTypeParams,
},
}

Expand Down

0 comments on commit c83f42d

Please sign in to comment.