From 9eb77f1cc1e93e0ab03a0c44ffd05e520d3c0ccd 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. --- CHANGES.md | 3 +++ flycheck-ocaml.el | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 69b3ed5..adddd3d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,9 @@ ## master (unreleased) +- Since there are projects that use build systems other than Dune, we + are opting to look for either `dune-project` or `.merlin`. + ## 0.4.2 (2022-07-29) - Turns out Dune 2.8 stopped generating `.merlin` files (see [this article](https://tarides.com/blog/2021-01-26-recent-and-upcoming-changes-to-merlin)) - now we look for `dune-project` instead. 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))))