Skip to content

add support for ocaml mli files #250

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

Closed
wants to merge 1 commit into from

Conversation

rmmanseau
Copy link

the ML and MLI files have separate parsers, but appear to share the same highlights.scm file. this change duplicates the file so that emacs can find the queries when using the ocaml-interface grammar. this is necessary to get proper highlighting in interface files. without it, tree-sitter-hl-mode will silently fail to activate in mli files if the language is set to ocaml-interface.

how an interface file looks with the ocaml parser:
image

how an interface file looks with the ocaml-interface parser
image

some additional config is required on the part of the user to ensure that the ocaml-interface parser gets loaded for mli files. I use doom emacs so my configuration looks as follows

(use-package! tuareg
  :init
  (define-derived-mode tuareg-mli-mode tuareg-mode "Tuareg Mli")
  (add-hook! 'tuareg-mli-mode-hook #'tree-sitter!)
  (setq auto-mode-alist (delete '("\\.ml[ip]?\\'" . tuareg-mode) auto-mode-alist))
  (add-to-list 'auto-mode-alist '("\\.ml[p]?\\'" . tuareg-mode))
  (add-to-list 'auto-mode-alist '("\\.mli\\'" . tuareg-mli-mode)))

(after! tree-sitter-langs
  (set-tree-sitter-lang! 'tuareg-mli-mode 'ocaml-interface))

the ML and MLI files have separate parsers, but appear to share the same
highlights.scm file. this change duplicates the file so that emacs can
find the queries when using the ocaml-interface grammar. this is
necessary to get proper highlighting in interface files. without it,
tree-sitter-hl-mode will silently fail to activate in mli files if the
language is set to ocaml-interface.
@rmmanseau
Copy link
Author

addresses #189 (comment)

@rmmanseau
Copy link
Author

configuration snippet provides workaround for #116

@jcs090218
Copy link
Member

jcs090218 commented Oct 3, 2023

Highlighting is good. Do you think we need to add the parser as well? 🤔

tree-sitter-load: Cannot find shared library for language: ocaml-interface

@rmmanseau
Copy link
Author

rmmanseau commented Oct 3, 2023

not sure what you mean. for me, highlighting worked with just this change & the config snippet i posted. ocaml-interface is provided by the same repo as ocaml, and on my system they are both available. I dont think doom emacs is doing any extra configuration to build ocaml-interface on my setup, but I could be wrong.

im a noob to this repo, just thought it would be helpful to post the changes that gave me correct highlighting in mli files :)

@jcs090218
Copy link
Member

jcs090218 commented Oct 4, 2023

I've added ocaml-interface support in #251. Can you see if that works for you?

@rmmanseau
Copy link
Author

rmmanseau commented Oct 7, 2023

just got time to try it out, it does work! I had to change my config snippet a tiny bit tho. thanks for doing a proper fix :)

(use-package! tuareg
  :config        <--------------- this needed to be config instead of init
  (define-derived-mode tuareg-mli-mode tuareg-mode "Tuareg Mli")
  (add-hook! 'tuareg-mli-mode-hook #'tree-sitter!)
  (setq auto-mode-alist (delete '("\\.ml[ip]?\\'" . tuareg-mode) auto-mode-alist))
  (add-to-list 'auto-mode-alist '("\\.ml[p]?\\'" . tuareg-mode))
  (add-to-list 'auto-mode-alist '("\\.mli\\'" . tuareg-mli-mode)))

(after! tree-sitter-langs
  (set-tree-sitter-lang! 'tuareg-mli-mode 'ocaml-interface))

@jcs090218
Copy link
Member

Closing this now since it's working! :)

@jcs090218 jcs090218 closed this Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants