| 1 | --- |
| 2 | title: "Gopls: Inlay hints" |
| 3 | --- |
| 4 | |
| 5 | Inlay hints are helpful annotations that the editor can optionally |
| 6 | display in-line in the source code, such as the names of parameters in |
| 7 | a function call. This document describes the inlay hints available |
| 8 | from `gopls`. |
| 9 | |
| 10 | <!-- This portion is generated by doc/generate from golang.AllInlayHints. --> |
| 11 | <!-- BEGIN Hints: DO NOT MANUALLY EDIT THIS SECTION --> |
| 12 | ## **assignVariableTypes** |
| 13 | |
| 14 | `"assignVariableTypes"` controls inlay hints for variable types in assign statements: |
| 15 | ```go |
| 16 | i« int», j« int» := 0, len(r)-1 |
| 17 | ``` |
| 18 | |
| 19 | |
| 20 | **Disabled by default. Enable it by setting `"hints": {"assignVariableTypes": true}`.** |
| 21 | |
| 22 | ## **compositeLiteralFields** |
| 23 | |
| 24 | `"compositeLiteralFields"` inlay hints for composite literal field names: |
| 25 | ```go |
| 26 | Point2D{«X: »1, «Y: »2} |
| 27 | |
| 28 | Outer{«Embedded.»Field: 0} |
| 29 | ``` |
| 30 | |
| 31 | |
| 32 | **Disabled by default. Enable it by setting `"hints": {"compositeLiteralFields": true}`.** |
| 33 | |
| 34 | ## **compositeLiteralTypes** |
| 35 | |
| 36 | `"compositeLiteralTypes"` controls inlay hints for composite literal types: |
| 37 | ```go |
| 38 | for _, c := range []struct { |
| 39 | in, want string |
| 40 | }{ |
| 41 | «struct{ in string; want string }»{"Hello, world", "dlrow ,olleH"}, |
| 42 | } |
| 43 | ``` |
| 44 | |
| 45 | |
| 46 | **Disabled by default. Enable it by setting `"hints": {"compositeLiteralTypes": true}`.** |
| 47 | |
| 48 | ## **constantValues** |
| 49 | |
| 50 | `"constantValues"` controls inlay hints for constant values: |
| 51 | ```go |
| 52 | const ( |
| 53 | KindNone Kind = iota« = 0» |
| 54 | KindPrint« = 1» |
| 55 | KindPrintf« = 2» |
| 56 | KindErrorf« = 3» |
| 57 | ) |
| 58 | ``` |
| 59 | |
| 60 | |
| 61 | **Disabled by default. Enable it by setting `"hints": {"constantValues": true}`.** |
| 62 | |
| 63 | ## **functionTypeParameters** |
| 64 | |
| 65 | `"functionTypeParameters"` inlay hints for implicit type parameters on generic functions: |
| 66 | ```go |
| 67 | myFoo«[int, string]»(1, "hello") |
| 68 | ``` |
| 69 | |
| 70 | |
| 71 | **Disabled by default. Enable it by setting `"hints": {"functionTypeParameters": true}`.** |
| 72 | |
| 73 | ## **ignoredError** |
| 74 | |
| 75 | `"ignoredError"` inlay hints for implicitly discarded errors: |
| 76 | ```go |
| 77 | f.Close()« // ignore error» |
| 78 | ``` |
| 79 | This check inserts an `// ignore error` hint following any |
| 80 | statement that is a function call whose error result is |
| 81 | implicitly ignored. |
| 82 | |
| 83 | To suppress the hint, write an actual comment containing |
| 84 | "ignore error" following the call statement, or explicitly |
| 85 | assign the result to a blank variable. A handful of common |
| 86 | functions such as `fmt.Println` are excluded from the |
| 87 | check. |
| 88 | |
| 89 | |
| 90 | **Disabled by default. Enable it by setting `"hints": {"ignoredError": true}`.** |
| 91 | |
| 92 | ## **parameterNames** |
| 93 | |
| 94 | `"parameterNames"` controls inlay hints for parameter names: |
| 95 | ```go |
| 96 | parseInt(« str: » "123", « radix: » 8) |
| 97 | ``` |
| 98 | |
| 99 | |
| 100 | **Disabled by default. Enable it by setting `"hints": {"parameterNames": true}`.** |
| 101 | |
| 102 | ## **rangeVariableTypes** |
| 103 | |
| 104 | `"rangeVariableTypes"` controls inlay hints for variable types in range statements: |
| 105 | ```go |
| 106 | for k« int», v« string» := range []string{} { |
| 107 | fmt.Println(k, v) |
| 108 | } |
| 109 | ``` |
| 110 | |
| 111 | |
| 112 | **Disabled by default. Enable it by setting `"hints": {"rangeVariableTypes": true}`.** |
| 113 | |
| 114 | <!-- END Hints: DO NOT MANUALLY EDIT THIS SECTION --> |