From 3f2e52d55d588f3a11bcc3c8bb54bbef8031184d Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Sat, 6 Jan 2024 12:29:01 -0500 Subject: [PATCH] Enable the checker in .merlin presence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: some projects don't use Dune, while using Merlin, configured with the .merlin file. `flycheck-ocaml` is only turned on if the «dune-project» file is present though. As a result, `flycheck-ocaml` is disabled for such projects. Solution: enable the `flycheck-ocaml` checker if either dune-project or .merlin are present. In a round-about way this fixes #15. People who don't use Dune, don't need to create an empty dune-project to use the checker, which was misleading. --- flycheck-ocaml.el | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/flycheck-ocaml.el b/flycheck-ocaml.el index 0c63d00..d7cfc57 100644 --- a/flycheck-ocaml.el +++ b/flycheck-ocaml.el @@ -105,19 +105,28 @@ Return the corresponding `flycheck-error'." (or level 'error) (or message .message) :checker checker))))) +(defun flycheck-ocaml-find-merlin-config-dir () + "Find the directory containing Merlin configuration. + +The configuration is currently considered to be either .merlin or +dune-project." + (and buffer-file-name + (or (locate-dominating-file buffer-file-name "dune-project") + (locate-dominating-file buffer-file-name ".merlin")))) + (defun flycheck-verify-ocaml-merlin (_checker) "Verify the OCaml Merlin syntax checker." (let ((command (executable-find (merlin-command))) - (dune-file (and buffer-file-name (locate-dominating-file buffer-file-name "dune-project")))) + (config-dir (flycheck-ocaml-find-merlin-config-dir))) (list (flycheck-verification-result-new :label "Merlin command" :message (if command (format "Found at %s" command) "Not found") :face (if command 'success '(bold error))) (flycheck-verification-result-new - :label "Dune project" - :message (if dune-file (format "Found at %s" dune-file) "Not found") - :face (if dune-file 'success '(bold error))) + :label "Dune project or .merlin" + :message (if config-dir (format "Found at %s" config-dir) "Not found") + :face (if config-dir 'success '(bold error))) (flycheck-verification-result-new :label "Merlin mode" :message (if merlin-mode "enabled" "disabled") @@ -149,9 +158,9 @@ See URL `https://github.com/ocaml/merlin'." :verify #'flycheck-verify-ocaml-merlin :modes '(caml-mode tuareg-mode reason-mode) :predicate (lambda () (and merlin-mode - ;; Don't check if there is not a 'dune-project' + ;; Don't check if Merlin configuration isn't ;; present somewhere in the directory tree - (and buffer-file-name (locate-dominating-file buffer-file-name "dune-project")) + (flycheck-ocaml-find-merlin-config-dir) ;; Don't check if Merlin's own checking is ;; enabled, to avoid duplicate overlays (not merlin-error-after-save))))