bscan / PerlNavigator

Perl Language Server that includes syntax checking, perl critic, and code navigation
MIT License
199 stars 39 forks source link

Completion works with neovim, but not very well #6

Closed sdondley closed 2 years ago

sdondley commented 2 years ago

Completion works, however, the completions options are extremely limited. The completion menu doesn't suggest built in keywords like print, for example. If I type in p, the only option is the parent Module. The only other completion suggestions that show up are identifiers in the file I'm currently editing.

Not sure if it's a configuratoin problem but the same exact settings I'm using worked 100% with PLS language server module.

bscan commented 2 years ago

Thanks for the report. Currently, I'm not showing keywords in the autocomplete, but that's a good suggestion. I've focused much more on contextual autocomplete, and narrowing down choices as opposed to adding more, which I generally find to be helpful. Here are some examples worth trying to make sure it is working correctly:

# While typing Pod::Text and Data::Dumper, you should get list of all installed modules including importable things found on your path
# This is because it is in the context of a "use" statement
use Math::BigInt;
use Data::Dumper;

# Here, you should only get Math::BigInt as an option, as opposed to all installed modules. 
# It should also show all the subs available on Math::BigInt with ->new as the first option. 
my $foo = Math::BigInt->new(16);

# $foo should autocomplete and more importantly, -> should show all the methods available on $foo specifically as a Math::BigInt object. 
print $foo->as_oct();

# Dumper was automatically exported from Data::Dumper into the symbol table, so will autocomplete as well.
print Dumper($foo);

Similarly, if you have any Moo/Moose objects, it will find all the method and attributes (including indicating method vs attribute) from the entire class hierarchy of the object. The code above is also a good test for hover and navigation, as you can "Go to definition" on new(), Dumper(), and as_oct(), or hover over anything to see more details.

sdondley commented 2 years ago

Wow, so I switched to a different completion plugin called COQ: https://github.com/ms-jpq/coq_nvim

It has a complete list of suggestions, including keywords.

Any idea how that happens?

sdondley commented 2 years ago

Ah, looking more closely, it's making suggestions for commands used by TMUX, not perl.

sdondley commented 2 years ago

By the way, COQ is "fast as fuck," as advertised. Here's my config that works:

local coq = require "coq"
local capabilities = vim.lsp.protocol.make_client_capabilities()

if not configs.perlnavigator then
  configs.perlnavigator = {
   default_config = {
     cmd = { "/usr/local/bin/node", "/Users/stevedondley/git_repos/PerlNavigator/server/out/server.js", "--stdio" },
     root_dir = function(fname)
       return lspconfig.util.find_git_ancestor(fname)
     end;
     on_attach = on_attach,
     flags = {
         debounce_text_changes = 150
     },

     --single_file_support = true,
     capabilities = capabilities,
     filetypes = { 'perl' };
     settings = { perlnavigator = {
         perlPath = '/Users/stevedondley/perl5/perlbrew/perls/perl-5.34.0/bin/perl',
         perlcriticProfile = '/Users/stevedondley/.perlcritic',
         perltidyProfile = '/Users/stevedondley/.perltidyrc' },
         selector = 'source.perl'
     };

   };
  }
end

lspconfig.perlnavigator.setup{ (coq.lsp_ensure_capabilities()) }

One tricky bit, if you don't set it up to autostart, it will not do anything. You have to kick it no manually with :COQnow. Took me 1/2 hour of flailing before I remembered this.