From 590c0bedc925b2babe7abd015d414c5b153c3a04 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 11 Aug 2024 00:29:15 +0100 Subject: [PATCH] chore(language/ruby): simplify lsp-solargraph format-on-save predicate --- modules/languages/siren-ruby.el | 41 +++++++++++++-------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/modules/languages/siren-ruby.el b/modules/languages/siren-ruby.el index ea349e0..2e360e8 100644 --- a/modules/languages/siren-ruby.el +++ b/modules/languages/siren-ruby.el @@ -197,40 +197,31 @@ (lsp-solargraph-log-level "warn") :preface - (defgroup siren-lsp-solargraph nil - "Customizations for the lsp-solargraph package." - :group 'lsp) + (defun siren-lsp-solargraph-format-on-save-p () + "Determine if format on save (FoS) should be enabled in the current buffer. - (defcustom siren-lsp-solargraph-fos-disable-predicate nil - "Predicate function to determine if the FOS (Format On Save) feature should -be disabled in the current buffer. +Returns t if FoS should be enabled, nil otherwise. -Defaults to `siren-lsp-solargraph-fos-disable-predicate-default' if not set." - :type 'function - :group 'siren-lsp-solargraph) - - (defun siren-lsp-solargraph-fos-disable-predicate-default () - "Default predicate function to determine if the FOS (Format On Save) feature - should be disabled." - (if buffer-file-name - (string-suffix-p (concat (file-name-as-directory "db") "schema.rb") - buffer-file-name))) +Currently only disables FoS in 'db/schema.rb' files, as Rails' generated +output typically does not conform to any common Ruby formatting standards." + (let ((db-schema-file (concat (file-name-as-directory "db") "schema.rb"))) + (or (not buffer-file-name) + (not (string-suffix-p db-schema-file buffer-file-name))))) (defun siren-lsp-ruby-mode-setup () - (setq-local lsp-disabled-clients '(vue-semantic-server)) (setq-local siren-lsp-manual-format-buffer-func - 'siren-lsp-ruby-manual-format-buffer) + 'siren-lsp-solargraph-manual-format-buffer) - ;; Enable format on save unless the disable predicate returns true. - (let ((disable-fos (if siren-lsp-solargraph-fos-disable-predicate - (funcall siren-lsp-solargraph-fos-disable-predicate) - (siren-lsp-solargraph-fos-disable-predicate-default)))) - (if (not disable-fos) - (lsp-format-buffer-on-save-mode t))) + ;; Disable ruby clients which have higher priority than the ruby-ls client. + (setq-local lsp-disabled-clients '(vue-semantic-server)) + + ;; Enable format on save if the predicate returns true. + (when (siren-lsp-solargraph-format-on-save-p) + (lsp-format-buffer-on-save-mode t)) (lsp-deferred)) - (defun siren-lsp-ruby-manual-format-buffer () + (defun siren-lsp-solargraph-manual-format-buffer () (stree-format-buffer) (lsp-format-buffer))