PerlNavigator icon indicating copy to clipboard operation
PerlNavigator copied to clipboard

textDocument/definition not working for shared package variables

Open cpakkala opened this issue 2 years ago • 1 comments

test.pm:

package perl_test;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw($SHARED_VAR shared_subroutine);
our $SHARED_VAR="BLAH";
sub shared_subroutine
{
  print "Shared routine\n";
}

test.pl:

use lib "./";
use test qw( shared_subroutine $SHARED_VAR );
&test::shared_subroutine();
test::shared_subroutine();
shared_subroutine();
print "$test::SHARED_VAR\n";
print "${test::SHARED_VAR}\n";
print "$SHARED_VAR\n" if $SHARED_VAR and ${SHARED_VAR};

textDocument/definition does not work on any of the above 5 instances of SHARED_VAR, but it does work for shared_routine...

cpakkala avatar Jun 19 '22 16:06 cpakkala

Thanks for the report. Unfortunately, this is currently a limitation of the Navigator. The navigator primarily works by parsing the symbol table, which gives the file and line of all subroutines it finds. For variables, they simply exist in the symbol table without additional metadata (or I simply can't find where that information would be). However, you can still get hover information about the $SHARED_VAR for 3 of those 5 instances. For example:

image

To fix these issues, I believe the Navigator needs to:

  1. Parse and tag all found dependencies with pltags.pm instead of solely relying on the symbol table. This would also benefit require statements. The tagger is how it currently finds the location of variables from the current file.
  2. Add support for package variables like $test::SHARED_VAR, which would also help for packages that use this technique as their primary configuration interface, such as Data::Dumper and $Data::Dumper::Varname.

I'll keep this ticket open to keep track of these issues. Thanks!

bscan avatar Jun 19 '22 20:06 bscan