nvim-lspconfig icon indicating copy to clipboard operation
nvim-lspconfig copied to clipboard

PureScript & Spago

Open mkohlhaas opened this issue 2 years ago • 7 comments

Description

https://github.com/nwolverson/purescript-language-server/issues/176#issuecomment-1048831911

Neovim version

NVIM v0.6.1 Build type: Release LuaJIT 2.1.0-beta3 Compiled by void-buildslave@a-fsn-de

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

nvim-lsp-installer: require("nvim-lsp-installer.health").check()

nvim-lsp-installer report

  • OK: neovim version >= 0.6.0
  • OK: tar: tar (GNU tar) 1.34
  • OK: gzip: gzip 1.11
  • OK: curl: curl 7.81.0 (x86_64-unknown-linux-gnu) libcurl/7.81.0 OpenSSL/1.1.1l zlib/1.2.11 zstd/1.5.2 libssh2/1.9.0 ghttp2/1.46.0
  • OK: wget: GNU Wget 1.21.2 built on linux-gnu. - OK: python3: Python 3.10.2
  • OK: node: v17.2.0
  • OK: Ruby: ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
  • OK: Go: go version go1.17.6 linux/amd64
  • OK: sh: Ok
  • OK: bash: GNU bash, version 5.1.16(1)-release (x86_64-unknown-linux-gnu)
  • OK: PHP: PHP 7.4.27 (cli) (built: Jan 16 2022 20:13:08) ( NTS )
  • OK: Composer: Composer version 2.2.4 2022-01-08 12:30:42
  • OK: julia: julia version 1.6.1
  • OK: java: Ok
  • OK: RubyGem: 3.2.32
  • OK: npm: 8.3.0
  • OK: javac: Ok
  • OK: pip3: pip 22.0.3 from /usr/lib/python3.10/site-packages/pip (python 3.10)

Nvim-lspconfig version

ec7119b166b16e681f663fcbf16b7139b38172ae

Operating system and version

Void Linux

Affected language servers

PureScript

Steps to reproduce

  1. git clone https://github.com/mkohlhaas/qqqq
  2. cd qqqq
  3. nvim src/Main.purs
  4. Goto definition for function 'log'

Actual behavior

Error Message:

Output directory does not exist at '/home/schmidh/Gitrepos/qqqq/.spago/console/v5.0.0/output'. Ensure project is built, or check configuration of output directory and build command..                  
                                                                                                                                                                                                        
Ensure project is built with the same purs version as the IDE server is using                                                                                                                           
                                                                                                                                                                                                        
Request Actions:                                                                                                                                                                                        
1. Build project                                                                                                                                                                                        
Type number and <Enter> or click with the mouse (q or empty cancels):

Note: it searches for output directory.

No further code navigation with e.g. goto definition is possible.

In the background an additional language server is started!

For good measure the language server in .local/share/nvim/lsp_servers/purescript/node_modules/.bin/ is started, not the one which I installed part of the project and can be started from the command line.

If I create a project without a purescript-language-server I will get an error message stating that the language server could not be started. Actually the one which comes with the plugin is started (.local/share/nvim/lsp_servers/purescript/node_modules/.bin/purescript-language-server).

The problem is that the root_dir is not correctly determined. The spago files are PureScript projects itself. So several language servers are started. This solves the problem in my case: root_dir = util.root_pattern('output') (See also the links to my config files below in the section 'Minimal config'.)

See also: Language Server Issue: Neovim configuration

Expected behavior

Don't start several language servers.

Minimal config

See my lsp config:https://github.com/mkohlhaas/Dotfiles/blob/925642a717d50ea9b6cf9116a451358e5649a4fe/nvim/.config/nvim/lua/lsp/init.lua#L37

This line solves the problem: https://github.com/mkohlhaas/Dotfiles/blob/925642a717d50ea9b6cf9116a451358e5649a4fe/nvim/.config/nvim/lua/lsp/init.lua#L52

LSP log

https://gist.github.com/mkohlhaas/6f7efdf602cbbae6273c815d13124946

mkohlhaas avatar Feb 23 '22 14:02 mkohlhaas

Is the summary of this issue report, that the root pattern results in multiple servers started per project, and we should make the root pattern more restrictive?

mjlbach avatar Feb 23 '22 15:02 mjlbach

The essence of the problem is that dependencies are fetched from git and stored in a directory within the project, so any local file pattern for a file indicating a project (or a traversal to the first matching ancestor) will match inside those dependencies as well as the top level. As you indicate, this means multiple servers started per project, and those ones for nested directories will have the wrong context.

Not sure I can suggest the best approach starting from a given source file rather than a root directory/project initially - naively either the topmost such config file or one not nested in a path matching some ignorable pattern

nwolverson avatar Feb 23 '22 16:02 nwolverson

does this problem still exists?

glepnir avatar Sep 05 '22 11:09 glepnir

@glepnir Yes. I am trying to change root_dir in such a way that it returns false when there's a parent directory called ./spago but my Lua is failing me.

i-am-the-slime avatar Nov 11 '22 12:11 i-am-the-slime

I think this works:

              root_dir = function(path)  
                local util = require('lspconfig.util')
                if path:match('/.spago/') then
                  return nil
                end
                return util.root_pattern('bower.json', 'psc-package.json', 'spago.dhall', 'flake.nix', 'shell.nix')(path);
              end,

i-am-the-slime avatar Nov 11 '22 17:11 i-am-the-slime

I think this works:

              root_dir = function(path)  
                local util = require('lspconfig.util')
                if path:match('/.spago/') then
                  return nil
                end
                return util.root_pattern('bower.json', 'psc-package.json', 'spago.dhall', 'flake.nix', 'shell.nix')(path);
              end,

don't hardcode the path sep will be better should check iswindows. do you want to make a pr for this?

glepnir avatar Nov 12 '22 00:11 glepnir

I assumed / was the start of the regex. I can make a PR one day, I think.

i-am-the-slime avatar Nov 24 '22 09:11 i-am-the-slime