-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Highlight current indent (no color) with a lower priority than scope (with color) #649
Comments
No, it doesn't exist. There is a similar discussion in #632 to give some context. Of course if someone makes a great PR I am open to add this. If anyone wants to try, please discuss the implementation with me first, so you don't waste time on a suboptimal solution. |
I am willing to try to implement this. How would you want something like this to be implemented? I haven't used So I assume the main work is to get the highlighting of the current indentation level to work. I haven't looked much at the code yet, so I am sure I will find out that it is much harder than it looks quickly, but I thought we would have access to the indent lines drawn on the current cursor line and could relatively simply "catch" the inner most one and highlight that level of indentation. I assume some of the complexity comes from how the indentation blocks are made, but am I missing anything else? Also, when I work on this, which files would I need to edit? (Where would you prefer this code to be?) |
Yeah it's not that easy. The code iterates only a single time over the lines for performance. So when you reach the cursor, all lines above are already rendered. You can't change the highlight anymore. The scope works by walking the treesitter tree up from the cursor before looping over the lines, that is very fast. I added wildcards for the scope in version 3.2.0. That gets pretty close to "current" indent, but it has a lot of edge cases. |
I have looked at the code now and can see that it will be a bit more complicated than I thought. Would something like this work:
(I know this is not really mentioning any exact implementation details, but I mostly just want to get a general picture to start with.) |
yeah these details don't really matter. The main question is just how the algorithm should work. |
I think what I want can almost be done with small changes in the It is not at all finished yet, but I do get the behavior I want in most cases I have checked now. I plan to work more on this tomorrow and maybe the day after, but I thought I would upload it for now, if you had any early comments about it. |
Yes, name should definitely be something like |
I have renamed it to The algorithm is still almost an exact copy of scope that just basically counts almost everything as being a "scope". And then you have to for each language figure out how that language's tree sitter implementation represents blank lines and lists of commands, so that you can make sure not to highlight by mistake as above in these cases. I think a lot of this could be moved into the implementation of I have tested on the following file types now:
And most things works as I would want/expect. I think one problematic thing about the way I am doing it now is that you have to maintain a file like: https://github.com/lukas-reineke/indent-blankline.nvim/blob/master/lua/ibl/scope_languages.lua And from what I can tell that file was generated, while I don't see anything in neovim's tree sitter implementation that I could use to generate what I use in I haven't run into many extra edge cases after considering the "blank line" types mentioned above, but I have seen a few and I also haven't tested that much. It is mostly pretty easy to debug. You just have to do something like I agree that this is not at a level, where you would want to accept the draft pull request, but since it works mostly as I wanted now, I don't think I will do much more work on it unless I discover a much better way or you want me to change anything specific and work towards a proper pull request? I will try to look more at tree sitter, but it doesn't seem to expose the things I would like to use to improve what I have for now. (Also, I can close/delete the draft pull request if you prefer?) |
Yeah this is a dealbreaker. Maintenance effort would be way too high. And this would never be perfect. |
I would also like to see indentation level "context" be highlighted, I was not even aware that there was a problem with the old current context, it always worked fine for me. Instead of using treesitter, why not just use old fashioned regex? Why does it have to be treesitter? |
It has to be something like this, yes. But doing it separate from the main loop would kill performance. |
I had some time today too, so I tried making a version without tree sitter where most of the code is completely separate from the tree sitter stuff, so if you disable `current_indent´ you shouldn't notice any difference in speed although this is slower than tree sitter: On my machine it works fine, but I don't know if that is true for most people. It is again not ready for pull request yet, but I just thought I would ask if you would be more willing to accept something like that? I am pretty sure there is a slow down when enabling it, but when it is disabled, everything should feel the same, and then it is up to the individual user, if they want to use it. I haven't found any edge cases so far, and I think it should basically always work (can't see what could go wrong if the indents are drawn correctly already). |
I had a look at the code again. Let me explain what I think is the only reliable solution for this.
indent-blankline.nvim/lua/ibl/init.lua Lines 283 to 316 in 906ba1e
Basically,
But this is very complicated. It has to work with all the other logic that is already there. |
I looked into doing what you said, but it was hard to get it to work with everything else. What I ended up doing was split the The first loop goes over each line and makes an array of Then after the first loop I use the array of each line's furthest indent to calculate the current row's indent and find the start and end of the current indent level (this is easy and quick since I have an array with just numbers to look at for the indent levels). Then the second loop goes over each line and makes the virtual text and sets up extmarks using the array of Realistically keeping the array of whitespace tables is not optimal, but I don't notice any slowdown when using this setup on my computer and I have everything working as I wanted now. As mentioned in the previous pull request, I don't really expect this to be committed here, but I wanted something like this for my own editing and I am also just trying to get used to writing more complicated Lua code. I will probably just keep my fork that is slightly slower (I think, it doesn't feel slower), but does what I want for now, but if I figure out a smarter way to do this I will probably ask if you will accept a pull request. (I don't know a good way to compare code without making a pull request, but here is the new By the way, while I kept looking at this and asking about it, I just want to reiterate that I think the |
It's definitely the best attempt so far. But the 2 loop solution is not ideal. You now do duplicate work in both. |
I changed it slightly by adding a boolean array keeping track of which |
Actually, what I said is not entirely correct. With only adding a few arrays containing either booleans or numbers (i.e., arrays that should have no influence on the performance when we work with less than a thousand lines and do other more calculation heavy stuff), I got it so that I don't do any calculation twice (other than an integer addition since it seemed like overkill to save that in an array...). I think now the only thing that might impact performance is keeping around the array of |
Yeah, keeping the You can improve the calculation for the current indent by having a stack that mirrors Overall, this solution is probably as good as it will get. Please make a PR. Thanks for being persistent, I think there is a good chance we can get this merged. |
Hi, I've used both indent-blankline.nvim and mini.indent at same time. And so far everything looks fine. Look at following screenshot :
Just sharing, also expect the discuss of here. |
I have added a stack now, but I am not sure if you meant to add it in the
I have made a pull request now. If there is anything specific you would like me to edit, you can just let me know, and I can do some stuff at first before you go over it yourself. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as off-topic.
This comment was marked as off-topic.
Basically it just highlights tabs, see lukas-reineke/indent-blankline.nvim#649 (comment)
Excited to see this <3, I'll drop mini.animate as soon as this is out |
Problem
I just updated to version 3 today and haven't yet played around with all the options, but I couldn't find something doing what I am asking for in the following. If it already exists, could someone let me know how to do it?
I really like the new highlighting via scope (especially in Rust). Even in Lua, I think this is helpful:
So I plan to keep the highlighting on (I am matching it with rainbow-delimiters).
But whenever there is no scope highlighting I would like to fall back to slight highlighting of my current indentation level. I.e., in this picture:
I would like to have some slight highlighting of the second indent line to the left of my cursor.
Preferably I would probably want to always have a slight highlighting of the current indent level unless that highlighting is overwritten by the scope highlighting. So sometimes the might be two highlighted indent lines at the same time. E.g., here:
I would like to keep the first indent red, but have the second indent slightly light up to indicate the current indent level at the cursor position.
Is there already a way to do this? If not, I am willing to spend some time to try helping with implementation or testing of something like that. And if nothing else, I would like to request a feature like that.
Expected behavior
Always slightly highlight (e.g., just brighter color) the current indent level unless the current indent level is also the scope level in which case the scope is preferred for highlighting.
(Alternatively, when not using the current scope to highlight anything, highlight slightly the current indent level.)
The text was updated successfully, but these errors were encountered: