InlayHints support for gopls #1369
-
I was wondering if anyone has gotten inlay hints working with gopls? I know the server supports it but can't get them to display after enabling them via https://github.com/golang/tools/blob/master/gopls/doc/settings.md#inlayhint Shows how the settings should work am just unable to enable it myself. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Managed to get this working in the end. Hope this can be of help to future gophers (use-package eglot-gopls-x :no-require t
:after (:all eglot go-ts-mode)
:config
;; Ensure gopls will use typehints (IDK why I needed to do this manually)
(setq-default eglot-workspace-configuration
'(:gopls (:hints (
:assignVariableTypes t
:compositeLiteralFields t
:compositeLiteralTypes t
:constantValues t
:functionTypeParameters t
:parameterNames t
:rangeVariableTypes t
))))
(cl-defmethod eglot-client-capabilities :around (server)
"Allow dynamic registration of inlay hints since it's the only way
to get gopls to give us any inlay hints"
(let ((base (cl-call-next-method)))
(when (cl-find "gopls" (process-command
(jsonrpc--process server))
:test #'string-match)
(setf (cl-getf (cl-getf base :textDocument) :inlayHint)
`(:dynamicRegistration t)))
base))
;; Ensure inlay hints going for eglot
(add-hook 'go-ts-mode-hook 'eglot-inlay-hints-mode)) |
Beta Was this translation helpful? Give feedback.
-
Sorry, @Gavinok , I unmarked you answer because I don't think it needs to be as complicated as you say. A much simpler way is to just set:
add more types of hints if you want. See #1369 (reply in thread) for a full Ideally, even this shouldn't be needed. Gopls should enable this by default, or allow this via |
Beta Was this translation helpful? Give feedback.
Sorry, @Gavinok , I unmarked you answer because I don't think it needs to be as complicated as you say.
A much simpler way is to just set:
add more types of hints if you want. See #1369 (reply in thread) for a full
emacs -Q
recipe.Ideally, even this shouldn't be needed. Gopls should enable this by default, or allow this via
initializationOptions
or command-line parameters, since this is not usually a per-project thing.