Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make _block a visible scope #73

Open
ChrHorn opened this issue Nov 6, 2022 · 4 comments
Open

Make _block a visible scope #73

ChrHorn opened this issue Nov 6, 2022 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ChrHorn
Copy link
Contributor

ChrHorn commented Nov 6, 2022

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

  • end: Lua, Ruby (this was changed recently issue/PR)
  • indent: Python
  • {}: C++, Rust, ...

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
Copy link

ronisbr commented Jan 2, 2023

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.

@savq savq added the enhancement New feature or request label Jan 9, 2023
@savq savq added the help wanted Extra attention is needed label Sep 21, 2024
@haberdashPI
Copy link

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.

@savq
Copy link
Collaborator

savq commented Nov 5, 2024

Updating the grammar is very simple. It just requires renaming _block to block. But this requires changing almost every single test in the repo.

The repo follows the usual structure for a tree-sitter grammar (see Creating parsers). The generated stuff in src is commited straight in the repo because we're in the year 2024 CE and tree-sitter still doesn't have a packaging solution 🙄

@clason
Copy link

clason commented Nov 15, 2024

tree-sitter still doesn't have a packaging solution 🙄

2024 is not yet over

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants