-
-
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
locals are not retained for the whole document #1151
Comments
Yeah I haven't addressed this yet, it requires some more thought. It's possible to resolve locals for the whole document when we deal with injections (but that's slightly inefficient if we don't need the whole set), but that doesn't solve the whole problem: we'd also need to know what highlighting query matches for that A workaround would be resolving all the highlights ahead of time (so no querying at all happens during render), but that can use a lot of memory on large documents. We could include more styling information on the |
If we're worried about pathologically large documents, maybe we could do something kind of dumb: remember all definitions and highlight matches up to a certain size limit. If we reach the limit, bail out and don't remember anything (current behavior) so that we don't get erratic highlighting. This will enable local highlighting for 95% of cases, and fall back in extreme cases to save hx from blowing up. |
Another thought: do we have to remember all references? Could we get away with querying all of the references that are contained in the visible scopes that lie in the view? What I mean by that is e.g.: int global = 1;
void foo() {
char b;
}
// We only see from here down
void bar() {
float f;
}
... If our view starts at |
Yes, it hasn't been addressed yet which is why this issue is still open. |
I reported this in the Matrix chat room, but filing an issue to track it.
I tried to improve the C highlighting to highlight macro invocations differently than regular function calls. After reading through the tree-sitter docs, it seems like local variables should be able to enable this.
So far, I think I've followed the docs pretty closely and came up with this. However, it doesn't seem to be working. Macro invocations are still being colored like any other function call.
I figured out that locals do seem to work, but only if the definition is on screen.
As soon as you scroll past the definition, it loses it. I can see with added debug logging around here that the
scope.local_defs
is at first populated with the macro definition, but when it goes out of sight,scope.local_defs
becomes empty.@archseer mentioned that it could be because highlights are done only for the range on the screen, but that locals should be kept for the whole document.
https://github.com/helix-editor/helix/blob/master/helix-term/src/ui/editor.rs#L136-L142
Reproduction steps
Define a language locals query that finds variable definitions, and color them differently. If the definition and the reference are both on screen, it works, but as soon as the definition is off screen, the highlight reverts back to its own tree-sitter match instead of deferring to the definition's highlighter.
Environment
The text was updated successfully, but these errors were encountered: