Skip to content

Commit

Permalink
This adds support for controlling display of suffix/prefix (#893)
Browse files Browse the repository at this point in the history
* This adds support for controlling display of suffix/prefix

This adds the `g:tagbar_show_prefix` and `g:tagbar_show_suffix` options. These will help control if the prefix info and/or suffix info is printed in the tagbar window for the tag.

This is just test code for now.

* Correct the `show_prefix` behavior so it has proper whitespacing
  • Loading branch information
raven42 authored Nov 5, 2024
1 parent d55d454 commit 1c5a358
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
6 changes: 3 additions & 3 deletions autoload/tagbar/prototypes/basetag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ endfunction
function! s:_getPrefix() abort dict
let fileinfo = self.fileinfo

if !empty(self._childlist)
if !empty(self._childlist) && g:tagbar_show_prefix == 1
if fileinfo.tagfolds[self.fields.kind][self.fullpath]
let prefix = g:tagbar#icon_closed
else
Expand All @@ -95,9 +95,9 @@ function! s:_getPrefix() abort dict
endif
" Visibility is called 'access' in the ctags output
if g:tagbar_show_visibility
if has_key(self.fields, 'access')
if has_key(self.fields, 'access') && g:tagbar_show_prefix == 1
let prefix .= get(s:visibility_symbols, self.fields.access, ' ')
elseif has_key(self.fields, 'file')
elseif has_key(self.fields, 'file') && g:tagbar_show_prefix == 1
let prefix .= s:visibility_symbols.private
else
let prefix .= ' '
Expand Down
27 changes: 16 additions & 11 deletions autoload/tagbar/prototypes/normaltag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@ endfunction
function! s:strfmt() abort dict
let typeinfo = self.typeinfo

let suffix = get(self.fields, 'signature', '')
if has_key(self.fields, 'type')
let suffix .= ' : ' . self.fields.type
elseif has_key(get(typeinfo, 'kind2scope', {}), self.fields.kind)
let scope = s:maybe_map_scope(typeinfo.kind2scope[self.fields.kind])
if !g:tagbar_show_data_type
let suffix .= ' : ' . scope
if g:tagbar_show_suffix == 1
let suffix = get(self.fields, 'signature', '')
if has_key(self.fields, 'type')
let suffix .= ' : ' . self.fields.type
elseif has_key(get(typeinfo, 'kind2scope', {}), self.fields.kind)
let scope = s:maybe_map_scope(typeinfo.kind2scope[self.fields.kind])
if !g:tagbar_show_data_type
let suffix .= ' : ' . scope
endif
endif
endif
let prefix = self._getPrefix()

if g:tagbar_show_data_type && self.getDataType() !=# ''
let suffix .= ' : ' . self.getDataType()
if g:tagbar_show_data_type && self.getDataType() !=# ''
let suffix .= ' : ' . self.getDataType()
endif
else
let suffix = ''
endif

let prefix = self._getPrefix()

if g:tagbar_show_tag_linenumbers == 1
let suffix .= ' [' . self.fields.line . ']'
elseif g:tagbar_show_tag_linenumbers == 2
Expand Down
31 changes: 31 additions & 0 deletions doc/tagbar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,37 @@ Possible values are:
Example:
>
let g:tagbar_show_linenumbers = 2
<
*g:tagbar_show_prefix*
g:tagbar_show_prefix~
Default: 1

Controls if the prefix information is shown before the tag. The prefix info is
usually defined as the variable scope. For example, if a variable is private
scope only, then a '-' symbol will be used by default.

Possible values are:
0: Don't show the prefix.
1: Show the prefix.

Example:
>
let g:tagbar_show_prefix = 0
<
*g:tagbar_show_suffix*
g:tagbar_show_suffix~
Default: 1

Controls if the suffix information is shown after the tag. The suffix info is
usually data type.

Possible values are:
0: Don't show the suffix.
1: Show the suffix.

Example:
>
let g:tagbar_show_suffix = 0
<
*g:tagbar_show_tag_linenumbers*
g:tagbar_show_tag_linenumbers~
Expand Down
2 changes: 2 additions & 0 deletions plugin/tagbar.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ function! s:setup_options() abort
\ ['show_data_type', 0],
\ ['show_visibility', 1],
\ ['show_linenumbers', 0],
\ ['show_prefix', 1],
\ ['show_suffix', 1],
\ ['show_tag_count', 0],
\ ['show_tag_linenumbers', 0],
\ ['singleclick', 0],
Expand Down

0 comments on commit 1c5a358

Please sign in to comment.