preservim / tagbar

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

Problems opening perl files #672

Closed diegok closed 4 years ago

diegok commented 4 years ago

Since I've updated around a month ago I'm having lots of errors opening perl files and probably others:

Error detected while processing function tagbar#ToggleWindow[2]..<SNR>90_ToggleWindow[9]..<SNR>90_OpenWindow[81]..<SNR>90_AutoU
pdate[63]..<SNR>90_ProcessFile[146]..<SNR>110_sortTags[2]..tagbar#sorting#sort[6]..<SNR>114_compare_by_kind:
line    3:
E716: Key not present in Dictionary: m
E15: Invalid expression: typeinfo.kinddict[a:tag1.fields.kind] <# typeinfo.kinddict[a:tag2.fields.kind]
E716: Key not present in Dictionary: m

I had to disable this plugin as it was impossible to work with it and I was updating and re-checking since this problems started. I've seen other issues with similar problems for JS/bash so I was just waiting to see how it goes but I don't see any progress. I'm using universal-ctags and I've seen in those issues that this can be related, but it doesn't exists a package for the old "exuberant-ctags" on my distro...

If there is any more info I can collect to help understand this problem just let me know.

raven42 commented 4 years ago

Do you have a sample perl script that generates this error? I only have a few small perl scripts and I do not see this error when I open them up.

diegok commented 4 years ago

Sure, I've just reproduced this problem here:

It's not a script, but a class using moose. This used to work and it was able to list attributes, methods and everything picked up by ctags. This is what I get by running ctags against this file:

!_TAG_FILE_FORMAT   2   /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED   1   /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_OUTPUT_FILESEP    slash   /slash or backslash/
!_TAG_OUTPUT_MODE   u-ctags /u-ctags or e-ctags/
!_TAG_PROGRAM_AUTHOR    Universal Ctags Team    //
!_TAG_PROGRAM_NAME  Universal Ctags /Derived from Exuberant Ctags/
!_TAG_PROGRAM_URL   https://ctags.io/   /official site/
!_TAG_PROGRAM_VERSION   0.0.0   /a3c87ab5/
NOTE    lib/Resque/Job.pm   /^    NOTE: future versions will try to get the$/;" l
Resque::Job lib/Resque/Job.pm   /^package Resque::Job;$/;"  c
Resque::Job lib/Resque/Job.pm   /^package Resque::Job;$/;"  p
_payload_trigger    lib/Resque/Job.pm   /^sub _payload_trigger { shift->payload_reader(@_) }$/;"    m   class:Resque::Job
_payload_trigger    lib/Resque/Job.pm   /^sub _payload_trigger { shift->payload_reader(@_) }$/;"    s
args    lib/Resque/Job.pm   /^has args => ( is => 'rw', isa => 'ArrayRef', default => sub {[]} );$/;"   a   class:Resque::Job
class   lib/Resque/Job.pm   /^has class => ( is => 'rw', lazy => 1, default => sub { confess "This job needs a class to do som/;"   a   class:Resque::Job
dequeue lib/Resque/Job.pm   /^sub dequeue {$/;" m   class:Resque::Job
dequeue lib/Resque/Job.pm   /^sub dequeue {$/;" s
encode  lib/Resque/Job.pm   /^sub encode {$/;"  m   class:Resque::Job
encode  lib/Resque/Job.pm   /^sub encode {$/;"  s
enqueue lib/Resque/Job.pm   /^sub enqueue {$/;" m   class:Resque::Job
enqueue lib/Resque/Job.pm   /^sub enqueue {$/;" s
fail    lib/Resque/Job.pm   /^sub fail {$/;"    m   class:Resque::Job
fail    lib/Resque/Job.pm   /^sub fail {$/;"    s
payload lib/Resque/Job.pm   /^has payload => ($/;"  a   class:Resque::Job
payload_builder lib/Resque/Job.pm   /^sub payload_builder {+{$/;"   m   class:Resque::Job
payload_builder lib/Resque/Job.pm   /^sub payload_builder {+{$/;"   s
payload_reader  lib/Resque/Job.pm   /^sub payload_reader {$/;"  m   class:Resque::Job
payload_reader  lib/Resque/Job.pm   /^sub payload_reader {$/;"  s
perform lib/Resque/Job.pm   /^sub perform {$/;" m   class:Resque::Job
perform lib/Resque/Job.pm   /^sub perform {$/;" s
queue   lib/Resque/Job.pm   /^has queue => ($/;"    a   class:Resque::Job
queue_from_class    lib/Resque/Job.pm   /^sub queue_from_class {$/;"    m   class:Resque::Job
queue_from_class    lib/Resque/Job.pm   /^sub queue_from_class {$/;"    s
resque  lib/Resque/Job.pm   /^has resque  => ($/;"  a   class:Resque::Job
stringify   lib/Resque/Job.pm   /^sub stringify {$/;"   m   class:Resque::Job
stringify   lib/Resque/Job.pm   /^sub stringify {$/;"   s
worker  lib/Resque/Job.pm   /^has worker  => ($/;"  a   class:Resque::Job
raven42 commented 4 years ago

I have a potential fix to address this globally for unknown kinds. I am not sure what the specifics of the perl m kind is, so #676 will not actually add proper handling for the m kind, but only prevent any tagbar failures when an unknown kind is found.

As a followup for this, someone more familiar with perl can update the perl type definition to include the proper m kind (and possibly the a kind too).

diegok commented 4 years ago

Hey @raven42 I can help out with this. I'm not familiar with ctags or vim script, but I'm all in to help improve this.

From what you've said and what I've pasted, m looks like method as in: fail lib/Resque/Job.pm /^sub fail {$/;" m class:Resque::Job but then I can see an s with the same line but without the class at the end, so I'm probably missing something here :-/

On the other hand the a looks like attribute which is what has is used for. To give you some more context, this is nos native perl but an convention provided by several libraries in CPAN which Moose is the most used and the one used by this example.

Just let me know if I can help in any other way and thank you!.

diegok commented 4 years ago

On your PR you've said:

This is occurring because there are unknown kinds found when running ctags. This results in a dictionary lookup because the perl type isn't handling these other kinds

Do you think I can improve the "perl type"?, where should I look to do so?

diegok commented 4 years ago

Ok, I answer myself:

I'll play around it :+1:

diegok commented 4 years ago

Done: https://github.com/preservim/tagbar/pull/677 :+1: