From aa1364ef2968b0d06e793fa63f835e3001601481 Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Tue, 16 Dec 2025 09:43:32 +0100 Subject: [PATCH] Configure LSP for Shell Development --- emacs/.emacs.d/.lsp-session-v1 | 2 +- emacs/.emacs.d/init.el | 35 ++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/emacs/.emacs.d/.lsp-session-v1 b/emacs/.emacs.d/.lsp-session-v1 index 208e862..064b583 100644 --- a/emacs/.emacs.d/.lsp-session-v1 +++ b/emacs/.emacs.d/.lsp-session-v1 @@ -1 +1 @@ -#s(lsp-session ("/var/home/fscotto/Projects/toyforth") nil #s(hash-table test equal) #s(hash-table test equal) #s(hash-table test equal)) \ No newline at end of file +#s(lsp-session ("/var/home/fscotto/.dotfiles/emacs/.emacs.d/scripts" "/var/home/fscotto/Projects/toyforth") nil #s(hash-table test equal) #s(hash-table test equal) #s(hash-table test equal)) \ No newline at end of file diff --git a/emacs/.emacs.d/init.el b/emacs/.emacs.d/init.el index 8d427ac..9e152c3 100644 --- a/emacs/.emacs.d/init.el +++ b/emacs/.emacs.d/init.el @@ -156,6 +156,9 @@ (require 'magit) (call-interactively #'magit-dispatch)) +(defun fscotto/disable-c-formatting () + (setq-local lsp-enable-on-type-formatting nil)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PACKAGES ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -582,11 +585,17 @@ (company-idle-delay 0.1) :hook (prog-mode . company-mode)) +(with-eval-after-load 'company + (add-hook 'bash-ts-mode-hook 'company-mode)) + ;; Static analysis for code base (use-package flycheck :ensure t :hook (prog-mode . flycheck-mode)) +(with-eval-after-load 'flycheck + (add-hook 'bash-ts-mode-hook 'flycheck-mode)) + (use-package treesit :ensure nil :config @@ -596,7 +605,7 @@ '((c-mode . c-ts-mode) (c++-mode . c++-ts-mode) (python-mode . python-ts-mode) - (bash-mode . bash-ts-mode))) + (sh-mode . bash-ts-mode))) (setq treesit-language-source-alist '((c "https://github.com/tree-sitter/tree-sitter-c") (cpp "https://github.com/tree-sitter/tree-sitter-cpp") @@ -619,7 +628,7 @@ python-ts-mode go-mode go-ts-mode - bash-mode + sh-mode bash-ts-mode) . lsp-deferred) :config ;; Performance @@ -649,8 +658,7 @@ "--ranking-model=heuristics" "--malloc-trim" "--limit-results=500" - "--limit-references=2000")) - ) + "--limit-references=2000"))) (use-package lsp-ui :ensure t @@ -668,6 +676,9 @@ consult-lsp-diagnostics)) (with-eval-after-load 'lsp-mode + ;; Attach bash-language-server when open a shell scripts + (add-hook 'sh-mode-hook #'lsp) + ;; Symbols (global-set-key (kbd "C-c l s") #'consult-lsp-symbols) @@ -730,4 +741,20 @@ (global-set-key (kbd "C-c d r") #'dap-restart-frame) (global-set-key (kbd "C-c d q") #'dap-disconnect)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;; Formatters ;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; GOTCHA review this region +(use-package reformatter + :ensure t + :config + (reformatter-define shfmt-format + :program "shfmt" + :args '("-i" "2" "-ci"))) + +(add-hook 'bash-ts-mode-hook #'shfmt-format-on-save-mode) +(add-hook 'c-ts-mode-hook #'fscotto/disable-c-formatting) +(add-hook 'c-mode-hook #'fscotto/disable-c-formatting) + (message "...user configuration loaded")