; This Source Code Form is subject to the terms of the Mozilla Public ; License, v. 2.0. If a copy of the MPL was not distributed with this ; file, You can obtain one at https://mozilla.org/MPL/2.0/. (import-macros {: callback} :clojure-nvim.util-macros) (local {: get-package-path} (require :clojure-nvim.fs)) (local lsp (require :clojure-nvim.lsp)) (local M {}) (local ts-clj-dir (get-package-path "vendor" "tree-sitter-clojure")) (fn M.compile-parser [] "Attempts to call `tree-sitter` to build the vendored grammar, and then move it to `parser/clojure.so`" (vim.notify "Compiling tree-sitter-clojure parser" vim.log.levels.INFO) (let [ok (: (vim.system ["tree-sitter" "build" "-o" "../../parser/clojure.so"] {:cwd ts-clj-dir :text true}) :wait)] (if ok true (do (vim.notify "Error in building parser" vim.log.levels.ERROR) false)))) (fn M.initialize-ts [] (vim.api.nvim_create_autocmd [:FileType] {:group (vim.api.nvim_create_augroup :clojure-nvim-ts {:clear true}) :pattern "clojure" :callback (callback [] (vim.treesitter.start) nil)})) (local default-config {:compile true :register true :lsp {:enable true :register-keymaps true :register-commands true :config {:cmd ["clojure-lsp"] :filetypes ["clojure"] :root_markers ["project.clj" "deps.edn" "build.boot" "shadow-cljs.edn" "bb.edn" ".git"] :init_options {:log-path "/tmp/clojure-lsp.out"} :trace "verbose"}}}) (λ M.setup [?config] "To be called by the user" (let [cfg (vim.tbl_deep_extend :force default-config (or ?config {}))] (when (and (. cfg :compile) (not (vim.uv.fs_stat (get-package-path "parser" "clojure.so")))) (M.compile-parser)) (when (. cfg :register) (M.initialize-ts)) (when (. cfg :lsp :enable) (lsp.initialize cfg)))) M