Camelcade / Perl5-IDEA

Perl5 plugins for IntelliJ IDEA
https://plugins.jetbrains.com/plugin/7796-perl/
Other
405 stars 76 forks source link

Implement smart addition of use statements #1634

Open temporaryhamper opened 6 years ago

temporaryhamper commented 6 years ago

Found with:

Steps to reproduce:

  1. File -> New -> Project...
  2. Select Perl5 module
  3. Click Next
  4. Enter a project location
  5. Click Finish
  6. Click OK to create the project directory
  7. Select the sources root in the Project tools window
  8. File -> New -> Package
  9. Enter lib as the package name
  10. Click OK to create the package
  11. Select the sources root in the Project tools window
  12. File -> New -> Package
  13. Enter src as the package name
  14. Click OK to create the package
  15. IntelliJ IDEA -> Preferences...
  16. Languages & Frameworks -> Perl5
  17. Select Project
  18. Select a Perl5 Interpreter
  19. Select your project's name
  20. Right-click lib and select Perl5 libraries
  21. Click OK to save your preferences
  22. Select lib in the Project tools window
  23. File -> New -> Perl5 File
  24. Enter MyModule as the file name
  25. Select Package kind
  26. Click OK to create the Perl module
  27. Select src in the Project tools window
  28. File -> New -> Perl5 File
  29. Enter myscript as the file name
  30. Select Script kind
  31. Click OK to create the Perl script

Add the following contents to MyModule.pm and save:

package MyModule;

use strict;
use warnings FATAL => 'all';

require Exporter;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
    hello_world
);

sub hello_world()
{
    print "Hello, world\n";
}

1;

Add the following contents to myscript.pl:

#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';

hello_world();

Expected results:

Actual results:

Check if sub has been defined, declared or aliased with a typeglob.


- The tooltip links to https://github.com/Camelcade/Perl5-IDEA/wiki/Subs-resolution-status for more information
- Whether you save `myscript.pl` or not doesn't make a difference

The following also doesn't help:
1. File -> Project Structure...
1. Select `Project`
1. Select a Java version for the Project SDK
1. Select `Modules`
1. Right-click `lib` and select `Sources`

It also doesn't help if you unmark the project root as `Sources`

If I'm doing something wrong, then I think this is at least a doc bug, as I couldn't find anything in the wiki documenting how to properly set up auto imports.
hurricup commented 6 years ago

And where is use MyModule in the myscript.pl ? :)

temporaryhamper commented 6 years ago

That's what I expect auto import to add. Much like what IDEs do for Java. I expect to type the name of a subroutine in a file and to see the module it's defined in to automatically be imported.

Type hello_world and that should trigger use MyModule qw(hello_world); (or at least use MyModule) to be added to the top of the file.

Additional detail, in case it's relevant:

hurricup commented 6 years ago

Oh now I see. I thought it's about not resovled imported sub. No, there is no such feature yet. But if You'll add use manually, it should work.