Help testing Julia tree-sitter mode in Emacs

Anyone working on adding Julia support to combobulate?

2 Likes

This screenshot looks amazing. Is the completion from LSP or from this tree-sitter package?

The completion candidates are likely being powered by eglot, which is the LSP client that is now built into the 29 release of emacs. The pop up ui itself will be either company or corfu.

2 Likes

Got you. Thanks.

Hi @linwaytin !

The popup is company, which receives information from the LSP as @jcmkk3 said. However, I am using lsp-mode instead of eglot. I have never been able to make eglot works with Julia for some strange reason.

1 Like

Thank you!

I asked because I remember the LSP server for julia is very slow. I tried it some years ago and the experience is not good. Do you think it’s usable now?

I use eglot + corfu, and find the experience good.

1 Like

Yes, the experience was very slow but it got much better now. It is not perfect yet, but I use it daily without problems.

2 Likes

Awesome! It’s the time to try it again.

Hi, I am trying/enjoying the Julia tree-sitter on Emacs. Nice work. However, is there a specific config to get the indentation works properly? Right now, auto-indent works only if I write the begin and end of a block and then go and press enter at the end of the lines inside the block.

Hi!

I am not sure if this can be “fixed”. The tree sitter grammar does not identify the blocks until you add “begin” (or if, else, while, etc) and end. Hence, emacs does not know that it must apply an indentation to that code. I have no ideia how can we workaround.

I see. Maybe one can use snippets to add the “end” keyword automatically. Then tree-sitter should be able to take care of the indentation inside the block.

Could someone post a workable .emacs? I cannot get going… Thanks!

2 Likes

Recently, I built Emacs on a new system, and since then, julia-ts-mode does not show different colors for the source code. Upon checking the messages, I see the following errors. Does anyone have an idea what is missing?

Treesitter context fold mode cannot be enabled.
[eglot] Waiting in the background for server EGLOT (esi/(julia-mode ess-julia-mode julia-ts-mode))' Error during redisplay: (jit-lock-function 1) signaled (treesit-query-error "Node type error at" 177 "(assignment (identifier) @font-lock-variable-name-face (_)) (assignment (field_expression (identifier) \".\" (identifier) @font-lock-variable-name-face) (operator)) (assignment (bare_tuple (identifier) @font-lock-variable-name-face)) (assignment (bare_tuple (field_expression (identifier) \".\" (identifier) @font-lock-variable-name-face)) (operator)) (local_statement (identifier) @font-lock-variable-name-face) (let_binding (identifier) @font-lock-variable-name-face) (global_statement (identifier) @font-lock-variable-name-face)" "Debug the query with treesit-query-validate’")

1 Like

Sounds like you’re running into Displaying Julia files using julia-ts-mode fails on Emacs 30.0.5 · Issue #21 · JuliaEditorSupport/julia-ts-mode · GitHub. Help fixing it would of course be appreciated.

2 Likes

Hi @ehsani63 !

Are you using Emacs 29 or 30?

It seems that the grammar has changed, leading to some errors (this kind of problem is particularly difficult to debug in Emacs only by those debugging messages…). Unfortunately, I do not use Emacs anymore and it will take sometime until I can setup the environment to debug it myself.

I have already transferred the julia-ts-mode repository to the org JuliaEditorSupport and hopefully someone will be able to help us here :slight_smile:

2 Likes

In Neovim, the tree-sitter plugin decides what version of the grammar to use. Does it work the same way in Emacs?

EDIT: I see that GitHub - renzmann/treesit-auto: Automatic installation, usage, and fallback for tree-sitter major modes in Emacs 29 is used to install the grammar. This isn’t ideal because it’s very easy to have version mismatches. Ideally the mode should list the last tag that works correctly, so the installer knows the correct version to install (nvim-treesitter tracks the latest commit).

1 Like

Do not know if it would help at all, but see Helix’s (www.helix-editor.com) implementation of tree-sitter.

To be clear, julia-ts-mode merely assumes that a compatible grammar is installed but doesn’t itself install any grammar. Installing the grammar is the user’s responsibility, but treesit-auto is suggested as an option.

Obviously something needs to change if the recommended way of installing the grammar installs an incompatible version, but it’s not julia-ts-mode itself misbehaving. Maybe the correct change is to have julia-ts-mode manage the grammar installation itself, but that sounds like a massive pain to do correctly in a cross-platform way.

TLDR: .dll hell

1 Like

Yeah, I didn’t mean to imply julia-ts-mode should install the grammar, but rather that it should store metadata so the installer knows the version it needs to install. It’s a very bad idea to install HEAD unconditionally.

In nvim-treesitter, there’s a json file with the latest commit of each parser that is known to work with the queries in the repo. Since there’s no emacs tree-sitter mono-repo, you’d need a different approach. But the principle is the same.

1 Like