helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.49k stars 2.48k forks source link

support for jai #11845

Open EriKWDev opened 2 weeks ago

EriKWDev commented 2 weeks ago

I've tried adding language support for jai using the lsp https://github.com/SogoCZE/Jails and tree-sitter grammar at https://github.com/SogoCZE/tree-sitter-jai, but I can't get it to work. Nothing gets highlighted in the editor, and this is the error messages in the helix log

2024-10-07T08:05:27.905 helix_lsp::transport [ERROR] jails err: <- StreamClosed
2024-10-07T08:05:29.600 helix_core::syntax [ERROR] Failed to load tree-sitter parser for language "jai": Failed to load symbol tree_sitter_jai

I have added the following to the languages.toml

[[language]]
name = "jai"
scope = "source.jai"
file-types = ["jai"]
roots = ["jails.json", "build.jai", "first.jai"]
shebangs = ["jai", "jai-linux"]
language-servers = [
  "jails"  
]
indent = { tab-width = 4, unit = " " }
grammar = "jai"

[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'"' = '"'
'`' = '`'

[[grammar]]
name = "jai"
source = { git = "https://github.com/SogoCZE/tree-sitter-jai", rev="dd2d38d44bf71a0db95c7e745f86b06c3aa7e4d6" }

[language-server.jails]
command = "jails"
args = ["-jai_path", "~/Downloads/jai/current/bin/jai-linux"]

And without knowing much about the setup I did minimal modifications to the runtime/queries/odin stuff and put into a runtime/queries/jai folder. grammars have been fetched and built and seem to be identified correctly, just don't work

Byteron commented 2 weeks ago

I tried this a few days ago, I did get the LSP to work, but syntax highlighting I did not get working.

[language-server.jails]
command = "jails"

[[language]]
name = "jai"
scope = "source.jai"
injection-regex = "jai"
file-types = ["jai"]
comment-tokens = "//"
language-servers = [ "jails" ]

[[grammar]]
name = "jai"
source = { git = "https://github.com/St0wy/tree-sitter-jai", rev = "35c0d66c772900eae3d36b996672884960e35477" }

with this LSP works, (it does still output the same error for me, but jump to definition etc still works) just the [[grammar]] bit does not work as mentioned.

Byteron commented 2 weeks ago

I had just read on the odin tree sitter page that tree sitter stuff needs to be defined at compile time and a helix rebuild is required. Is that true, or is that perhaps an outdated information?

EriKWDev commented 2 weeks ago

I tried your config with the different tree-sitter implementation and indeed I get rudimentary highlighting and goto definition working!

I copied https://raw.githubusercontent.com/St0wy/tree-sitter-jai/refs/heads/main/queries/highlights.scm and putting it in runtime/queries/jai I also get some very basic highlighting though it seems to fall apart pretty quickly on multi-line comments and confusing some number-literals for types.

Don't know if this is just the state of the project or what to expect

I did try to recompile as you said but not with my modified odin stuff so don't know if that did anything in particular or not

the-mikedavis commented 2 weeks ago

The issue is the capital J in Jai here: https://github.com/SogoCZE/tree-sitter-jai/blob/dd2d38d44bf71a0db95c7e745f86b06c3aa7e4d6/grammar.js#L2

That needs to be lowercase to match name = "jai" in the [[grammar]] section. It might work (I haven't tested this) to use name = "Jai" in languages.toml instead but the convention with all other tree-sitter grammars is to use lowercase for the name so I would recommend suggesting this change upstream