commit e10785f5516fb14e42f49815b28f8f02e12876b2
parent edf84bc80a03d565365500477d349b8ed532d79d
Author: mtmn <miro@haravara.org>
Date: Fri, 10 Apr 2026 07:37:31 +0200
nvim: fix treesitter
Diffstat:
4 files changed, 80 insertions(+), 20 deletions(-)
diff --git a/modules/mixins/dotfiles/config/nvim/TREESITTER.md b/modules/mixins/dotfiles/config/nvim/TREESITTER.md
@@ -0,0 +1,73 @@
+# Neovim 0.12+ Tree-sitter Manual
+
+In Neovim 0.12 and later, Tree-sitter support is deeply integrated into the core. While plugins like `nvim-treesitter` provide management commands, Neovim itself handles the loading of parsers and queries through the standard **runtimepath (RTP)** mechanism.
+
+## 1. Storage Location
+
+By default, Neovim looks for Tree-sitter assets in any directory listed in your `runtimepath`. The standard user-writable location for these is:
+
+`~/.local/share/nvim/site/` (or `stdpath('data') .. '/site'`)
+
+### Directory Structure
+```text
+~/.local/share/nvim/site/
+├── parser/ # Compiled grammar libraries (.so or .dll)
+│ ├── fennel.so
+│ ├── purescript.so
+│ └── ...
+├── parser-info/ # Metadata used by management tools (optional)
+│ ├── fennel.lua
+│ └── ...
+└── queries/ # Tree-sitter query files (.scm)
+ ├── fennel/
+ │ ├── highlights.scm
+ │ ├── folds.scm
+ │ └── injections.scm
+ └── purescript/
+ └── highlights.scm
+```
+
+## 2. Discovery Mechanism
+
+Neovim discovers Tree-sitter assets by searching for specific subdirectories in the RTP:
+
+1. **Parsers**: It looks for a `parser/` directory and attempts to load `<language>.so`.
+2. **Queries**: It looks for `queries/<language>/` and loads `.scm` files (e.g., `highlights.scm`, `folds.scm`, `indents.scm`).
+
+You can verify if a directory is in your RTP by running:
+```vim
+:set runtimepath?
+```
+
+## 3. Manual Installation
+
+If you want to install a parser manually without a plugin:
+
+1. **Compile the Parser**: Use the `tree-sitter` CLI or a C compiler to generate a shared object (`.so`) from the grammar's `src/parser.c` (and `src/scanner.c` if it exists).
+2. **Move the Parser**: Place the `.so` file in `~/.local/share/nvim/site/parser/<lang>.so`.
+3. **Install Queries**: Copy the `.scm` files from the grammar's `queries/` directory (ensure they are compatible with Neovim) into `~/.local/share/nvim/site/queries/<lang>/`.
+
+## 4. Configuration and Activation
+
+Since Neovim 0.12 does not enable Tree-sitter automatically for every file, you should use an autocommand in your `init.lua` (or Fennel equivalent) to start the parser:
+
+```lua
+vim.api.nvim_create_autocmd('FileType', {
+ callback = function()
+ local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
+ if lang and pcall(vim.treesitter.language.inspect, lang) then
+ vim.treesitter.start(0, lang)
+ -- Optional: Enable folding
+ vim.wo.foldmethod = 'expr'
+ vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
+ end
+ end,
+})
+```
+
+## 5. Useful Commands
+
+- `:lua =vim.treesitter.language.inspect("fennel")`: Check if a language parser is correctly loaded.
+- `:lua =vim.treesitter.get_parser(0):parse()`: Force a re-parse of the current buffer.
+- `:InspectTree`: Open a window showing the syntax tree (built-in to Neovim 0.10+).
+- `:EditQuery`: Open the query editor for the current language.
diff --git a/modules/mixins/dotfiles/config/nvim/fnl/config/blink.fnl b/modules/mixins/dotfiles/config/nvim/fnl/config/blink.fnl
@@ -6,7 +6,6 @@
:<C-p> [:select_prev :fallback]
:<C-n> [:select_next :fallback]
:<C-b> [:scroll_documentation_up :fallback]
- :<C-b> [:scroll_documentation_up :fallback]
:<C-f> [:scroll_documentation_down :fallback]
:<C-Space> [:show
:show_documentation
diff --git a/modules/mixins/dotfiles/config/nvim/fnl/config/treesitter.fnl b/modules/mixins/dotfiles/config/nvim/fnl/config/treesitter.fnl
@@ -1,24 +1,15 @@
-(local {:nvim_command command :nvim_create_autocmd autocmd} vim.api)
-(local {: keys} (require :std.table))
-(local ts (require :nvim-treesitter))
-(local all-parsers (keys (require :nvim-treesitter.parsers)))
-(fn build []
- (: (ts.install all-parsers) :wait 300000)
- (: (ts.update all-parsers) :wait 300000))
+(local {:nvim_create_autocmd autocmd} vim.api)
-; To force rebuild:
-; rm -rf ~/.local/share/nvim/site
-; (ts.install all-parsers {:force true})
-;; Adapted from https://github.com/nvim-treesitter/nvim-treesitter/discussions/7894
(fn config []
- (local parsers (require :nvim-treesitter.parsers))
- (ts.setup {:highlight {:enable true} :indent {:enable true}})
(autocmd :FileType
{:callback (fn []
(let [lang (vim.treesitter.language.get_lang vim.bo.filetype)]
(when (and lang
- (pcall vim.treesitter.get_parser 0 lang))
+ (pcall vim.treesitter.language.inspect
+ lang))
+ (vim.treesitter.start 0 lang)
+ (set vim.wo.foldmethod :expr)
(set vim.wo.foldexpr
"v:lua.vim.treesitter.foldexpr()"))))}))
-{: build : config}
+{: config}
diff --git a/modules/mixins/dotfiles/config/nvim/fnl/init.fnl b/modules/mixins/dotfiles/config/nvim/fnl/init.fnl
@@ -68,10 +68,6 @@
:branch :master
:config (fn []
(: (require :config.lsp) :config))})
- (use "nvim-treesitter/nvim-treesitter"
- {:branch :main
- :build #(: (require :config.treesitter) :build)
- :config #(: (require :config.treesitter) :config)})
(use "tpope/vim-commentary")
(use "tpope/vim-repeat")
(use "tpope/vim-surround")
@@ -79,6 +75,7 @@
])
(fn init []
+ ((. (require :config.treesitter) :config))
(let [vimrc (.. (vim.fn.stdpath :config) :/init_.vim)
vim-dir (.. (vim.fn.expand "~") :/.vim/)]
(vim.cmd.source vimrc)