all repos — nixfiles @ 18ed3572ae444dbbb8e64adbc29639290cbadb21

System and user configuration, managed by nix and home-manager

emacs: use lsp-mode for go to support secondary language server
Alan Pearce alan@alanpearce.eu
Thu, 16 May 2024 18:01:16 +0200
commit

18ed3572ae444dbbb8e64adbc29639290cbadb21

parent

f134b702150f49f8ecaac7d3a1948422fd182592

2 files changed, 36 insertions(+), 3 deletions(-)

jump to
M user/emacs/init.eluser/emacs/init.el
@@ -3,7 +3,8 @@ (eval '(setq inhibit-startup-echo-area-message "alan")) (defvar default-file-name-handler-alist file-name-handler-alist)
 (setq file-name-handler-alist nil
       gc-cons-threshold most-positive-fixnum
-      gc-cons-percentage 0.6)
+      gc-cons-percentage 0.6
+      read-process-output-max (* 4 1024 1024))
 (defun set-max-gc-cons ()
   (setq gc-cons-threshold most-positive-fixnum))
 (defun set-default-gc-cons ()
@@ -1045,7 +1046,6 @@ dockerfile-mode-hook             yaml-mode-hook
             js-base-mode-hook
             css-base-mode-hook
-            go-mode-hook
             lua-mode-hook
             nim-mode-hook
             html-mode-hook
@@ -1084,6 +1084,34 @@ (use-package consult-eglot
   :commands (consult-eglot-symbols)
   :after eglot)
+
+(use-package lsp-mode
+  :defer 3
+  :ghook ('(go-mode-hook)
+          #'lsp-deferred)
+  ('lsp-mode-hook #'lsp-enable-which-key-integration)
+  :config (progn
+            (setq lsp-auto-guess-root t
+                  lsp-auto-execute-action nil
+                  lsp-headerline-breadcrumb-enable nil
+                  lsp-enable-suggest-server-download nil)
+
+            (lsp-register-custom-settings
+             '(("golangci-lint.command"
+                ["golangci-lint" "run" "--out-format" "json" "--issues-exit-code=1"])))
+
+            (lsp-register-client
+             (make-lsp-client :new-connection (lsp-stdio-connection
+                                               '("golangci-lint-langserver"))
+                              :activation-fn (lsp-activate-on "go")
+                              :language-id "go"
+                              :priority 0
+                              :server-id 'golangci-lint
+                              :add-on? t
+                              :library-folders-fn #'lsp-go--library-default-directories
+                              :initialization-options (lambda ()
+                                                        (gethash "golangci-lint"
+                                                                 (lsp-configuration-section "golangci-lint")))))))
 
 ;; Inside a javascript project, it's common to install tools locally to
 ;; the project.  This will allows emacs to find their executables.
M user/settings/emacs.nixuser/settings/emacs.nix
@@ -127,6 +127,7 @@ just-mode         justl
         kind-icon
         lua-mode
+        lsp-mode
         lispyville
         magit
         markdown-mode
@@ -155,7 +156,7 @@ wgrep-ag         ws-butler
         which-key
       ]);
-    overrides = self: super: rec {
+    overrides = self: super: {
       apheleia = self.melpaPackages.apheleia.overrideAttrs
         (old: {
           patchPhase = ''
@@ -163,8 +164,12 @@ substituteInPlace apheleia-formatters.el \               --replace-fail '"prettier"' '"prettierd"'
           '';
         });
+      lsp-mode = self.melpaPackages.lsp-mode.overrideAttrs {
+        LSP_USE_PLISTS = "true"; # sync with below
+      };
     };
     extraConfig = ''
+      (setenv "LSP_USE_PLISTS" "true") ; sync with above
       (with-eval-after-load 'editorconfig
         (setq editorconfig-exec-path "${pkgs.editorconfig-core-c}/bin/editorconfig"))
       (when (featurep 'native-compile)