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

Unable to use parser for indentation with significant whitespace syntax #173

Open
ckipp01 opened this issue Jan 20, 2023 · 3 comments
Open
Labels

Comments

@ckipp01
Copy link
Collaborator

ckipp01 commented Jan 20, 2023

Commit of tree-sitter-scala you tested this on

97d5e7c

A code sample showing the error

object Main:

Show the error node

So this is sort of a discussion, but also something that I think we'll need to change if we want to support indents. The issue is that in the above code sample the tree at that point would look like this:

object_definition [0, 0] - [0, 11]
  "object" [0, 0] - [0, 6]
  name: identifier [0, 7] - [0, 11]
ERROR [0, 11] - [2, 0]
  ":" [0, 11] - [0, 12]

If your cursor is here:

object Main:<cursor>

And you hit <enter> then you'd expect it to be indented. An indent query for this would look like this:

[
  (object_definition)
] @indent

From the nvim-treesitter docs it says:

@indent ; indent children when matching this node

The project is that this won't match here since the ERROR node isn't a child of the object_definition and : is actually a child of the current ERROR node.

Realistically even if you have an opening { you have the same issue:

object_definition [0, 0] - [0, 11]
  "object" [0, 0] - [0, 6]
  name: identifier [0, 7] - [0, 11]
ERROR [0, 12] - [0, 13]
  "{" [0, 12] - [0, 13]

But since the vast majority of editors will give you a closing } by default it will really look like this:

object_definition [0, 0] - [0, 15]
  "object" [0, 0] - [0, 6]
  name: identifier [0, 7] - [0, 11]
  body: template_body [0, 12] - [0, 15]
    "{" [0, 12] - [0, 13]
    "}" [0, 14] - [0, 15]

Meaning that you're in object_definition, so the <enter> will indent like you'd expect.

What do you expect the tree to look like

I'd expect that when you have the following:

object Main:<cursor>

And I hit <enter> there is a way that we can indent correctly.

Where are you experiencing this error?

nvim-treesitter

@susliko
Copy link
Collaborator

susliko commented May 30, 2023

@ckipp01 🖖🏻
I haven't found a way to influence the position of ERROR node in the tree.
However, we can write a query for what we have now, i.e. match the ERROR node! The following one seems to solve the described issue:

((ERROR ":") @indent.align (#set! indent.open_delimiter ":")) 

or, specifically for object definitions:

((object_definition) (ERROR ":") @indent.align (#set! indent.open_delimiter ":")) 

Inspired by Python indents.scm

@susliko susliko mentioned this issue Mar 10, 2024
@KaranAhlawat
Copy link
Contributor

KaranAhlawat commented Aug 12, 2024

One problem I run into is that after inserting the :, if I hit return, the node detected at point can be either no node, or an (ERROR ":") node, which is kinda weird. This is on emacs, and I'm kinda sure it's Emacs doing something. Will look into it further Seems to be an emacs thing, please disregard

@susliko
Copy link
Collaborator

susliko commented Aug 18, 2024

Adding indents to nvim-treesitter: nvim-treesitter/nvim-treesitter#7056

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants