I was wondering if anyone else has tried to do this. I recently started working in a project that uses JS Flow. Since flow syntax is quite similar to typescript, I was hoping I could load the typescript parser instead of the javascript one if flow-minor-mode
is active. Only problem, not sure how to do it. I’ve been playing around with the value of tree-sitter-lang
but it doesn’t seem to do much. Anybody else can think of a way? Or if there is an alternative better solution please tell me.
Edit: While writing this post I came around this:
(defun tree-sitter--setup ()
"Enable `tree-sitter' in the current buffer."
(unless tree-sitter-language
;; Determine the language symbol based on `major-mode' .
(let ((lang-symbol (alist-get major-mode tree-sitter-major-mode-language-alist)))
(unless lang-symbol
(error "No language registered for major mode `%s'" major-mode))
(setq tree-sitter-language (tree-sitter-require lang-symbol))))
(unless tree-sitter-parser
(setq tree-sitter-parser (tsc-make-parser))
(tsc-set-language tree-sitter-parser tree-sitter-language))
(add-hook 'before-change-functions #'tree-sitter--before-change :append :local)
(add-hook 'after-change-functions #'tree-sitter--after-change :append :local))
Seems like modifying tree-sitter-major-mode-language-alist
is the way to go, maybe I’ll make a derived major mode for flow files and register it to use typescript. I’ll update the post when I try that with the results.