vim9 exported functions not recognized by ctags

222 views
Skip to first unread message

N V

unread,
Aug 10, 2022, 2:58:23 PM8/10/22
to vim_use
Hi,

Exported functions in New vim9 are not found by exubérant ctags, universal ctags and not displayed by tagbar plugin

Is there a work around. 
Thank you
Nicolas

Lifepillar

unread,
Aug 10, 2022, 4:20:52 PM8/10/22
to vim...@googlegroups.com
I have the same problem. I think that this will be eventually solved
upstream, but in the meantime the following works for me with Universal
Ctags (I haven't had time to refine this, so what follows is just
a sketch):

1. Create ~/.ctags.d/vim.ctags with the following content:

--kinddef-vim=e,export,exported function
--regex-vim=/^[ \t]*export[ \t]+def[ \t]+([^(]+)/\1/e,export/

2. In your .vimrc, or in your after/ftplugin/vim.vim file, inform Tagbar
about the new entity:

g:tagbar_type_vim = { 'ctagstype': 'vim', 'kinds': ['e:export'] }

Now, Tagbar should display (only) exported functions. Refer to Tagbar
documentation to learn how to *extend* the already recognized entities
by adding exported functions.

Hope this helps,
Life.


Lifepillar

unread,
Aug 11, 2022, 3:03:07 AM8/11/22
to vim...@googlegroups.com
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.

Lifepillar

unread,
Aug 11, 2022, 3:10:37 AM8/11/22
to vim...@googlegroups.com
Aah, the line for global vars got cut off the Ctags config:

--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*(g:\w+)\b/\1/g,global/
--regex-vim=/^(\s*export\s+)?const\s+(\w+)/\2/K,const/
--regex-vim=/^(\s*export\s+)?final\s+(\w+)/\2/K,const/

But you've got the idea :-)
Life.


N V

unread,
Aug 11, 2022, 4:43:51 AM8/11/22
to vim_use
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

Lifepillar

unread,
Aug 11, 2022, 1:55:48 PM8/11/22
to vim...@googlegroups.com
On 2022-08-11, N V <niva...@gmail.com> wrote:
> So I put it in *somewhereOvertherainbow\*Vim\vim90\.ctags.d

If you put Ctags configuration there, does `ctags --list-kinds=vim`
still use it?

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

I'm afraid I can't help you with Windows-specific configuration, as I'm
not using Windows.

Life.

Message has been deleted
Message has been deleted
Message has been deleted

N V

unread,
Aug 12, 2022, 10:19:16 AM8/12/22
to vim_use
And YES It Is !!  :)

Windows configuration of vim9script  ctags extension


1/ In your $MYVIMRC ~_vimrc (here vim9script) just put these lines :

g:tagbar_type_vim = {
       kinds: [

          \ 'a:autocommand groups:1',
          \ 'c:commands:0:0',
          \ 'e:exported defs',
          \ 'f:functions',
          \ 'g:global variables',
          \ 'K:constants',

          \ 'm:maps:1:0',
          \ 'n:vimball filenames',
          \ 'v:variables:1:0',
      \ ],
}


2/ In your $vimruntime ~ vim90 folder where there is ctags.exe v5.9 just add  file in folder .ctags.d/vim.ctags

--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*(g:\w+)\b/\1/g,global/
--regex-vim=/^(\s*export\s+)?const\s+(\w+)/\2/K,const/
--regex-vim=/^(\s*export\s+)?final\s+(\w+)/\2/K,const/




and see the light : all exported defs vim9script functions are now displayed !   :) :)
Capture.PNG



THANK YOU Life !!
Hope this help someone.
Nicolas

N V

unread,
Aug 17, 2022, 9:24:35 PM8/17/22
to vim_use
For extended powershell script, displaying functions with tagbar see this:




If it can help. 
Have a good Day. 
Nicolas 

Nicolas

unread,
Dec 16, 2023, 7:36:24 AM12/16/23
to vim_use
Hi Life,

How to get exported and not exported def vim9 functions please according to g:tagbar_type_vim = { 'ctagstype': 'vim', 'kinds': ['e:export'] }?

Thank you
Nicolas

Nicolas

unread,
Dec 16, 2023, 9:21:35 AM12/16/23
to vim...@googlegroups.com
this is mine .ctags.d

--kinddef-vim=e,export,function,"Vim 9 exported functions"
--kinddef-vim=f,function,"Vim 9 non-exported functions"
--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,def/
--regex-vim=/^\s*def\s+([^(]+)/\1/f,function,def/

--regex-vim=/^\s*(g:\w+)\b/\1/g,global/
--regex-vim=/^(\s*export\s+)?const\s+(\w+)/\2/K,const/
--regex-vim=/^(\s*export\s+)?final\s+(\w+)/\2/K,const/

with g:tagbar_type_vim = {'ctagstype': 'vim', 'kinds': ['e:export', 'g:global', 'K:const', 'f:function']}

Hope this helps.
nicolas

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/hp4KeIsDlFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/260b74f5-7d2e-4446-b87e-a671c493d84an%40googlegroups.com.

Lifepillar

unread,
Dec 18, 2023, 6:08:58 PM12/18/23
to vim...@googlegroups.com
On 2023-12-16, Nicolas <niva...@gmail.com> wrote:
> this is mine .ctags.d
>
> --kinddef-vim=e,export,function,"Vim 9 exported functions"
> --kinddef-vim=f,function,"Vim 9 non-exported functions"
> --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,def/
> --regex-vim=/^\s*def\s+([^(]+)/\1/f,function,def/
> --regex-vim=/^\s*(g:\w+)\b/\1/g,global/
> --regex-vim=/^(\s*export\s+)?const\s+(\w+)/\2/K,const/
> --regex-vim=/^(\s*export\s+)?final\s+(\w+)/\2/K,const/
>
> with g:tagbar_type_vim = {'ctagstype': 'vim', 'kinds': ['e:export',
> 'g:global', 'K:const', 'f:function']}
>
> Hope this helps.
> nicolas

That should work, shouldn't it? Or what is your issue with it?

My current vim.ctags looks like this:

--kinddef-vim=g,vim9global,Vim 9 global variables
--kinddef-vim=K,vim9const,Vim 9 constants
--kinddef-vim=L,vim9class,Vim 9 class
--kinddef-vim=I,vim9interface,Vim 9 interface
--regex-vim=/^export\s+def\s+([^(]+)/\1/f/
--regex-vim=/^\s*(g:\w+)\b/\1/g,vim9global/
--regex-vim=/^(export\s+)?(const|final)\s+(\w+)/\3/K,vim9const/
--regex-vim=/^\s*(export\s+)?(abstract\s+)?class\s+(\w+)/\3/L,vim9class/
--regex-vim=/^\s*(export\s+)?interface\s+(\w+)/\2/I,vim9interface/

That works with Universal Ctags 6.0.0, as confirmed by:

uctags --list-kinds=Vim

which outputs:

a autocommand groups
c user-defined commands
f function definitions
m maps
v variable definitions
n vimball filename
C constant definitions
g Vim 9 global variables
K Vim 9 constants
L Vim 9 class
I Vim 9 interface

In my `vimrc` I set the path to the executable:

g:tagbar_ctags_bin = '/opt/local/bin/uctags'

and for Vim tags:

g:tagbar_type_vim = {
'kinds': [
'L:classes',
'f:functions and methods',
'v:variables:1:0',
'g:global variables',
'K:constants',
'c:commands:0:0',
'a:autocommand groups:1',
'm:maps:1:0',
],
}

Life.

Nicolas

unread,
Dec 29, 2023, 4:09:22 AM12/29/23
to vim_use
It works perfectly Life even if there is no disctinction between exported vim9 func and the other func. 
;)
Thank you I keep your
I wish you a happy holiday season
Nicolas

Nicolas

unread,
Dec 29, 2023, 4:15:16 AM12/29/23
to vim_use
With exported vim9 function distinction :)

g:tagbar_type_vim in a json.
  "g:tagbar_type_vim": "{ 'kinds': [ 'L:classes', 'e:exported functions', 'f:functions and methods', 'v:variables:1:0', 'g:global variables', 'K:constants', 'c:commands:0:0', 'a:autocommand groups:1', 'm:maps:1:0', ], }",

vim.ctags
--kinddef-vim=e,vim9exportedfunc,Vim 9 global variables

--kinddef-vim=g,vim9global,Vim 9 global variables
--kinddef-vim=K,vim9const,Vim 9 constants
--kinddef-vim=L,vim9class,Vim 9 class
--kinddef-vim=I,vim9interface,Vim 9 interface
--regex-vim=/^export\s+def\s+([^(]+)/\1/e/
--regex-vim=/^def\s+([^(]+)/\1/f/

--regex-vim=/^\s*(g:\w+)\b/\1/g,vim9global/
--regex-vim=/^(export\s+)?(const|final)\s+(\w+)/\3/K,vim9const/
--regex-vim=/^\s*(export\s+)?(abstract\s+)?class\s+(\w+)/\3/L,vim9class/
--regex-vim=/^\s*(export\s+)?interface\s+(\w+)/\2/I,vim9interface/



Christian Brabandt

unread,
Dec 29, 2023, 4:20:34 AM12/29/23
to vim...@googlegroups.com
Hi,
perhaps someone :) should send a PR to
https://github.com/universal-ctags/ctags to add support for Vim9 Script?

Thanks,
Chris
--
An investment in knowledge always pays the best interest.
-- Benjamin Franklin

Ken Takata

unread,
Jan 10, 2024, 3:16:50 AMJan 10
to vim_use
Hi,

I created an issue for this:

2023年12月29日金曜日 18:20:34 UTC+9 Christian Brabandt:

Nicolas

unread,
Jan 10, 2024, 4:42:17 AMJan 10
to vim...@googlegroups.com
Thank you Ken and Happy new year.
Nicolas. 


--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/hp4KeIsDlFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages