preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.1k stars 485 forks source link

Powershell function tags not displayed #830

Closed niva-xx closed 1 year ago

niva-xx commented 1 year ago

Hi,

How to deal with the fact that Universal-ctags recognize Powershell but vim9 set filetype of ps1 or psm1 as ft=ps1. The result is that universal-ctags used with tagbar seems to not recognized Powershell type of file.

raven42 commented 1 year ago

Just so I understand, is this a case where vim9 is not setting the filetype correctly? Or is the filetype correct in vim9 due to a difference in an older Powershell format vs the new one?

niva-xx commented 1 year ago

With vim90 patch 0217 on windows 10, vim recognize powershell scripts as this in vim90\filetype.vim|1447| au BufNewFile,BufRead .ps1,.psd1,.psm1,.pssc setf ps1 and it seems that tagbar does not displayed well the functions, globals, etc.. of powershell scripts.

So, a workaround to recognize powershellscript functions, globals

1/ In your $MYVIMRC just put these lines: g:tagbar_type_ps1 = { ctagstype: 'PowerShell', kinds: [ \ 'f:functions', \ 'g:global variables', \ 's:called scripts', \ ], }

2/ In a .ctags.d folder known of your PATH or at the Universal-ctags (ctags.exe) root, add this filetype

.ctags.d/ps1.ctags containing these lines : --kinddef-powershell=f,functions,PowerShell functions --kinddef-powershell=g,global,PowerShell global variables --kinddef-powershell=s,scripts,PowerShell Called Script --regex-powershell=/^function\s+([^(]+)/\1/f,functions/ --regex-powershell=/\$global:(\w+)\s/\1/g,global/ --regex-powershell=/\$script:(\w+)\s/\1/s,scripts/

raven42 commented 1 year ago

Ok thanks. Once universal ctags can support this filetype officially, we can add support for it in tagbar.

Thanks for providing a solution.