tree-sitter: tree-sitter highlight has does not find the language.
I wanted to try out tree-sitter highlight
but it seems like it has a near impossible time figuring out what language to use. For example, attempting to run tree-sitter highlight .\examples\jquery.js
for tree-sitter-javascript yields No language found for path ".\\examples\\jquery.js"
.
Repro on Linux:
git clone --depth=1 https://github.com/tree-sitter/tree-sitter-javascript
cd tree-sitter-javascript
npm i
./node_modules/tree-sitter-cli/tree-sitter highlight ./examples/jquery.js
# yields
# No language found for path "./examples/jquery.js"
Despite that, tree-sitter test
is able to run the highlighter tests just fine.
I’ve tried to get syntax highlighting working in my project, but have had no luck getting either the highlighting tests or the highlight command to work. Hopefully this issue can help shed some light on this problem.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 35 (14 by maintainers)
Things that worked for me in the past.
First. See the path of the config file with
tree-sitter init-config
Now, see if the
"parser-directories" in the
config.json`` is set correctly:If your grammar is at
/home/foo/git/tree-sitter-go/src/parser.c
theparser-directories
should include/home/foo/git
.Does it show when you run
tree-sitter dump-languages
?See if there is any file path on
tree-sitter-go/package.json
and check if they are correctly set (might try to include some file that doesn’t exist).Lastly, you can try running
tree-sitter generate
attree-sitter-go
. I had issues fix themselves after running this (might have been a coincidence).After adding the correct path (for future readers - in my case, because the directory I was working in was
~/tree-sitter-javascript
, I had to add~
to theparser-directories
subsection, with the config file located at~/.tree-sitter/config.json
after running./tree-sitter init-config
), it does!It seems odd that tree-sitter doesn’t use the same behavior it does for
tree-sitter test
when looking for a highlighter to use. Perhaps it should? (I’d be glad to take up a PR to do so)I’m seeing the module I’m trying to author, but it’s output in
dump-languages
looks wrong. Ringing my head after following the docs and suggestions here. I’ve tried both the local and globally installed tree-sitter, both giving the same results.~Any thoughts or suggestions that could help here?~
The issue was that I did not make the entry in
package.json
a list…@ahlinc Nope, it works fine on the upstream CLI. Now I’m just getting
ERROR
AST nodes without any explanation or what was expected.@ahlinc I fixed it, my JSON file had a syntax error. (Oops?)
Issue summary
tree-sitter highlight
andtree-sitter test
don’t behave in the same way."parser-directories"
in the config file (that’s the solution)Preferred solution
I hope this helps
TODO:
tree-sitter generator
that would show suggestions and in this case it will suggest to set thescope
field assource.LANG_NAME
by meaning that it’s best practice to to name languages with thesource.
prefix.tree-sitter parser
error output suggestions what to check to resolve the issue.tree-sitter-loader select_language(...)
behaviour. Actually done, but needs public PR.Thanks @alemuller I didn’t think to try
tree-sitter dump-languages
. It does find the language but I noticed all languages havehighlights: None
, per following terminal dump:Is that a clue? The rest seems to check out. I did try
tree-sitter generate
as well (again) but still the same thread panic.