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

feat(lua)!: switch from our fork to MunifTanjim's #2272

Merged
merged 1 commit into from
Jan 18, 2022
Merged

feat(lua)!: switch from our fork to MunifTanjim's #2272

merged 1 commit into from
Jan 18, 2022

Conversation

clason
Copy link
Contributor

@clason clason commented Jan 16, 2022

also take queries from https://github.com/MunifTanjim/nvim-treesitter-lua/tree/main/queries/lua

@MunifTanjim (it would help if you could summarize the advantages of your parser over the old one in a comment).

BREAKING CHANGE: queries are not compatible; modules will have to update

queries/lua/folds.scm Outdated Show resolved Hide resolved
@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

Test failures are due to upstream queries missing

  1. builtin functions highlighting
  2. indentation

as well as a (new?) Markdown test fail.

@MunifTanjim
Copy link
Contributor

Well, wow! That happened fast! 😂

it would help if you could summarize the advantages of your parser over the old one in a comment

Let me take it from my comment on reddit.


Block Comment/String

The old one didn't have separate nodes for block comment/string start/end. Since lua's block comment/string's start/end can be of arbritary length (e.g. [=[ or [======[, you get the idea), having separate nodes for them helps when you're writing query that targets string content (e.g. injections queries).

It also had some bugs handling these block comments/strings.

Table access

tbl.a["b"]:c()

Old parser:

(program
  (function_call
    (field_expression
      (identifier)
      (property_identifier))
    (string)
    (method)
    (arguments)))

This parser:

(chunk
  (function_call
    name: (method_index_expression
      table: (bracket_index_expression
        table: (dot_index_expression
          table: (identifier)
          field: (identifier))
        field: (string))
      method: (identifier))
    arguments: (arguments)))

If you're using the generated tree-sitter ast to do refactoring or some complex stuff in a script, these extra information will surely help.

Expression vs Statement

The old parser doesn't abide by some rules of lua about what is an expression and what is a statement and where can those go. For example:

Old parser:


42

---

(program
  (expression (number)))

Would not show any error and accept a whole line that's an expression.

This parser:


42

---

(chunk
  (ERROR (number)))

Would show error, because this is not valid Lua.

Tests

This one has corpus tests for various edge cases and parses the whole luvit/luvit repository (more can be added) as part of testing.

@MunifTanjim
Copy link
Contributor

indentation

I didn't get satisfactory result for indents queries. That's why I didn't push it. Here's a related discussion:

Here's the indents.scm file sitting on my disk:

[
  (function_definition)
  (variable_declaration)
  (field)
  (do_statement)
  (while_statement)
  (repeat_statement)
  (if_statement)
  (for_statement)
  (return_statement)
  (table_constructor)
  (arguments)
  (block)
] @indent

(comment) @ignore

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

Here's the indents.scm file sitting on my disk:

yoink!

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

One thing I worry about is that the query coverage seems to be a bit of a regression compared to what we had. It might be better to start from our queries and just adapt them where necessary?

@MunifTanjim
Copy link
Contributor

One thing I worry about is that the query coverage seems to be a bit of a regression compared to what we had. It might be better to start from our queries and just adapt them where necessary?

I haven't checked the current queries in nvim-treesitter/nvim-treesitter/queries/lua for a while. I just checked and seems like only highlights.scm is lacking a bit. Pushing it in a few minutes.

@theHamsta
Copy link
Member

@MunifTanjim should we Auto-Import the queries from your repo (curl during parser update CI) assuming that they're made for Neovim?

@theHamsta
Copy link
Member

We should also check the queries in nvim-treesitter-textobjects before merging this

@theHamsta
Copy link
Member

Test failure comes probably from hocon or something unrelated and can be ignored

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

@MunifTanjim should we Auto-Import the queries from your repo (curl during parser update CI) assuming that they're made for Neovim?

That would include moving the queries from the separate plugin to the parser repo (which should be obsolete once we make the switch).

We should also check the queries in nvim-treesitter-textobjects before merging this

I would have made a PR after this gets merged.

Test failure comes probably from hocon or something unrelated and can be ignored

No, there are definitely Lua failures. It seems that indentation with this parser doesn't really work.

@MunifTanjim
Copy link
Contributor

@MunifTanjim should we Auto-Import the queries from your repo (curl during parser update CI) assuming that they're made for Neovim?

If this PR is merged, there's no point in maintaining the MunifTanjim/nvim-treesitter-lua repo. I'll archive that repo in that case. So, nope.

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

If this PR is merged, there's no point in maintaining the MunifTanjim/nvim-treesitter-lua repo. I'll archive that repo in that case. So, nope.

I think @theHamsta meant that you would maintain queries in the parser repo, and we would pull them from there. Other parsers do similar things. This way, you could make improvements without needing to PR to this repo.

@MunifTanjim
Copy link
Contributor

I think @theHamsta meant that you would maintain queries in the parser repo, and we would pull them from there. Other parsers do similar things. This way, you could make improvements without needing to PR to this repo.

Ah, I see. I can do that too. But doesn't it get confusing for the contributors? 🤔 How do they know where to update the queries?

It seems that indentation with this parser doesn't really work.

Just curious, is it Lua in general? or this new parser? As far as I remember I couldn't get proper indentation with the current parser either. I'm just using whatever indentation comes with vim by default for Lua.

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

Ah, I see. I can do that too. But doesn't it get confusing for the contributors? 🤔 How do they know where to update the queries?

We would tell them ;) (Similarly to how in Neovim, we tell people to report/fix bugs with legacy syntax files in Vim.) But it's not necessary; whatever is easiest to maintain.

Just curious, is it Lua in general? or this new parser? As far as I remember I couldn't get proper indentation with the current parser either. I'm just using whatever indentation comes with vim by default for Lua.

I was under the impression that it was the new parser since the indentation tests are not marked as known failures. But I have to admit I did not check myself.

@theHamsta
Copy link
Member

Tests are failing due to Markdown. Sorry, for pushing this to master. Indent tests for Lua might also fail when the new parser is better than the old, then the expected failure need to be updated.

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

The highlight test for Lua is fixed now (thanks, @MunifTanjim). The expected indentation looks like correct indentation, though, while the found indentation is wrong? I also checked master, and the failures are not there. So this looks like a definite regression.

@MunifTanjim
Copy link
Contributor

We would tell them ;) (Similarly to how in Neovim, we tell people to report/fix bugs with legacy syntax files in Vim.) But it's not necessary; whatever is easiest to maintain.

I think these queries are pretty stable and won't change that much in future. So I'd prefer archiving the MunifTanjim/nvim-treesitter-lua repo.

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

We would tell them ;) (Similarly to how in Neovim, we tell people to report/fix bugs with legacy syntax files in Vim.) But it's not necessary; whatever is easiest to maintain.

I think these queries are pretty stable and won't change that much in future. So I'd prefer archiving the MunifTanjim/nvim-treesitter-lua repo.

OK, let's keep them here then. PRs for improving them are still appreciated :)

@clason
Copy link
Contributor Author

clason commented Jan 16, 2022

@vigoux (and others) I think this is getting to the point where it'd be good if people familiar with the old parser would test-drive it for a bit and see if there are any noticeable regressions.

also take queries from https://github.com/MunifTanjim/nvim-treesitter-lua/tree/main/queries/lua

BREAKING CHANGE: queries are not compatible; modules will have to update
@clason clason requested a review from vigoux January 18, 2022 18:53
Copy link
Member

@vigoux vigoux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big green tick on this one, thanks!

@clason
Copy link
Contributor Author

clason commented Jan 18, 2022

If @vigoux says it's good, it's good :)

Do we need some sort of "breaking changes" issue where we mention the switch?

@vigoux
Copy link
Member

vigoux commented Jan 18, 2022

Hmm... I think that the language support issue could do it?

@clason
Copy link
Contributor Author

clason commented Jan 18, 2022

No, that's for something different. I'm talking about something like the "Following HEAD" issue on Neovim where breaking changes are mentioned and migration paths are explained.

Like "new parser, please make sure to update queries"

@theHamsta
Copy link
Member

Yes, would be good for people to subscribe. Lanugage support would mix-up feature requests with breaking change notification.

I suposse we need to fix also nvim-treesitter-textobjects for this one (or remove the Lua queries as a quickfix.

Copy link
Member

@theHamsta theHamsta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Also the syntax tree is now tidied up also for Lua

@clason
Copy link
Contributor Author

clason commented Jan 18, 2022

Yes, would be good for people to subscribe. Lanugage support would mix-up feature requests with breaking change notification.

Agreed; I'll open up such an issue and pin it.

I suposse we need to fix also nvim-treesitter-textobjects for this one (or remove the Lua queries as a quickfix.

Yep, that was my next todo; luckily, @MunifTanjim's repo already contains replacement queries.

(This leaves nvim-treesitter-textsubjects, but that's third-party.)

@clason clason merged commit c80715f into nvim-treesitter:master Jan 18, 2022
@clason clason deleted the switch-lua branch January 18, 2022 21:15
gravndal added a commit to gravndal/nixpkgs that referenced this pull request Jan 24, 2022
This keeps it in sync with what has been done in nvim-treesitter:
nvim-treesitter/nvim-treesitter#2272
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

Successfully merging this pull request may close these issues.

None yet

4 participants