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

refactor: remove nvim-treesitter as a dependency #523

Merged
merged 1 commit into from
Apr 11, 2024
Merged

refactor: remove nvim-treesitter as a dependency #523

merged 1 commit into from
Apr 11, 2024

Conversation

TheLeoP
Copy link

@TheLeoP TheLeoP commented Nov 18, 2023

DONE:

  • refactor
    • copy and refactor functions previously owned by nvim-treesitter and no longer present on their main branch
    • move away from the nvim-treesitter modules based architechture
    • expose lua functions instead of creating keymaps ourselves
    • introduce a TSTextObjects.Range abstraction to deal with: TSNode, range4, range6, lsp_range, vim_range and fake nodes created using the metadata from multiple captures (i.e. @*.outer captures)
  • update README
    • show new keymaps examples using vim.keymap.set directly
  • update docs
    • same as README
  • update tests
  • update scripts
  • add autoformat queries to CI (has also already been done on the master branch)

This addresses #503

Moved to a follow up PR (TODO)

  • cache query results
  • reimplement consistency tests using Lua (python was previously used for this)
  • better define the user interface of the plugin
    • some mappings rhs have the form some_exposed_func while others have the form function() some_exposed_func() end
    • should other interfaces like the previously used user commands be considered?
  • maybe include incremental selection as an, in textobject

@clason
Copy link
Collaborator

clason commented Nov 19, 2023

Thank you for tackling this! I think the best course here is to not merge this to master but make this a new parallel branch main (which will become the default branch when nvim-treesitter itself switches). The goal here is to make this work (only) in concert with the main branch of nvim-treesitter; mixing and matching main and master is not supported.

(This also means we don't have to complete the rewrite in a single PR.)

refactor the code again (to not only used the copied functions from nvim-treesitter)

💯 (and yes, this approach is what I would suggest as well)

check if autocmds on filetype are the best option

Probably not; I would enable this globally with a check for parsers and query that short-circuits them.

Also, it's perfectly fine (and often preferable) to have some global startup code in /plugin; the standard assumption is that the plugin should work without explicitly calling setup if you're fine with default options.

add some kind of on_attach like nvim-treesitter-context (?)

I consider nvim-treesitter-context to be the gold standard right now for a standalone treesitter plugin; I'd try to follow its lead as much as possible. (@lewis6991)

refactor attach.lua

Yes, attach/detach delendam esse. These are obsolete concepts. The assumption is that people enable these different functions themselves, however makes most sense for the functionality.

should vim.treesitter.query.get be cached?

delete configuration fields for keymaps and let users define the keymaps themselves (?)

Yes, definitely! We don't need yet another DSL for setting keymaps. (Although we could talk about reasonable default mappings as opt-in.)

Although possibly this is a special case here; maybe we could discuss instead exposing a single (Lua!) function that is easy to map?

nvim-treesitter is only being used inside of scripts (check-queries, minimal_init and update_readme), is this ok?

That is OK; you need nvim-treesitter (main!) to set up the test environment.

@lewis6991
Copy link
Member

should vim.treesitter.query.get be cached?

Correct me if I'm wrong, but doesn't core already cache this via a weak table?

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.

Are there any plans to keep the commands? We've added them because some users requested them because they wanted to use them in ext mode or for vinyl remappings. Not a strong requirement since all functionality is available via Lua functions, just being curious on what your idea for this PR was.

@theHamsta
Copy link
Member

should vim.treesitter.query.get be cached?

Correct me if I'm wrong, but doesn't core already cache this via a weak table?

I believe you're right, they should be cached. Nvim-treesitter-textobjects might be doing additional caching of the query results if they are using still an own slow algorithm to aggregate query results

@clason
Copy link
Collaborator

clason commented Nov 19, 2023

Are there any plans to keep the commands? We've added them because some users requested them because they wanted to use them in ext mode or for vinyl remappings. Not a strong requirement since all functionality is available via Lua functions, just being curious on what your idea for this PR was.

I think we should take this opportunity to revisit the user API here, with all the lessons learned since. (Not necessarily in this PR.)

My preference would be to start with a clean slate and (re-)add stuff when it is requested with a compelling use case. (User commands are trivial to add in a plugin file, as we do in nvim-treesitter now.)

What I don't want to see again is a custom module for creating keymaps and user commands through setup().

@TheLeoP
Copy link
Author

TheLeoP commented Nov 20, 2023

Thank you for tackling this! I think the best course here is to not merge this to master but make this a new parallel branch main (which will become the default branch when nvim-treesitter itself switches).

How should I tackle this? I see that I can change which branch the PR targets, but I can't select the main branch since it does not exit yet. @clason

@clason clason changed the base branch from master to main November 20, 2023 07:29
@clason
Copy link
Collaborator

clason commented Nov 20, 2023

Now it does :)

@lucario387
Copy link
Member

So make-range was never needed? 😱

@clason
Copy link
Collaborator

clason commented Nov 21, 2023

should vim.treesitter.query.get be cached?

Correct me if I'm wrong, but doesn't core already cache this via a weak table?

Does this mean the memoize in nvim-treesitter (indent, locals) is obsolete now?

@lucario387

This comment was marked as outdated.

@clason
Copy link
Collaborator

clason commented Nov 21, 2023

Nice; want to make a PR to remove it from the main branch? (After local testing, which -- at least for indents -- you're in the best position to do.)

@lucario387
Copy link
Member

Sadly, my previous comment was incorrect.

vim.treesitter.query.{get,parse} is cached, but the result of it is used for memoize of locals of indents, so neovim core's caching is for the parsing, while nvim-treesitter's caching is for the handling of such parse

@clason
Copy link
Collaborator

clason commented Nov 21, 2023

So we will need the same sort of memoization here for the textobjects query results, right?

@lucario387
Copy link
Member

So we will need the same sort of memoization here for the textobjects query results, right?

Would be nice, I don't think there's one right now though

@TheLeoP
Copy link
Author

TheLeoP commented Nov 25, 2023

So make-range was never needed? 😱

I didn't understand the codebase enought to know what make-range does, so I deleted it. I just added it again (because I couldn't make the test pass because parameter.outer in Python uses make-range), sorry :c.

@lucario387
Copy link
Member

lucario387 commented Nov 25, 2023

@TheLeoP basically we create a new node capture from the two node captures that is specified for make-range,

@TheLeoP
Copy link
Author

TheLeoP commented Nov 27, 2023

@clason Is there a specific part of the code left that you would like to be refactored? I still haven't give too much atention to test, docs or scripts, I wanted to focus on the plugin functionality first.

@clason
Copy link
Collaborator

clason commented Jan 7, 2024

@clason Is there a specific part of the code left that you would like to be refactored? I still haven't give too much atention to test, docs or scripts, I wanted to focus on the plugin functionality first.

I think you are right that we should first make sure everything works with nvim-treesitter main and that all tests pass; afterwards it's much easier to make changes one by one (e.g., going through the backported utility functions to see if they can be replaced by Neovim core APIs).

Also, we have an autoformatter for queries now, which could be added to CI here ;)

Copy link
Member

@ObserverOfTime ObserverOfTime left a comment

Choose a reason for hiding this comment

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

Can you keep the keymap configuration in setup?

What I don't want to see again is a custom module for creating keymaps and user commands through setup().

Disregard this comment. :^)

@clason
Copy link
Collaborator

clason commented Jan 8, 2024

No, this comment stands. I want to see the module framework gone. If you want to set keymaps (through this plugin), use the Neovim API directly.

@ObserverOfTime
Copy link
Member

Yes, I didn't mean it should remain a module.

@clason
Copy link
Collaborator

clason commented Feb 10, 2024

@TheLeoP this looks like it's in a good place -- can you take care of the remaining items?

@TheLeoP
Copy link
Author

TheLeoP commented Feb 15, 2024

@clason. Will do. Question: are the current vimdocs generated? Or do they have to be manually updated?

@clason
Copy link
Collaborator

clason commented Feb 15, 2024

They are manually written. It's OK to have a minimal (but correct) version for the initial PR.

@TheLeoP
Copy link
Author

TheLeoP commented Feb 15, 2024

Is it expected to document the lua API being used for keymaps on the vimdocs/README?

@mehalter

This comment was marked as off-topic.

@clason
Copy link
Collaborator

clason commented Feb 19, 2024

You can use nvim -l to run Lua scripts. To install all parsers, use (an adapted copy of) https://github.com/nvim-treesitter/nvim-treesitter/blob/main/scripts/install-parsers.lua

(Also, you can't unfortunately trust the check marks for the Python tests. We may need to remove them and punt proper -- native Lua -- unit tests to a follow-up PR.)

README.md Outdated Show resolved Hide resolved
@TheLeoP
Copy link
Author

TheLeoP commented Apr 9, 2024

The query files test is working again c:, but the python tests seem to be broken indeed and I don't know enought python to look into them.

I wouldn't like to keep blocking this PR. @clason would it be ok to remove the python tests, as you mentioned, and move native lua test to a follow up PR?

@TheLeoP TheLeoP requested a review from clason April 9, 2024 05:04
@TheLeoP
Copy link
Author

TheLeoP commented Apr 10, 2024

This PR should be ready to merge

@clason
Copy link
Collaborator

clason commented Apr 10, 2024

Can you squash your commits and update the PR/commit message (what's changed, what's still todo)? Then I'll merge.

@TheLeoP
Copy link
Author

TheLeoP commented Apr 10, 2024

I've squashed all my commits and updated the PR and commit messages. Let me know if there is something else I may be missing

@clason
Copy link
Collaborator

clason commented Apr 10, 2024

You may need to rebase on main as well (rebase -i main and drop all but your commit), otherwise the merge won't be clean.

@clason
Copy link
Collaborator

clason commented Apr 10, 2024

Guess we need to rebase on master. Let me try to do this properly, you don't have to worry about it.

details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check #523 for more info
@clason clason merged commit cc42781 into nvim-treesitter:main Apr 11, 2024
4 checks passed
@clason
Copy link
Collaborator

clason commented Apr 11, 2024

Ok, CI is green.

@TheLeoP Before you delete (or pull!) your branch, please check the diff here against your local changes to make sure I did not force-push some of them away (in which case, please make a follow-up PR from latest main). Thank you so much for tackling this and for your patience through the (too) long process!

I'm looking forward to follow-up PRs (by you and other interested parties) cleaning up the old legacy design and adding a proper keymap setup (@ObserverOfTime).

@kiyoon @ribru17 Note that this means that master is essentially frozen:

  • no further big changes to the plugin (bugfixes are fine, but only if they can be rebased on cleanly -- otherwise they should go to main directly)
  • query changes still go to master as usual, but remember to regularly git rebase master on main; git checkout --theirs for non-query files will deal with conflicts.

@ribru17
Copy link
Collaborator

ribru17 commented Apr 11, 2024

Awesome, thank you so much for your work @TheLeoP and @clason! Is there a roadmap (or general idea) for what must happen before master is updated to reflect these changes?

@clason
Copy link
Collaborator

clason commented Apr 11, 2024

Yes: hell must freeze over.

@clason
Copy link
Collaborator

clason commented Apr 11, 2024

Less facetiously: these changes will never make it to master; what will happen is that the main branch will become the default branch that receives all future updates and master becomes essentially a legacy branch for people unable to move to the shiny new world. This will happen together with the same change for nvim-treesitter (and other plugins we control), so is described by its roadmap.

@ribru17
Copy link
Collaborator

ribru17 commented Apr 11, 2024

Makes sense, thank you

clason pushed a commit that referenced this pull request Apr 13, 2024
details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check #523 for more info
clason pushed a commit that referenced this pull request Apr 14, 2024
details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check #523 for more info
clason pushed a commit that referenced this pull request Apr 20, 2024
details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check #523 for more info
clason pushed a commit that referenced this pull request May 18, 2024
details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check #523 for more info
ribru17 pushed a commit to ribru17/nvim-treesitter-textobjects that referenced this pull request May 26, 2024
details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check nvim-treesitter#523 for more info
kiyoon added a commit that referenced this pull request Jun 1, 2024
details:
- This plugin no longer depends on nvim-treesitter nor it's modules
  system.
- A bunch of code previously owned by nvim-treesitter has been moved to
  this plugin and been refactored.
- The user interface has changed in the following ways:
  - keymaps are no longer an option provided via the `setup` function.
    Users are expected to create them using `vim.keymap.set`
  - User commands have been removed for now.
- Python dependant tests (consistency_tests) have been removed
- Check #523 for more info
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

10 participants