From 2d3c1b241ce85db914e1dc41c93ee590734a8e94 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Fri, 2 Apr 2021 10:41:20 +0100 Subject: [PATCH] chore(lang): tweak ruby-mode format on save setup to use lsp-mode directly Instead of executing lsp-format-buffer on save via the rubocopfmt package, simply set it up as a buffer-local before-save-hook. Also simplify the rubocopfmt package configuration, as I rarely use it anymore, but would still want to be able to manually execute rubocopfmt. --- modules/languages/siren-ruby.el | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/languages/siren-ruby.el b/modules/languages/siren-ruby.el index 59911e0..e80c6aa 100644 --- a/modules/languages/siren-ruby.el +++ b/modules/languages/siren-ruby.el @@ -86,10 +86,19 @@ :straight lsp-mode :hook - (ruby-mode . lsp-deferred) + (ruby-mode . siren-lsp-ruby-mode-setup) :custom - (lsp-solargraph-multi-root nil)) + (lsp-solargraph-multi-root nil) + + :init + (add-to-list 'safe-local-variable-values + '(lsp-solargraph-use-bundler . t)) + + (defun siren-lsp-ruby-mode-setup () + (add-hook 'before-save-hook #'lsp-format-buffer t t) + + (lsp-deferred))) (use-package dap-ruby :straight dap-mode @@ -145,22 +154,15 @@ (use-package rubocopfmt :bind (:map ruby-mode-map ("C-c C-f" . rubocopfmt)) - :hook - (ruby-mode . rubocopfmt-mode) :custom (rubocopfmt-include-unsafe-cops t) - (rubocopfmt-on-save-use-lsp-format-buffer t) (rubocopfmt-show-errors 'echo) - (rubocopfmt-use-bundler-when-possible nil) - (rubocopfmt-rubocop-command - (expand-file-name "bin/rubocop-daemon-wrapper" siren-dir)) + (rubocopfmt-use-bundler-when-possible t) :config (add-to-list 'safe-local-variable-values - '(rubocopfmt-include-unsafe-cops)) - (add-to-list 'safe-local-variable-values - '(rubocopfmt-on-save-use-lsp-format-buffer))) + '(rubocopfmt-include-unsafe-cops))) (use-package ruby-compilation :defer t)