Skip to content

Commit 0c63175

Browse files
committed
fix(treesitter): make highlighting work out of the box
Two independent bugs were preventing treesitter highlighting from attaching to .lf buffers on a fresh install: 1. Parser fallback path was not on the runtime path. get_parser_install_dir() fell back to stdpath("data") .. "/parser" (~/.local/share/nvim/parser), but Neovim only auto-loads parsers from {rtp}/parser/*.so, and the user data dir itself is not in rtp — only its "site" subdir is. The file was written to disk but Neovim never saw it, so vim.treesitter.language.inspect("lf") kept failing. Fall back to stdpath("data") .. "/site/parser" instead, matching where other parsers (e.g. python, tmux) are installed. Also update uninstall() to clean up the legacy wrong location. 2. Several query patterns referenced node fields/tokens that don't exist in the grammar, which caused vim.treesitter.start() to throw and disabled all highlighting: - highlights.scm: "widthof" -> "widthof(" (token includes paren), imported_reactor class:/alias: -> reactor_class:/name:, key_value_pair key: -> name: - locals.scm: imported_reactor alias: -> name: - textobjects.scm: method body: -> code:, deadline handler: -> code:
1 parent 84e26e7 commit 0c63175

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

lua/lf/treesitter.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ local function get_parser_install_dir()
9393
end
9494
end
9595

96-
-- Fall back to user data directory (always writable)
97-
local data_parser = vim.fn.stdpath("data") .. "/parser"
96+
-- Fall back to user data directory (always writable; must be under site/
97+
-- so that it's picked up via runtimepath)
98+
local data_parser = vim.fn.stdpath("data") .. "/site/parser"
9899
vim.fn.mkdir(data_parser, "p")
99100
return data_parser
100101
end
@@ -514,10 +515,11 @@ function M.uninstall()
514515
removed = true
515516
end
516517

517-
-- Also clean up any stale queries in site directory (legacy location)
518-
local site_queries = vim.fn.stdpath("data") .. "/site/queries/lf"
519-
if vim.fn.isdirectory(site_queries) == 1 then
520-
vim.fn.delete(site_queries, "rf")
518+
-- Also clean up a stale parser in the legacy location (stdpath("data")/parser
519+
-- is not in runtimepath, so parsers installed there were never loaded).
520+
local legacy_parser = vim.fn.stdpath("data") .. "/parser/" .. parser_lib_name()
521+
if vim.fn.filereadable(legacy_parser) == 1 then
522+
vim.fn.delete(legacy_parser)
521523
removed = true
522524
end
523525

tree-sitter-lf/queries/highlights.scm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"after" @keyword
5151
"deadline" @keyword
5252
"at" @keyword
53-
"widthof" @keyword.function
53+
"widthof(" @keyword.function
5454
"interleaved" @keyword
5555
"STP" @keyword
5656
"STAA" @keyword
@@ -147,9 +147,9 @@
147147
; ============================================================================
148148

149149
(imported_reactor
150-
class: (identifier) @type)
150+
reactor_class: (identifier) @type)
151151
(imported_reactor
152-
alias: (identifier) @type)
152+
name: (identifier) @type)
153153

154154
; ============================================================================
155155
; Attributes
@@ -165,9 +165,9 @@
165165
; ============================================================================
166166

167167
(key_value_pair
168-
key: (kebab) @property)
168+
name: (kebab) @property)
169169
(key_value_pair
170-
key: (string) @property)
170+
name: (string) @property)
171171

172172
; ============================================================================
173173
; Time units

tree-sitter-lf/queries/locals.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113

114114
; Import alias
115115
(imported_reactor
116-
alias: (identifier) @local.definition.type)
116+
name: (identifier) @local.definition.type)
117117

118118
; ============================================================================
119119
; References - References to defined variables

tree-sitter-lf/queries/textobjects.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
; Method as function
2020
(method
21-
body: (code_block) @function.inner) @function.outer
21+
code: (code_block) @function.inner) @function.outer
2222

2323
; Deadline handler
2424
(deadline
25-
handler: (code_block) @function.inner) @function.outer
25+
code: (code_block) @function.inner) @function.outer
2626

2727
; Watchdog handler
2828
(watchdog

0 commit comments

Comments
 (0)