bscan / PerlNavigator

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

Neovim docs in README #8

Closed WhoIsSethDaniel closed 1 year ago

WhoIsSethDaniel commented 2 years ago

There should be a quick section about Neovim in the README, along with the sublime, vscode, etc... docs.

I can do this, but wanted to make sure you were aware.

FWIW, I've submitted a basic lspconfig configuration: https://github.com/neovim/nvim-lspconfig/pull/1756 And I've submitted an installer for nvim-lsp-installer: https://github.com/williamboman/nvim-lsp-installer/pull/522

I would recommend that people use the installer as, IMO, it makes everything a little bit easier. The installer takes advantage of the npm package you published awhile back. So remember to publish npm packages whenever you make changes. Once the above PRs are merged I can write a section for the README that details all this.

sdondley commented 2 years ago

Got a newb question: How does the installer work? I'm still pretty new at this lspconfig stuff. Better question: how do I use it?

WhoIsSethDaniel commented 2 years ago

Got a newb question: How does the installer work? I'm still pretty new at this lspconfig stuff. Better question: how do I use it?

It's not lspconfig. It's nvim-lsp-installer. You'd need to install that as a neovim plugin. When you bring up neovim you can type :LspInstall perlnavigator and it will install the server (assuming you have npm installed on your machine). It installs to $XDG_DATA_HOME/nvim/lsp_servers (in neovim you can see the $XDG_DATA_HOME path by using :echo stdpath('data'). How you pass the configuration is different when using the installer. It's all documented at the link I give above, but a very basic usage:

local i = require 'nvim-lsp-installer'

local function setup_servers()
  local servers = i.get_installed_servers()

  for _, server in pairs(servers) do
      -- the name of the server is in server.name
      local config = <config for the given server> 
      server:setup(config)
  end
end

setup_servers()

I install all of the servers I use using something like this (except PLS). I just worry about the config and I don't need to worry about anything else. Since I don't want to setup npm on my host this is great since a lot of the servers I use are nodejs based. But I also use it to install gopls and some other non-nodejs servers. nvim-lsp-installer will also inform me if there are updates (not all servers have a way to do this, but a lot do).

The installer will also setup cmd to be the correct thing. In the case of PerlNavigator the cmd would be set to something like cmd = { 'node', '<path to server.js>', '--stdio' }.

bscan commented 2 years ago

Hi @WhoIsSethDaniel , sorry for the delay on this one. I'm very interested in installation instructions for Neovim if you're interested in submitting a pull request. Looks like both of your commits to the neovim repos have been merged. Somewhat related, Emacs lsp-mode also has a configuration for the Navigator: https://emacs-lsp.github.io/lsp-mode/page/lsp-perlnavigator/#installation and uses the pre-built binaries. For neovim, sounds like the installer is the way to go.

marcopolo4k commented 2 years ago

I'm also having issues, coming to neovim from vim.

So far, I've installed (via Plug) williamboman/nvim-lsp-installer, neovim/nvim-lspconfig, and 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' }. LspInstall perlnavigator also seemed to complete without errors.

I deleted the ctags files I was using, so I could test this. The variable completion seems to be working lightning-fast Cntrl-P. I used set runtimepath^=~ ... source ~/.vimrc from https://neovim.io/doc/user/nvim.html#nvim-from-vim, so I'm guessing things are mostly installed.

But I'd like the go-to-definitions enabled, and Cntrl-] gives error E433: No tags file ... E426.

Of course, I've tried several things without success, but this seemed like it was going to be the most promising, changes to what I think is loaded by default: ~/.config/nvim/init.lua

vim.bo.omnifunc = 'v:lua.vim.lsp.omnifunc'
-- vim.api.nvim_buf_set_option(buf, "tagfunc", "v:lua.vim.lsp.tagfunc")
vim.api.nvim_buf_set_option(0, 'tagfunc', "v:lua.vim.lsp.tagfunc")

I try to test various of these configs by restarting nvim, then source ~/.config/nvim/init.lua for safe measure, but same error: E433: No tags file ... E426.

WhoIsSethDaniel commented 2 years ago

@cPMarco if you place the cursor under the thing you wish to see the definition of and then type :lua vim.lsp.buf.definition(). If that works then you have everything setup correctly...you just need to setup keymaps that call them. See the lspconfig docs for this (see: https://github.com/neovim/nvim-lspconfig#suggested-configuration, notice all the vim.keymap.set commands). Also important is the on_attach function that contains many of those keymaps.

If all that sounds like a lot you may want to look at: https://github.com/junnplus/nvim-lsp-setup. I don't know much about it but some people on Reddit seem to like it. The idea is that if you use this plugin (along with having lspconfig and nvim-lsp-installer) and only configure this plugin (see https://github.com/junnplus/nvim-lsp-setup#usage) it's simpler. It seems to do all the on_attach and keymap stuff for you.

For both of these solutions the default/suggested keymap for go-to-defintion is gd. You can make it C-] but that won't be the default.

bscan commented 1 year ago

This seems pretty much done at this point, especially as nvim-lspconfig has the instructions from @WhoIsSethDaniel . Thanks!

If there's any additional documentation detail needed, pull requests would be great.