-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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(ui): sticky context #3944
feat(ui): sticky context #3944
Conversation
88a32c5
to
f2e6d7e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Maybe it's better to wait for an additional maintainer before putting additional work, because I'm unsure whether everyone agrees on including this.
That being said, here is my initial feedback =)
EDIT: regarding the naming of the feature, I like "sticky context". 👍
helix-view/src/editor.rs
Outdated
/// Display context of current cursor line if it is outside the view. | ||
pub context: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move to the editor::Config
struct and go with a new category: sticky_context: StickyContext
.
- enable: to enable sticky context feature (default: false)
- min_window_height: disable sticky context when the window is too small (default: ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to editor::Config
but left it as boolean config option for now. I am not sure if min_window_height
is necessary as the context usually spans only a few lines. What do you thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m just thinking this can be useful when the editing some file in a small window. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a keybind to toggle it? That way it can be decided per case.
I also want to throw in my tiny opinion i have: the Also this seems to be a bit untouched for a while i guess? Is some help needed to further implement this? |
@s0LA1337 I agree, that was just for testing. No help needed, I just need to find some time 😅 sorry about that; or feel free to pick it up if you feel like. |
440c940
to
091e327
Compare
@s0LA1337 I had some time and moved the PR a bit. Feel free to test it out locally and I would be happy for any further feedback. Otherwise, I have a few open questions:
|
Really cool addition! I personally use it a lot in my neovim setup. As for the comments:
It would be cool to show the line numbers of the overlayed context lines instead of the ones under them, but I'd say that's best left to a separate PR.
I suppose cases like that would require writing actual tree-sitter queries instead of providing a simple list of scope names, and it does provide more granularity, so I suppose it would be nice to have. But I like how simple the current PR is and how it delivers most of the functionality already, so I would shelve that for a separate PR again :)
We definitely need separate theme keys, and it can manually fallback to another scope like
I'm not sure how expensive it is to traverse up the tree checking every parent, so someone with more experience in that area would have to give their input. The traversal is done on every render, so it might be costly. Maybe a cache could help? But only after checking actual perf numbers. Premature optimization is indeed the root of all evil :) (Also removing the draft status and marking ready for review since it's no longer WIP in the title.) |
807e3c6
to
f7d20c2
Compare
i actually opened a pr for your branch to include line numbers :) |
f7d20c2
to
5f95619
Compare
This is looking pretty good! Agreed with @sudormrfbin.
Unless you had performance issues when testing in a reasonable sized file, I wouldn’t dig that just yet. The feature is optional and can be disabled at any time if it is an issue. Worst case, we can optimize that in a separate PR =) |
@s0LA1337 oh please go ahead with the PR, would love to take a look. And sorry, I amended a few more minor changes. |
since i have literally worked on that already - i am not sure what you mean with that. What i essentially did is: replacing the current line nrs in the gutter with the absolute ones (next to the sticky context) of the sticky context. pictures: |
@s0LA1337 we're on the same page about the line number display, your implementation was exactly how i imagined it to be. |
|
3614b69
to
17271a3
Compare
helix-term/src/ui/editor.rs
Outdated
|
||
let mut line_numbers = Vec::new(); | ||
for line_num in context { | ||
if line_num >= view.offset.row { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if line_num >= view.offset.row { | |
if line_num >= view.offset.row || text.byte_to_line(cursor_byte) == line_num { |
this is required because the sticky context will overshadow the cursor if you're on the same line with the cursor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried with the latest changes? I ammended it to the latest commit but for me it works just with line_num >= view.offset.row
, previously it was line_num > view.offset.row
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried with the latest changes? I ammended it to the latest commit but for me it works just with
line_num >= view.offset.row
, previously it wasline_num > view.offset.row
.
actually i haven't. time to try it out when i have time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: yup seems good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good to me code-wise!
@archseer I think this change is not too complex and can be part of helix’s built-ins. Are you okay with me merging this feature once last nits are addressed if any?
@CBenoit (and maybe @archseer for further input): what I don't like right now is the way the context lines are passed from the |
I also have a proposal if it's:
Couldn't we capture via tree-sitter all the arguments and have them stick, too? |
For reference: #3944 (comment) My problem with this is that it will then be a breaking change to modify in order to add more options. But then, maybe we don’t want additional configuration and the additional keybinding only as suggested by @sudormrfbin is alright (I would like both) |
helix-term/src/ui/editor.rs
Outdated
|
||
let mut parent = tree | ||
.root_node() | ||
.descendant_for_byte_range(cursor_byte, cursor_byte) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the sticky context lines should depend on the top of the viewport instead of the cursor location
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would complicate it a little bit as what can happen is that for example if the context would contain 3 nodes the 3 lines that we would display would cover more than just the top line of the viewport.
17271a3
to
f76a789
Compare
I actually have noticed a small bug with the line numbers that i introduced. other than that: scopes on the first line seems to be sometimes a bit... wrong? /**
* i am a comment
*/
...
class Abc {
...
}; The comment will still be put on the sticky context, even though i completely left the scope. |
f76a789
to
60ac894
Compare
hi! will there be option to choose the style between: The separator line may say: The separator line will be extremely crucial choice for the default signature purple theme:
|
Hi, i also just discovered that there is still a bug. An example can be found in this file: https://github.com/ziglang/zig/blob/master/src/main.zig
stack trace:
|
I took the time and integrated this pr's (partial) functionality to the new text api.
@matoous should i open up a pr for you to look over it, or open an entirely new pr for it? |
@SoraTenshi please feel free to open new PR, I am afraid I don't have time at the moment to pick this up. |
New pr created, i think this one can be closed. |
Note: This PR is
roughproof of concept. I am completely fine if the final decision is not to include this in the core. (although I believe it fits well with the rest of the tree-sitter support and should be part of the core).Add option to render the context of current line if the context is outside the view. Parent Tree-sitter node(s) outside the view are displayed at the top of the view providing additional (hopefully helpful) context for the current cursor line. The nodes are filtered based on language-specific configuration to strike the right balance between helpful and too noisy.
Inspiration taken from context.vim and a treesitter port of context.vim - https://github.com/romgrk/nvim-treesitter-context.
The desired behavior should resemble this:
or this
Fixes: #396