emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.8k stars 892 forks source link

Support for inlay hints in go files #4357

Open Gavinok opened 8 months ago

Gavinok commented 8 months ago

I tried implementing this myself but had no luck adding this to the lsp-mode code base but from what I can see from lsp-go.el it's simply adding a ("gopls.hints" lsp-go-hints) to lsp-register-custom-settings and a definition similar to:

(defcustom lsp-go-hints `(assignVariableTypes t
                                              compositeLiteralFields t
                                              compositeLiteralTypes t
                                              constantValues t
                                              functionTypeParameters t
                                              parameterNames t
                                              rangeVariableTypes t)
                                              ""
  :type '(alist :key-type (symbol :tag "hint type") :value-type (boolean :tag "value"))
  :group 'lsp-go
  :risky t
  :package-version '(lsp-mode "6.2"))

https://github.com/golang/tools/blob/master/gopls/doc/settings.md#inlayhint

Describes the functionality however no matter what I have tried I still get this error after enabling lsp-inlay-hints-mode

Error running timer ‘lsp--on-idle’: (error "The connected server(s) does not support method textDocument/inlayHint.
To find out what capabilities support your server use ‘M-x lsp-describe-session’
and expand the capabilities section")
Souheab commented 8 months ago

This is what I use in my init.el to get inlay hints in go files, maybe it could be of help to what you're trying to do

   (lsp-register-custom-settings
    '(("gopls.hints" ((assignVariableTypes . t)
                      (compositeLiteralFields . t)
                      (compositeLiteralTypes . t)
                      (constantValues . t)
                      (functionTypeParameters . t)
                      (parameterNames . t)
                      (rangeVariableTypes . t)))))

Also fyi currently there is a bug in lsp-mode where if you have this set in your early-init.el

  (setenv "LSP_USE_PLISTS" "true")
  (setq lsp-use-plists t)

then despite registering the settings with lsp-register-custom-settings you will still get the error message that inlay hints are not supported by the connected server (See #4325). So that also might possibly be the cause of the error