tree-sitter / tree-sitter-julia

Julia grammar for tree-sitter
MIT License
95 stars 33 forks source link

Make `_block` a visible scope #73

Open ChrHorn opened 1 year ago

ChrHorn commented 1 year ago

Most languages make their blocks inside functions, classes, etc visible.

This added visible scope would make targeting the inside/body of a function much easier. Textobjekt queries that do this are currently very cumbersome to do.

The other advantage is tree-sitter based expanding/shrinking selection. Currently it is expression -> whole function with this change it would be expression -> function body -> whole function It would be much easier to select these code blocks without selecting the surrounding syntax.

I think just changing everything to block should be fine. The exception would be the top scope. Here we already have source_file, so an additional scope is not needed.

ronisbr commented 1 year ago

This modification will be very welcome for Emacs. I am trying to design a Julia major mode (https://github.com/ronisbr/julia-ts-mode) and without this feature the automatic indentation will not work very well. For example, if we type:

function test(a)
end

And then press enter after ), the cursor will start at the beginning of the line because there is no node inside the function body. Hence, we cannot apply an indentation rule in Emacs at least.

haberdashPI commented 1 day ago

I see this has the label "help wanted".

What is involved here? It seems like this could be as simple as adding field('body', ...) to e.g. function_definition.

I don't know much about the build setup for this repo, but I am happy to try to take a stab at this if I can get some information about what is involved in going from making a change in grammar.js and having build artifacts available.