From f0222e5528c844a4292f4bf78b9f4caeca99a881 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 25 Mar 2026 13:06:24 -0700 Subject: [PATCH] Fix Go mode eldoc setup --- dotfiles/emacs.d/README.org | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index 34212f04..c5343171 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -2280,6 +2280,8 @@ bind-key and global-set-key forms. :mode (("\\.go\\'" . go-mode)) :preface (progn + (defvar imalison:use-lsp-go t) + (defun imalison:glide-novendor () (projectile-with-default-dir (projectile-project-root) (shell-command-to-string "glide novendor"))) @@ -2328,16 +2330,36 @@ bind-key and global-set-key forms. (imalison:let-advise-around imalison:advise-normal-go-command (go-command "go")) + (defun imalison:go-lsp-server-wrapper-function (args) + (if (executable-find (car args)) + args + (append (list "nix" "run" "nixpkgs#gopls" "--") + (cdr args)))) + (defun imalison:go-mode-hook () - (go-eldoc-setup) - (set (make-local-variable 'company-backends) '(company-go)) + (setq-local gofmt-command + (if (executable-find "goimports") "goimports" "gofmt")) + (setq-local imenu-create-index-function + #'imalison:go-mode-create-imenu-index) (make-local-variable 'projectile-globally-ignored-files) (add-hook 'after-save-hook 'imalison:install-current-go-project nil 'yes-do-local) + (add-hook 'before-save-hook 'gofmt-before-save nil 'yes-do-local) (add-to-list 'projectile-globally-ignored-files - "vendor"))) + "vendor") + (when (and imalison:use-lsp-go + (fboundp 'lsp-deferred) + (or (executable-find "gopls") + (executable-find "nix"))) + (lsp-deferred)))) :config (progn + (use-package lsp-mode + :config + (progn + (require 'lsp-go) + (setq lsp-go-server-wrapper-function + #'imalison:go-lsp-server-wrapper-function))) (use-package gotest :demand t :bind (:map go-mode-map @@ -2357,15 +2379,9 @@ bind-key and global-set-key forms. (setq go-test-verbose t go-test-additional-arguments-function 'imalison:add-expected-test-name-for-suite))) - (use-package company-go - :config (setq company-go-show-annotation t)) - (advice-add 'go-import-add :around 'imalison:advise-normal-go-command) - (setq gofmt-command "goimports") - - (add-hook 'go-mode-hook 'imalison:go-mode-hook) - (add-hook 'before-save-hook 'gofmt-before-save t))) + (add-hook 'go-mode-hook 'imalison:go-mode-hook))) #+END_SRC **** Show diffs of testify output #+BEGIN_SRC emacs-lisp