From 1509214e55b829c2765a3cd130795fa99d360fd0 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 24 Aug 2025 15:03:49 +0200 Subject: [PATCH] feat: reintroduce lsp-mode, flycheck I think moving to eglot, flymake was a mistake. --- init.el | 165 +++++++++++++++++++++----------------------------------- 1 file changed, 61 insertions(+), 104 deletions(-) diff --git a/init.el b/init.el index b99988fe017d09bc63999a1a4a5ce99f911bebe6..ca1335e586798394a668c7c6cdc9ac96576c4c9d 100644 --- a/init.el +++ b/init.el @@ -88,14 +88,16 @@ ;; NOTE: this is loaded so early as to prevent this issue ;; Fix eldoc loading before Elpaca activation (from issue #398) -(unload-feature 'eldoc t) -(setq custom-delayed-init-variables '()) -(defvar global-eldoc-mode nil) +;; (unload-feature 'eldoc t) +;; (setq custom-delayed-init-variables '()) +;; (defvar global-eldoc-mode nil) (my-use-package eldoc - :ensure t + ;; :ensure t :custom (eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly) + (eldoc-echo-area-use-multiline-p nil) + (eldoc-idle-delay 0.25) :config (require 'eldoc) (global-eldoc-mode) @@ -411,8 +413,6 @@ "d m" '(consult-man :wk "Consult uan") "d i" '(consult-info :wk "Consult info") - "e c" '(consult-flymake :wk "Consult flymake") - "y" '(consult-yank-pop :wk "Yank pop") "s" '(:keymap search-map :wk "Search") @@ -441,7 +441,6 @@ ("M-y" . consult-yank-pop) ;; orig. yank-pop ;; M-g bindings in `goto-map' ("M-g e" . consult-compile-error) - ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck ("M-g g" . consult-goto-line) ;; orig. goto-line ("M-g M-g" . consult-goto-line) ;; orig. goto-line ("M-g o" . consult-outline) ;; Alternative: consult-org-heading @@ -474,7 +473,7 @@ ("s" . consult-ripgrep-all) ("i" . consult-imenu) ("I" . consult-imenu-multi) - ("f" . consult-flymake)) + ("f" . consult-flycheck)) :custom (register-preview-delay 0.5) (register-preview-function #'consult-register-format) @@ -487,6 +486,12 @@ (require 'consult-ripgrep-all) (recentf-mode 1)) +(my-use-package consult-flycheck + :ensure t + :general + (my-leader + "e c" '(consult-flycheck :wk "Flycheck"))) + (my-use-package orderless :ensure t :custom @@ -566,6 +571,7 @@ (popper-reference-buffers '("\\*Messages\\*" "Output\\*$" + "*lsp-help*" ;; "\\*Async Shell Command\\*" ;; "^\\*Embark Collect: " "^\\*eat\\*$" @@ -800,13 +806,12 @@ (:eval (when buffer-read-only " RO")))) (vs-modeline-right '( - (:eval (when which-func-mode which-func-format)) - (:eval (when which-function-mode " ")) + (:eval (when (and (boundp 'which-func-mode) which-func-mode) which-func-format)) + (:eval (when (and (boundp 'which-function-mode) which-function-mode) " ")) (:eval (vs-modeline-input-method)) - (:eval (when flymake-mode " ")) - (:eval (when flymake-mode flymake-mode-line-exception)) - (:eval (when flymake-mode flymake-mode-line-counters)) - (:eval (when flymake-mode " ")) + (:eval (vs-modeline-flycheck)) + (:eval (vs-modeline-lsp-diagnostics)) + (:eval (vs-modeline-org-clock)) mode-name " " (:eval (vs-modeline-position-rel)) @@ -1011,23 +1016,21 @@ ) ;; Editing -(my-use-package flymake +(my-use-package flycheck :ensure t :demand t + :config + (global-flycheck-mode 1) :general (my-leader - "e n" '(flymake-goto-next-error :wk "Next error") - "e p" '(flymake-goto-prev-error :wk "Prev error") - "e j" '(flymake-goto-next-error :wk "Next error") - "e k" '(flymake-goto-prev-error :wk "Prev error") - - "e R" '(flymake-running-backends :wk "Running backends") - "e d" '(flymake-disabled-backends :wk "Disabled backends") - "e r" '(flymake-reporting-backends :wk "Reported backends") - - "e l" '(flymake-show-buffer-diagnostics :wk "Show buffer diagnostics") - "e L" '(flymake-show-project-diagnostics :wk "Show project diagnostics") - )) + "e s" '(flycheck-buffer :wk "Start flycheck") + + "e n" '(flycheck-next-error :wk "Next error") + "e p" '(flycheck-prev-error :wk "Prev error") + "e j" '(flycheck-next-error :wk "Next error") + "e k" '(flycheck-prev-error :wk "Prev error") + + "e l" '(flycheck-list-errors :wk "Show buffer diagnostics"))) ;; TODO: what about isearch-lazy-count variable? ;; Added in emacs 27, could be an alternative. (my-use-package evil-anzu @@ -1255,6 +1258,32 @@ (setq eldoc-documentation-strategy 'eldoc-documentation-compose-eagerly))) +(my-use-package lsp-mode + :ensure t + :commands (lsp lsp-mode) + :hook + (csharp-mode . lsp-conditional) + (csharp-ts-mode . lsp-conditional) + :general + (my-leader + "D" '(lsp-describe-thing-at-point :wk "LSP Documentation")) + (normal lsp-managed-mode + :definer 'minor-mode + "gr" '(lsp-find-references :wk "Find references") + "gR" '(lsp-rename :wk "Rename identifier") + "g." '(lsp-execute-code-action :wk "Code actions")) + :custom + (lsp-enable-suggest-server-download nil) + :config + (defun lsp-conditional () + "Enable LSP only if already running in project." + (lsp-deferred))) + +(my-use-package lsp-ui + :ensure t + :hook + (lsp-mode . lsp-ui-mode)) + (my-use-package envrc :ensure t :demand t @@ -1306,6 +1335,9 @@ :commands pdf-view-mode) ;; Treesit langs +(use-package ts-fold + :ensure (ts-fold :type git :host github :repo "emacs-tree-sitter/ts-fold")) + (my-use-package emacs :ensure nil :custom @@ -1398,7 +1430,7 @@ minibuffer, even without explicitly focusing it." (defun csharp--find-csproj (dir) (csharp--get-csproj-in-directory (locate-dominating-file - dir #'get-csproj-in-directory))) + dir #'csharp--get-csproj-in-directory))) (defun csharp--find-current-csproj () (csharp--find-csproj buffer-file-name)) @@ -1499,72 +1531,6 @@ minibuffer, even without explicitly focusing it." (my/indent-variable-mode-alist-add matlab-mode matlab-indent-level) ) -;; Vhdl -(defun flymake-ghdl-backend (report-fn &rest _args) - "GHDL syntax checking backend for Flymake." - (condition-case err - (progn - (unless (executable-find "ghdl") - (error "Cannot find ghdl executable")) - (when-let* ((source (buffer-file-name)) - (source (file-truename source))) - (let* ((temp-file (make-temp-file "flymake-ghdl" nil ".vhdl")) - (command `("ghdl" "-s" "-Wall" "-fno-color-diagnostics" ,temp-file))) - (save-restriction - (widen) - (write-region (point-min) (point-max) temp-file nil 'silent)) - (make-process - :name "flymake-ghdl" - :buffer (generate-new-buffer " *flymake-ghdl*") - :command command - :noquery t - :connection-type 'pipe - :sentinel - (lambda (proc _event) - (let ((proc-buffer (process-buffer proc))) - (when (memq (process-status proc) '(exit signal)) - (unwind-protect - (if (with-current-buffer proc-buffer - (goto-char (point-min)) - (zerop (buffer-size))) - (funcall report-fn nil) - (funcall report-fn - (with-current-buffer proc-buffer - (flymake-ghdl--parse-diagnostics source temp-file)))) - (when (file-exists-p temp-file) - (delete-file temp-file)) - (kill-buffer proc-buffer))))))))))) - -(defun flymake-ghdl--parse-diagnostics (source temp-file) - "Parse GHDL diagnostics from current buffer for SOURCE file." - (let ((result '()) - (ignored-patterns '("cannot find resource library \".*\"" - "entity \".*\" was not analysed"))) - (save-excursion - (goto-char (point-min)) - (while (re-search-forward - (concat "\\(" (regexp-quote temp-file) "\\)" - ":\\([0-9]+\\):\\([0-9]+\\):\\s-*\\(.*?\\):\\s-*\\(.*\\)") - nil t) - (let* ((line-num (string-to-number (match-string 2))) - (col-num (string-to-number (match-string 3))) - (type-str (match-string 4)) - (msg (match-string 5)) - (type (cond ((string-match-p "error\\|Error" type-str) :error) - ((string-match-p "warning\\|Warning" type-str) :warning) - (t :note))) - (pos (flymake-diag-region (get-file-buffer source) line-num col-num)) - (should-ignore (cl-some (lambda (pattern) - (string-match-p pattern msg)) - ignored-patterns))) - (when (and pos (not should-ignore)) - (push (flymake-make-diagnostic - (get-file-buffer source) - (car pos) (cdr pos) - type - (format "%s: %s" type-str msg)) - result))))) - result)) (my-use-package vhdl-mode :ensure nil @@ -1580,11 +1546,7 @@ minibuffer, even without explicitly focusing it." "a c" '(vhdl-align-inline-comment-group :wk "Align comment group")) :hook ((vhdl-mode . vhdl-electric-mode) - (vhdl-mode . vhdl-stutter-mode) - (vhdl-mode . (lambda () - (add-hook 'flymake-diagnostic-functions - #'flymake-ghdl-backend nil t) - (flymake-mode 1)))) + (vhdl-mode . vhdl-stutter-mode)) :custom (vhdl-clock-edge-condition 'function) (vhdl-clock-name "clk_i") @@ -1618,11 +1580,6 @@ minibuffer, even without explicitly focusing it." (vhdl-ts-indent-level tab-width) :mode ("\\.vhdl?\\'" . vhdl-ts-mode) - :hook - (vhdl-ts-mode . (lambda () - (add-hook 'flymake-diagnostic-functions - #'flymake-ghdl-backend nil t) - (flymake-mode 1))) :init (defun my/vhdl-ts/beautify-block-at-point () (interactive)