Tree-sitter tab navigation (Smart tab)#41321
Tree-sitter tab navigation (Smart tab)#41321vamsi10010 wants to merge 20 commits intozed-industries:mainfrom
Conversation
… when EVERY cursor is ahead of non-whitespace
|
Thanks for this! I think the actions of move to start/end of tree-sitter node make sense, but I don't see a world where we can bind them to Is it possible to reduce this to just creating the actions, or would we need to add more information to the key-context to determine what to do when you hit tab? |
Thanks for the feedback! Its definitely possible to reduce this just to those two actions. I would have to add new key contexts that determine whether forward or backward movement is active. They would essentially do the same checks I hardcoded into |
|
Hmm; I'm not sure what the best option is. What happens on this branch when you hit tab and have an autocompleter open, an AI suggestion visible, or a snippet with tab-stops? I am nervous about tab just because it does so much already, but maybe this works if it's right at the end of the fallback list. Either way a PR to just add the actions seems totally reasonable. |
Hitting tab will accept the autocompletion/edit prediction, or move to the next tab stop as expected. I also created settings that let you supersede accepting autocompletions/edit predictions, but I am not sure if we want to keep them. However, by default, tab key as movement is at the end of the fallback list and happens only before indentation. |
|
Closing this for now as it conflicts with everything. Let's start with a PR that does the actions you want, and then figure out separately how to get the tab behavior perfect. |
Release Notes: - Added two actions `move_to_start_of_larger_syntax_node` and `move_to_end_of_larger_syntax_node` that move cursors to the start or end of the parent tree-sitter node Following up on my PR #41321, this PR only adds the actions that are used to enable code navigation across syntax nodes, without binding them to any keys (such as tab) by default. Both actions use the tree-sitter syntax tree to find parent nodes of the nodes the cursors are currently in. `move_to_start_of_larger_syntax_node` will then move each cursor to the first position of the parent nodes while `move_to_end_of_larger_syntax_node` to a position right after the parent nodes. Related issues and discussions: #22349, #14803, #42828, #13736. This PR doesn't achieve "tab out" functionality in the exact sense as is requested in these issues as it does not bind the actions to the tab key. I hope this PR can start some discussion on what the best way forward for these issues is. In the meantime, users can configure keys to use these actions as they see fit to emulate "tab out" behavior. For example, ``` "context": "Editor && vim_mode == insert && !in_snippet && !showing_completions", "bindings": { "tab": "editor::MoveToEndOfLargerSyntaxNode", "shift-tab": "editor::Tab" } ``` This will enable tab to skip past code structures like brackets when the cursor is not in a snippet or the autocomplete menu is not open. At the same time, shift tab will act as a backup tab.
Closes #22349
Closes #14803
MoveToEndOfLargerSyntaxNodeandMoveToStartOfLargerSyntaxNode. These actions can be bound to any keybinding if the user does not like the default smart tab settings.Questions:
editor::Tabandeditor::Backtabactions. Is this approach preferred to making separate actions for binding to tab and shift-tab keys?Here is smart tab in action:
zed-smart-tab.mp4
This is my first contribution to zed, so I would really appreciate any feedback on this! I believe this feature could be very helpful for users coming from other IDEs like VSCode or JetBrains.
Release Notes: