Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable the checker in .merlin presence #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 15 additions & 6 deletions flycheck-ocaml.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))))
Expand Down