Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LspInfo for Java based LSP shows OpenJDK version (use serverInfo.version instead?) #3509

Open
schrieveslaach opened this issue Dec 14, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@schrieveslaach
Copy link

Description

sonarlint.nvim is a LSP that is based on Java which needs to be started with java -jar path/to/the/lsp.jar …more options… and when invoking :LspInfo it prints the Java version instead of the version of sonarlint-language-server because nvim-lspconfig invokes java --version which leads to following output:

- Client: `sonarlint.nvim` (id: 2, bufnr: [1])
  root directory:    ~/Projekte/Open-Source/sonarlint-language-server/
  filetypes:         
  cmd:               /usr/lib/jvm/java-17-openjdk/bin/java -jar ~/.local/share/nvim/mason/packages/sonarlint-language-server/extension/server/sonarlint-ls.jar -stdio -analyzers ~/.local/share/nvim/mason/share/sonarlint-analyzers/csharpenterprise.jar …
  version:           `openjdk 17.0.13 2024-10-15`
  executable:        true
  autostart:         false

The --version flag has been introduced to sonarlint-language-server via SonarSource/sonarlint-language-server#402, succeeded by SonarSource/sonarlint-language-server#410, and nvim-lspconfig needs to invoke java -jar path/to/the/lsp.jar --version.

Do you think there is a way to make nvim-lspconfig aware of such situations?

@schrieveslaach schrieveslaach added the bug Something isn't working label Dec 14, 2024
@justinmk
Copy link
Member

justinmk commented Dec 14, 2024

Known issue. Would need to make the logic smarter so that it can guess that /.../java -jar ~/.../*.jar is the server program.

@schrieveslaach
Copy link
Author

Known issue.

Oh, @justinmk, did I miss an open issue and should I close this one?

@schrieveslaach
Copy link
Author

schrieveslaach commented Dec 17, 2024

I just stumbled across serverInfo.version because sonarlint-language-server reports that. Shouldn't this be shown instead of trying to run the LSP with --version or -V or …?

@justinmk
Copy link
Member

I just stumbled across serverInfo.version

Nice! Not sure how I missed that. We should definitely try to use that instead.

@justinmk justinmk changed the title LspInfo for Java based LSP shows OpenJDK version LspInfo for Java based LSP shows OpenJDK version (use serverInfo.version instead?) Dec 17, 2024
@schrieveslaach
Copy link
Author

Happy that I made I helpful comment. 😉

@lithammer
Copy link
Collaborator

lithammer commented Dec 17, 2024

Would it make sense to do something like this in core (I can create a PR for discussion if it looks interesting)?

diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua
index 72043c18dd..92337b5076 100644
--- a/runtime/lua/vim/lsp/client.lua
+++ b/runtime/lua/vim/lsp/client.lua
@@ -174,6 +174,10 @@ local validate = vim.validate
 --- capabilities.
 --- @field server_capabilities lsp.ServerCapabilities?
 ---
+--- Response from the server sent on `initialize` describing information about
+--- the server.
+--- @field server_info lsp.ServerInfo?
+---
 --- A ring buffer (|vim.ringbuf()|) containing progress messages
 --- sent by the server.
 --- @field progress vim.lsp.Client.Progress
@@ -556,6 +560,10 @@ function Client:initialize()
       self.offset_encoding = self.server_capabilities.positionEncoding
     end
 
+    if result.serverInfo then
+      self.server_info = result.serverInfo
+    end
+
     if next(self.settings) then
       self:notify(ms.workspace_didChangeConfiguration, { settings = self.settings })
     end
diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua
index d2cf888d89..26018710fe 100644
--- a/runtime/lua/vim/lsp/health.lua
+++ b/runtime/lua/vim/lsp/health.lua
@@ -40,6 +40,7 @@ local function check_active_clients()
   local clients = vim.lsp.get_clients()
   if next(clients) then
     for _, client in pairs(clients) do
+      local server_version = vim.tbl_get(client, 'server_info', 'version') or 'n/a'
       local cmd ---@type string
       local ccmd = client.config.cmd
       if type(ccmd) == 'table' then
@@ -62,6 +63,7 @@ local function check_active_clients()
       end
       report_info(table.concat({
         string.format('%s (id: %d)', client.name, client.id),
+        string.format('- Version: %s', server_version),
         dirs_info,
         string.format('- Command: %s', cmd),
         string.format('- Settings: %s', vim.inspect(client.settings, { newline = '\n  ' })),

@justinmk
Copy link
Member

yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants