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

Indentation does not seem to work #17

Open
Susensio opened this issue Feb 1, 2023 · 3 comments
Open

Indentation does not seem to work #17

Susensio opened this issue Feb 1, 2023 · 3 comments

Comments

@Susensio
Copy link

Susensio commented Feb 1, 2023

I have treesitter installed and enabled, fish language installed and indentation enabled for all languages.
How ever, fish files don't get automatic indentation. That is, if I type

if true

and press Enter, I get a cursor in the same indent as i:

if true
|

when the correct cursor should be indented:

if true
    |

Before migrating to treesitter, I used dag/vim-fish and indentation worked.
Indentation in other languages works.

Is this a problem with this language spec? How can I help debug and solve this?

@taekwombo
Copy link
Contributor

When your example is parsed the following tree is the result:

(program [0, 0] - [1, 0]
  (ERROR [0, 0] - [1, 0]
    (command [0, 3] - [0, 7]
      name: (word [0, 3] - [0, 7]))))

In nvim-treesitter the indent capture name is defined for some nodes but none of the above is among them.

In order for the indent to work, end is needed so that the source file produces valid tree when parsed.

if test|
end
# After enter
if test
    |
end

In order for your example if test to work this grammar would need to be more relaxed.
Probably rewritten with such use cases in mind in the first place.

@Susensio
Copy link
Author

Susensio commented Feb 1, 2023

Thank you for your response. Could this be achieved somehow? Or is this impossible for treesitter?

@taekwombo
Copy link
Contributor

One way to achieve indent working for your example is to update indent.scm queries.
Here is an example of such query with ERROR node for python:

https://github.com/nvim-treesitter/nvim-treesitter/blob/4cc201ecd9840562ed8822af607966e3303df228/queries/python/indents.scm#L34

If you have time to play around with nvim-treesitter and see if you can create such query so the indent works see:

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

No branches or pull requests

2 participants