Thursday, August 11, 2022

Re: vim9 exported functions not recognized by ctags

Thank you a lot Amazing Man LifePillar , 

  • Migh take account on the possibility of extended that ctags : Mine version on windows 10 is :  Universal Ctags 5.9.0(80ee839), Copyright (C) 2015-2022 Universal Ctags Team
            Version of Universal Ctags 5.9.0  is a little out of date don't you think ?
  • ctags --list-kinds=vim done and receive as you same values:
a  autocommand groups
c  user-defined commands
f  function definitions
m  maps
v  variable definitions
n  vimball filename
C  constant definitions


  • after extending :
somewhereOvertherainbow\Vim\vim90>ctags --list-kinds=vim
a  autocommand groups
c  user-defined commands
f  function definitions
m  maps
v  variable definitions
n  vimball filename
C  constant definitions
e  Vim 9 exported defs
g  Vim 9 global variables
K  Vim 9 constants

  • The only point that disturbs me is to have to create that :    ~/.ctags.d/vim.ctags        coupled to  OS-usersession. Because I use only standalone and portable own Vim distro that can be replicated on several machines.
So I put it in somewhereOvertherainbow\Vim\vim90\.ctags.d


But it seems to not runnning well : does not displays vim9 exported functions

Capture.PNG



Thank for help
Nicolas




Le jeudi 11 août 2022 à 09:03:07 UTC+2, Lifepillar a écrit :
On 2022-08-10, Lifepillar <lifep...@lifepillar.me> wrote:
> On 2022-08-10, N V <niva...@gmail.com> wrote:
>> Hi,
>>
>> Exported functions in New vim9 are not found by exubérant ctags, universal
>> ctags and not displayed by tagbar plugin
>> https://github.com/preservim/tagbar
>>
>> Is there a work around.

I'd like to elaborate a bit more on my previous reply, as I had just
played a bit more with the issue. In the following, "Ctags" means
Universal Ctags, because that is what I am using.

Ctags supports Vim out of the box. You may check which entities are
supported with `ctags --list-kinds=vim` from the command-line. That
currently gives me:

a autocommand groups
c user-defined commands
f function definitions
m maps
v variable definitions
n vimball filename
C constant definitions

Each "kind" (i.e., entity) is identified by a letter, and has a name
(not shown) and description. You may extend Ctags support for Vim by
creating a ~/.ctags.d/vim.ctags configuration file. In that file, you
define new "kinds" and corresponding regexes to recognize them. Each new
kind is also identified by a letter: be careful not to use the already
defined letters!

My current ~/.ctags.d/vim.ctags looks as follows:

--kinddef-vim=e,export,Vim 9 exported defs
--kinddef-vim=g,global,Vim 9 global variables
--kinddef-vim=K,const,Vim 9 constants
--regex-vim=/^\s*export\s+def\s+([^(]+)/\1/e,export/
--regex-vim=/^(\s*export\s+)?const\s+(\w+)/\2/K,const/
--regex-vim=/^(\s*export\s+)?final\s+(\w+)/\2/K,const/

The value of --kinddef is a triple <letter>,<name>,<description>. Each
regex item has three parts /A/B/C/:

- A is the pattern that recognizes an entity;
- B is the value that should be returned for that entity (what Tagbar
will display);
- C is the identifier of the entity, as defined in --kinddef.

So, the logic is: "if a line matches A, return the value B of kind C".

You may check that your configuration is correct by running `ctags
--list-kinds=vim` again. With the configuration file in place, you
should get:

a autocommand groups
c user-defined commands
f function definitions
m maps
v variable definitions
n vimball filename
C constant definitions
e Vim 9 exported defs
g Vim 9 global variables
K Vim 9 constants

Now, you need to configure Tagbar. Create
`~/.vim/after/ftplugin/vim.vim` and execute:

:TagbarGetTypeConfig vim

This will paste into the buffer Tagbar's current configuration, which
should look like this:

let g:tagbar_type_vim = {
\ 'kinds' : [
\ 'n:vimball filenames',
\ 'v:variables:1:0',
\ 'f:functions',
\ 'a:autocommand groups:1',
\ 'c:commands:0:0',
\ 'm:maps:1:0',
\ ],
\ }

Now, it's a matter of adding the new kinds, possibly removing those that
you don't need, and reordering the items the way you want them
displayed. I like to use vim9script, so my current script looks as
follows:

vim9script

if !exists('g:tagbar_type_vim')
g:tagbar_type_vim = {
'kinds': [
'e:exported defs',
'f:functions',
'v:variables:1:0',
'g:global variables',
'K:constants',
'c:commands:0:0',
'a:autocommand groups:1',
'm:maps:1:0',
],
}
endif

That's it! You may need to restart Vim for the changes to take effect.

You will notice that def's parameters are not shown for exported defs,
and that is intentional, because I don't find them useful. But you may
of course adapt Ctags's regexps to include those, and in general to fit
your taste.

Hope this helps,
Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/7bc94b73-39ac-4ee7-a0e6-a12e65cc1368n%40googlegroups.com.

No comments:

Post a Comment