开发者

Is there a vim plugin that makes Moose attributes show up in Tag_List?

开发者 https://www.devze.com 2022-12-19 09:20 出处:网络
I am editing packages that use Moose, and I was wondering if there were a plugin for making Moose attributes show up in the Tag List.

I am editing packages that use Moose, and I was wondering if there were a plugin for making Moose attributes show up in the Tag List.

For example, in the following code, the attribute options does not show up in Tag_List, but print_out_site does:

use Moose;
use MooseX::AttributeHelpers;

...

has 'options' => (
    metaclass => 'Collection::Hash',
    isa       => 'HashRef[Str]',
    is        => 'ro',
    provides  => {
        exists =&开发者_运维知识库gt; 'exists',
        get    => 'get',
        set    => 'set',
    },
);

...

sub print_out_site {
    my $self = shift;
    my $key  = shift;
    $self->fasta_out_fh->print(">", $key, "\n");
    $self->fasta_out_fh->print($self->sites->{$key}, "\n");
}


Add the line

--regex-perl=/has '(.*)' => \(/\1/a,attribute,moose attributes/

to ~/.ctags and it should show up. You may need to tweak the regular expression to avoid spurious matches in other files or to accommodate different formatting for the attribute declarations in other files.

This extends ctags so that it detects another type of tag based on the regular expression when parsing perl files.

Then you need to tell the taglist plugin about the new tag type by adding this to your vimrc file:

let tlist_perl_settings='perl;c:constant;l:label;p:package;s:subroutine;a:attribute'


Geoff, I tried your code but it didn't work for me with the syntax you use. Could this be a version problem? I'm using exuberant ctags version 5.8.
I also modified the regex a bit because the quotes are optional and you might want to allow spaces (but nothing else) preceeding the 'has' keyword.
Here is what worked for me. I created a $HOME/.ctags file (didn't have one yet, otherwise just add to it) with the following line:

--regex-perl=/^\s*has\s+['"]?([0-9a-zA-Z_]+)/\1/a,attribute/

Then added the line in .vimrc as you suggested

let tlist_perl_settings='perl;c:constant;l:label;p:package;s:subroutine;a:attribute'

Now it lists my attributes in Moose modules.

In addition, I find it useful to also have information about the parent class, roles and used modules show up in the taglist, so here is my complete $HOME/.ctags file:

--regex-perl=/^\s*has\s+['"]?([0-9a-zA-Z_]+)/\1/a,attribute/
--regex-perl=/^\s*with\s+(['"])(.+)\1/\2/r,role/
--regex-perl=/^\s*extends\s+(['"])(.+)\1/\2/e,extends/
--regex-perl=/^\s*use\s+([^ ;]+)/\1/u,use/

and this is what I have in .vimrc (you can change the order of tags in the taglist simply by changing the order in the tlist_par_settings):

let tlist_perl_settings='perl;u:use;p:package;r:role;e:extends;c:constant;a:attribute;s:subroutine;l:label'
let Tlist_Show_One_File = 1

Because of the additional content I find it useful to use the Tlist_Show_One_File option, which forces the taglist to show only the tags of the currently selected file.
To temporarily hide some of the tags you can always move the cursor to the tag name and hit "zc" (and "zo" to reopen) the fold.

0

精彩评论

暂无评论...
验证码 换一张
取 消