neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.31k stars 955 forks source link

LSP not working in `coc-groovy` if current path is not the file path #4859

Closed marslo closed 8 months ago

marslo commented 8 months ago

Result from CocInfo

LSP works:

## versions

vim version: NVIM v0.9.5
node version: v21.5.0
coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800
coc.nvim directory: /Users/marslo/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin

## Log of coc.nvim

2024-01-15T18:52:39.861 INFO (pid:49081) [plugin] - coc.nvim initialized with node: v21.5.0 after 447
2024-01-15T18:52:39.909 WARN (pid:49081) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. 
    at t.activate (/Users/marslo/.config/coc/extensions/node_modules/coc-groovy/lib/index.js:1:1755)
    at async /Users/marslo/.vim/plugged/coc.nvim/build/index.js:251:33328
2024-01-15T18:52:40.173 INFO (pid:49081) [extension:coc-groovy] - Starting Groovy Language Server with: /usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/bin/java -Dfile.encoding=utf-8 -noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -jar /Users/marslo/.config/coc/extensions/node_modules/coc-groovy/server/groovy-language-server-all.jar
2024-01-15T18:52:40.176 WARN (pid:49081) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. 
    at /Users/marslo/.config/coc/extensions/node_modules/coc-groovy/lib/index.js:1:2246
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-01-15T18:52:40.178 INFO (pid:49081) [language-client-index] - Language server "groovy" started with 49094
2024-01-15T18:52:40.445 WARN (pid:49081) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. 
    at /Users/marslo/.config/coc/extensions/node_modules/coc-groovy/lib/index.js:1:2057
2024-01-15T18:52:40.453 INFO (pid:49081) [extension:coc-groovy] - getBuiltClasspath: No build file was found to use for classpath generation.
2024-01-15T18:52:47.023 INFO (pid:49081) [attach] - receive notification: showInfo []

LSP not work:

## versions

vim version: NVIM v0.9.5
node version: v21.5.0
coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800
coc.nvim directory: /Users/marslo/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin

## Log of coc.nvim

2024-01-15T18:53:07.451 INFO (pid:49157) [plugin] - coc.nvim initialized with node: v21.5.0 after 419
2024-01-15T18:53:07.496 WARN (pid:49157) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. 
    at t.activate (/Users/marslo/.config/coc/extensions/node_modules/coc-groovy/lib/index.js:1:1755)
    at async /Users/marslo/.vim/plugged/coc.nvim/build/index.js:251:33328
2024-01-15T18:53:08.646 INFO (pid:49157) [extension:coc-groovy] - Starting Groovy Language Server with: /usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/bin/java -Dfile.encoding=utf-8 -noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -jar /Users/marslo/.config/coc/extensions/node_modules/coc-groovy/server/groovy-language-server-all.jar
2024-01-15T18:53:08.650 WARN (pid:49157) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. 
    at /Users/marslo/.config/coc/extensions/node_modules/coc-groovy/lib/index.js:1:2246
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-01-15T18:53:08.653 INFO (pid:49157) [language-client-index] - Language server "groovy" started with 49169
2024-01-15T18:53:17.293 WARN (pid:49157) [workspace] - workspace.showMessage is deprecated, please use window.showMessage instead. 
    at /Users/marslo/.config/coc/extensions/node_modules/coc-groovy/lib/index.js:1:2057
2024-01-15T18:53:17.301 INFO (pid:49157) [extension:coc-groovy] - getBuiltClasspath: No build file was found to use for classpath generation.
2024-01-15T18:53:17.445 INFO (pid:49157) [attach] - receive notification: showInfo []

Describe the bug

if current path same with the *.groovy, LSP working in coc ( i.e.: file: ~/a.groovy, pwd: ~ ). it will show as f [LS]

coc-groovy-lsp-1 coc-groovy-lsp-2

However, when current path is not the file path ( i.e.: cd .vim; nvim ~/a.groovy ), LSP won't work, it will show as [A]

coc-groovy-lsp-3

details as below:

https://github.com/neoclide/coc.nvim/assets/5822057/a2d977f9-af80-48a0-9d34-16859763a8bf

Reproduce the bug

We will close your issue when you don't provide minimal vimrc and we can't reproduce it

Can be reproduced in mini.vim

result:

https://github.com/neoclide/coc.nvim/assets/5822057/54677ca2-6c78-466c-a067-82afbc483d73

here my sample groovy file:

#!/usr/bin/env groovy

def foo( String str1, String str2 ) {
  println "${str1} ~> ${str2}"
}

def foo( List<String> list ) {
  println list.join(' ~> ')
}

def foo( Map<String, String> map ) {
  println map.collect{ "${it.key} ~> ${it.value}" }.join()
}
marslo commented 8 months ago

One more question I'm just curious, I've installed neovim/nvim-lspconfig and also well configured the gralde_ls, and it works in :LspInfo, but seems coc still using the own groovy lsp instead of nvim-lspconfig.

Here my gradlels details:

# install gradlels in system
$ mkdir -p ~/.vim/lsp
$ git clone https://github.com/microsoft/vscode-gradle.git ~/.vim/lsp/vscode-gradle && cd $_
$ ./gradlew installDist
$ sudo ln -sf /opt/lsp/gradle-language-server/build/install/gradle-language-server/bin/gradle-language-server /usr/local/bin/
$ which -a gradle-language-server
/usr/local/bin/gradle-language-server

vim settings:

Plug 'neovim/nvim-lspconfig'

lua settings:

-- ~/.config/nvim/init.lua
require('config/lsp')

-- ~/.config/nvim/lua/config/lsp.lua
require'lspconfig'.gradle_ls.setup{
  filetypes = { 'groovy', 'Jenkinsfile' }
}
fannheyward commented 8 months ago

cd .vim; nvim ~/a.groovy

In this case, coc uses your current folder as workspace root, here's .vim, sends to groovy language server. But language server couldn't find your file in workspace, won't work. Most language server needs workspace to work, you should start vim in it.

coc still using the own groovy lsp instead of nvim-lspconfig

coc didn't use language server from nvim-lspconfig.

marslo commented 8 months ago

Hi @fannheyward , any suggestion to setup the global workspace root?

And will you considering have configurable lsp for filetype? i.e.: I'm using groovy and Jenkinsfile most of time, I'd like to mapping Jenkinsfile to using groovy LSP as well, and using gradle_ls ( /usr/local/bin/gradle-language-server ) as first priority LSP ?

fannheyward commented 8 months ago
  1. LSP always needs a workspace to work, no global one.
  2. Some language server can work in single file mode, this needs language server support.
marslo commented 8 months ago

I'm kinda understand. So, coc.nvim is pretty much something similar with hrsh7th/nvim-cmp, another autocompletion engine. in coc.nvim all lsp are highly integrated via CocInstall coc-.., so I don't have to investigate or manual install every single lsp how to enable/setup/install/configure.

So, pretty much coc.nvim = nvim-cmp + nvim-cmp-lsp + nvim-lspconfig ? Will you considering have configurable lsp for filetype, I mean coc-xxx as second priority, and using something manual installed as first priority.

fannheyward commented 8 months ago

pretty much coc.nvim = nvim-cmp + nvim-cmp-lsp + nvim-lspconfig ?

Yes, and more.

configurable lsp for filetype, I mean coc-xxx as second priority, and using something manual installed as first priority.

Can't understand, more informations please.

marslo commented 8 months ago

So, for example, I'd like to use gradle_ls as LSP provider if coc-groovy not been installed.

something pretty much like "language server setup" And, how to mapping ft=Jenkinsfile to using groovy LSP ?

pretty much something like:

{
  "lspsettings" : {
    "coc-groovy" : {
      "filetype": { "groovy", "Jenkinsfile" },
      "cmd" : { "/usr/local/bin/gradle-language-server", "coc-groovy" },
      "autostart": true
    }
  }
}

so, coc will check /usr/local/bin/gradle-language-server exists or not:

btw: coc-groovy can be any of commands like java -jar /path/to/groovy-language-server-all.jar, or default means coc-groovy, or anything.