dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.37k stars 209 forks source link

add go-* shortcuts for various hard-to-find eglot operations #436

Open adonovan opened 2 months ago

adonovan commented 2 months ago

Could we add these declarations to go-mode.el to make it easier for Go programmers to find common operations whose eglot command is somewhat obscure?

;; upcoming features of gopls/v0.16 that it would be nice to have go-mode support for in advance:

(eglot--code-action eglot-code-action-doc "source.doc")

(defalias 'go-doc #'eglot-code-action-doc
  "View documentation for the current Go package.")

(eglot--code-action eglot-code-action-freesymbols "source.freesymbols")

(defalias 'go-freesymbols #'eglot-code-action-freesymbols
  "View free symbols referenced by the current selection.")

;; existing features

(defalias 'go-inline #'eglot-code-action-inline
  "Inline the Go function call under the cursor.")

(defalias 'go-rename #'eglot-rename
  "Rename a Go symbol.")

[Edit: rename "freerefs" to "freesymbols"]

dominikh commented 2 months ago

Do we also need to support lsp-mode or will they add their own functions? And if we only support eglot, should we name them go-eglot-* instead? That'd also help avoid confusion between godoc and go-doc.

adonovan commented 2 months ago

Good question. Perhaps these functions shouldn't presume which LSP client is in use, but should query (waved hands vigorously) whether the buffer is managed by eglot or lsp-mode and take appropriate action.

Much better that way than to include eglot in the symbol name; ideally most Emacs users wouldn't need to know anything about their LSP client.