FractalBoy / perl-language-server

99 stars 12 forks source link

Trouble getting perlcriticrc to work for linting in Neovim #87

Closed CharlesARoy closed 2 years ago

CharlesARoy commented 2 years ago

Hello, I'm having a hard time getting linting to work with perlcriticrc and any pointers would be appreciated. With my current setup, I'm at least getting Perl autocomplete suggestions, so I know I'm almost there.

E.g.: image

image

My Neovim config looks like:

├── init.lua
├── lua
│   └── user
│       ├── alpha.lua
│       ├── autocommands.lua
│       ├── autopairs.lua
│       ├── bufferline.lua
│       ├── cmp.lua
│       ├── colorscheme.lua
│       ├── comment.lua
│       ├── gitsigns.lua
│       ├── icons.lua
│       ├── impatient.lua
│       ├── indentline.lua
│       ├── keymaps.lua
│       ├── lsp
│       │   ├── handlers.lua
│       │   ├── init.lua
│       │   ├── lsp-installer.lua
│       │   ├── null-ls.lua
│       │   ├── perlpls.lua
│       │   └── settings
│       │       ├── jsonls.lua
│       │       └── sumneko_lua.lua
│       ├── lualine.lua
│       ├── nvim-tree.lua
│       ├── options.lua
│       ├── plugins.lua
│       ├── project.lua
│       ├── telescope.lua
│       ├── toggleterm.lua
│       ├── treesitter.lua
│       └── whichkey.lua
└── plugin
    └── packer_compiled.lua

The init.lua file in the top directory requires the lsp directory which contains an init.lua file. That init.lua file looks like this: image

It requires the user.lsp.perlpls file which has this for content: image

Per the perl-language-server documentation, I installed the PLS, using the information at this link and ran cpanm PLS to install it.

Note, for all other language servers, I installed them using the nvim-lsp-installer, but unfortunately it doesn't support Perl.

My hope is that with Perl linting, I'll be able to get behavior like I have with Python, including goto definition, hover, etc. image

FractalBoy commented 2 years ago

I don't use Neovim, so I don't think I'll be of much help here. I don't think I was able to get it work the one time I tried.

@WhoIsSethDaniel contributed the instructions for how to use Neovim - can you help?

WhoIsSethDaniel commented 2 years ago

Hi @CharlesARoy. I may be able to help you. I use pls and perlcritic is working fine.

If you run perlcritic on a perl file do you receive output? What is it?

If you then use pls to work on the file do you not see the same errors?

Are you using a perlcriticrc file?

I assume you have Perl::Critic installed since pls requires Perl::Critic as a dependency.

If we start with a simple example: a single file in its own directory. Call it pc.pl with the following contents:

#!/usr/bin/env perl

print "hi there."

If you now run perlcritic on it you should see an error:

$ perlcritic pc.pl
Code before strictures are enabled at line 3, column 1.  See page 429 of PBP.  (Severity: 5)

If you then edit this file with neovim you should see the error in-line (typically in red, but may be different based on your theme -- I'm also assuming you have a default LSP configuration that has virtual text turned on). Screenshot from 2022-02-21 19-14-18

Verify that PLS is running.

If you do not see an error when running perlcritic than something is wrong with your perlcritic installation. Or you have a perlcriticrc file lying around that has non-default rules.

If you continue to have problems please let us know what version of neovim you are running and what plugins you are using with it. You may try to whittle down the plugins to see if one of them is causing problems. Perhaps just use lspconfig while testing. Since you seem to be able to get python to work with lspconfig this probably isn't the problem, but better safe than sorry.

Your final comment suggests that you also don't have hover or go-to-definition working. Is this the case? All I can tell you is that it does work. We just need to figure out why it isn't working for you. Given the near infinite flexibility of neovim this can be difficult...which is why working with as few plugins as possible while testing is very useful.

CharlesARoy commented 2 years ago

Thanks so much for the detailed response @WhoIsSethDaniel !

It took me a bit but I got it figured out.

First off (and I know this isn't ideal), my Neovim config is based on the setup Chris@Machine describes in these videos (repo here), and I'm still figuring out some of the details behind the config.

First, I reorganized my setup slightly to the following (moving perlpls.lua to the settings directory):

tree
.
├── init.lua
├── lua
│   └── user
│       ├── alpha.lua
│       ├── autocommands.lua
│       ├── autopairs.lua
│       ├── bufferline.lua
│       ├── cmp.lua
│       ├── colorscheme.lua
│       ├── comment.lua
│       ├── gitsigns.lua
│       ├── icons.lua
│       ├── impatient.lua
│       ├── indentline.lua
│       ├── keymaps.lua
│       ├── lsp
│       │   ├── handlers.lua
│       │   ├── init.lua
│       │   ├── lsp-installer.lua
│       │   ├── null-ls.lua
│       │   └── settings
│       │       ├── jsonls.lua
│       │       ├── perlpls.lua
│       │       └── sumneko_lua.lua
│       ├── lualine.lua
│       ├── nvim-tree.lua
│       ├── options.lua
│       ├── plugins.lua
│       ├── project.lua
│       ├── telescope.lua
│       ├── toggleterm.lua
│       ├── treesitter.lua
│       └── whichkey.lua
└── plugin
    └── packer_compiled.lua

I then required the user.lsp.settings.perlpls file in the init.lua file in the lsp directory (which contains the following): image

Then, I configured the perlpls.lua file like this: image

Turns out that the reason linting wasn't working had to do with a part of Chris' config that I didn't (and still don't) understand very well, which is his handlers.lua file. Anyway, as I understand it, the on_attach and capabilities functions are loaded from the handlers.lua file and then added to the perlpls config settings with the vim.tbl_deep_extend command. Finally, the perlpls language server is setup with the local config and perl opts.