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

Feature Request: Highlight higher scope of unshown highlit items #882

Open
jamesTSCoop opened this issue Jun 12, 2024 · 5 comments
Open

Comments

@jamesTSCoop
Copy link

It bugs me a bit that if my cursor rests on a variable assignment line too long the highlighting for the method I'm in disappears because the variable within its scope is highlit but folded from view. I'd love to be able to configure tagbar so that there are four options:

  1. Current behaviour, highlight based on the configured tagbar_highlight_method regardless of if the tag is folded out of view or not
  2. Highlight the deepest visible tag even if the actual nearest tag is folded from view
  3. Highlight all parent tags for the current nearest tag
  4. Automatically unfold folded tags to ensure the nearest tag is in view, then fold back up to the default level when no tag in such an unfolded list is nearest
  5. Both 4 & 3.

I'm not completely sure 4 isn't already possible, I scanned the help, wiki, and issues pretty carefully but not perfectly. I'm also not completely sure I can't already configure the highlighting colour/style based on tag type, but that's another thing I think would be cool.

I'm a software developer and I'd be happy to do the coding if someone who knows this codebase can confirm that it's possible and point me in approximately the right direction!

@raven42
Copy link
Collaborator

raven42 commented Jun 12, 2024

Can you please share a screenshot or something? I'm not quite understanding the issue you are describing. I'm not understanding why a variable assignment line being too long would have any impact on the tags identified by universal-ctags or on tagbar. I just want to make sure I understand your request.

As for number 4, if I understand that request, I don't believe there is any option to do this currently. Tagbar only sets the fold levels for each line, but doesn't control showing/hiding the folds.

@raven42
Copy link
Collaborator

raven42 commented Jun 13, 2024

If you want to take a look at the current implementation, the function that performs the highlight is here.

tagbar/autoload/tagbar.vim

Lines 2242 to 2246 in 0815b54

" User actions {{{1
" s:HighlightTag() {{{2
function! s:HighlightTag(openfolds, ...) abort

There is a bit specifically about highlighting the parent instead. Is this the issue to which you are referring?

tagbar/autoload/tagbar.vim

Lines 2304 to 2308 in 0815b54

" Check whether the tag is inside a closed fold and highlight the parent
" instead in that case
let tagline = tag.getClosedParentTline()

@jamesTSCoop
Copy link
Author

Yes, the code at 2307 looks like it should be doing what I am wanting/expecting, but for me it isn't, here are some screenshots.

The cursor is on an unfolded var, the var is highlit, makes sense:

cursor_on_unfolded_var

The cursor is on a folded var, the parent scope isn't highlit, and I wish it was :(

cursor_on_foded_var

The cursor is not on a var, the function is highlit, I'm happy for a moment :)

cursor_not_on_var

@raven42
Copy link
Collaborator

raven42 commented Jun 13, 2024

Ok, I see what you mean now. Ya it looks like this might be a bug based on the comments in the code. It looks like it is supposed to set the highlight identifier to the parent tag if the fold is closed, but it looks like that might now be happening correctly.

I suspect something it wrong with this logic here:

tagbar/autoload/tagbar.vim

Lines 2322 to 2325 in 0815b54

" If printing the line number of the tag to the left, and the tag is
" visible (I.E. parent isn't folded)
let identifier = '\zs\V' . escape(tag.name, '/\') . '\m\ze'
if g:tagbar_show_tag_linenumbers == 2 && tagline == tag.tline

It is using the same tag.name that was returned from here:

tagbar/autoload/tagbar.vim

Lines 2260 to 2264 in 0815b54

if a:0 > 2
let tag = s:GetNearbyTag(g:tagbar_highlight_method, 0, a:3)
else
let tag = s:GetNearbyTag(g:tagbar_highlight_method, 0)
endif

So maybe it is something to do with the GetNearbyTag() function?

Unfortunately I don't have time to really dig into it right now, but it is likely something in this area. I'm thinking if we do detect that the parent is folded, we may need to change the value of tag to be the parent instead of the nearest tag. Or maybe the GetNearbyTag() needs a different argument to ignore folded tags?

@raven42 raven42 added bug and removed feature labels Jun 13, 2024
@jamesTSCoop
Copy link
Author

Thanks for the pointers though, I'm sure I can figure it out from here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants