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: integrate treesitter to determine filetype at cursor position #50

Merged
merged 1 commit into from
Dec 15, 2021

Conversation

smjonas
Copy link
Collaborator

@smjonas smjonas commented Dec 9, 2021

Heavily inspired by L3MON4D3/LuaSnip#226.

TODO:

  • check if there are performance issues => did not notice any
  • should we suppport filetype_source="both" to show snippets for the current filetype as well as for the filetype determined by Treesitter? => we chose not to support it right now (if users actually want this feature, we will add it)
  • explore if the current filetype for the active buffer can be changed in UltiSnips (to support the filetype_source="treesitter" option)
  • update readme

@smjonas smjonas force-pushed the treesitter_integration branch from 9c0a603 to 34d9836 Compare December 10, 2021 08:40
@smjonas smjonas force-pushed the treesitter_integration branch from 34d9836 to 55443d0 Compare December 10, 2021 08:58
@smjonas smjonas force-pushed the treesitter_integration branch from 55443d0 to 8a0f837 Compare December 11, 2021 13:45
@quangnguyen30192
Copy link
Owner

Just reviewed. thanks for the PR

@smjonas smjonas force-pushed the treesitter_integration branch 2 times, most recently from 9cd51c5 to ebd10c8 Compare December 12, 2021 20:56
@smjonas
Copy link
Collaborator Author

smjonas commented Dec 13, 2021

@quangnguyen30192 I just noticed we don't even need nvim-treesitter as a dependency. We can simply copy those functions from the nvim-treesitter plugin. Since Treesitter is built into Neovim we will always have the functionality we need.

@quangnguyen30192
Copy link
Owner

Cool 😊

@smjonas smjonas force-pushed the treesitter_integration branch 4 times, most recently from 4f067c5 to 742baa3 Compare December 14, 2021 19:44
@smjonas smjonas marked this pull request as ready for review December 14, 2021 19:49
@smjonas smjonas force-pushed the treesitter_integration branch from 742baa3 to cfb4c91 Compare December 14, 2021 19:51
@smjonas
Copy link
Collaborator Author

smjonas commented Dec 14, 2021

@quangnguyen30192 Please review again and test this feature :) E.g. in a CSS code block within a .html file. Also what do you think about adding a "both" option (as Luasnip also has this option)? See TODO at the top of this PR. Maybe this could be a separate PR if users actually want it.

I don't think there will be noticeable performance issues right now because:

  • Treesitter has already parsed the entire file after entering a buffer
  • then it is simply a lookup for the current node the cursor is on and return the info (no additional logic should be involved)
  • our Python code is only called when Treesitter found a different language than the current filetype of the buffer

@smjonas smjonas force-pushed the treesitter_integration branch from cfb4c91 to 25966b6 Compare December 14, 2021 20:00
@quangnguyen30192
Copy link
Owner

Just tested it and working fine 👍

I don't think there will be noticeable performance issues right now because:
Treesitter has already parsed the entire file after entering a buffer
then it is simply a lookup for the current node the cursor is on and return the info (no additional logic should be involved)
our Python code is only called when Treesitter found a different language than the current filetype of the buffer

Sure, let's go with it for now

E.g. in a CSS code block within a .html file. Also, what do you think about adding a "both" option (as Luasnip also has this option)? See TODO at the top of this PR. Maybe this could be a separate PR if users actually want it.

Do we really need it as of now? Let's add it when the user needs it then.

@smjonas smjonas force-pushed the treesitter_integration branch from 25966b6 to 9a03b07 Compare December 15, 2021 09:36
@smjonas smjonas changed the title Feat: use treesitter to determine filetype at cursor position Feat: integrate treesitter to determine filetype at cursor position Dec 15, 2021
@smjonas smjonas force-pushed the treesitter_integration branch from 9a03b07 to 4dad3d4 Compare December 15, 2021 09:42
@smjonas smjonas merged commit 1d0eec7 into quangnguyen30192:main Dec 15, 2021
@smjonas smjonas deleted the treesitter_integration branch December 15, 2021 09:43
@mathjiajia mathjiajia mentioned this pull request Dec 15, 2021
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.

2 participants