Skip to content

protols crashes when receiving foreign LSP notifications from other language servers #83

@vasigorc

Description

@vasigorc

Problem

protols crashes with a panic when it receives notifications from other LSP servers running in the same Neovim session. This happens in multi-language projects where multiple LSP servers are active simultaneously (in my case it is a project that uses Scala and Protocol Buffers).

Error

thread 'main' panicked at <REDACTED>.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/protols-0.11.5/src/main.rs:94:46:
called `Result::unwrap()` on an `Err` value: Routing("Unhandled notification: metals/didFocusTextDocument")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Steps to Reproduce

  1. Open a project containing both .proto and .scala files in Neovim
  2. Configure both protols (for Protocol Buffers) and metals (for Scala) LSP servers
  3. Open a .proto file (protols starts)
  4. Open a .scala file (metals starts)
  5. Focus on the Scala file
  6. protols crashes when metals sends metals/didFocusTextDocument notification

Environment

  • protols version: 0.11.5
    • I have attached the configuration that I am using for protols at the bottom of this description
    • Of note, I configured "scalameta/nvim-metals" to only be enabled for Scala files: ft = { "scala", "sbt" },
  • Editor: Neovim NVIM v0.11.1 with LazyVim
  • Other LSP servers: metals (Scala), but this could happen with any LSP server sending custom notifications

Root Cause

This is a known limitation of the underlying async-lsp library that protols uses. As documented in async-lsp issue #20, their library doesn't gracefully handle unknown notifications and crashes instead.

Suggested Solutions

Based on the async-lsp maintainer's response, protols could implement a no-op handler (link) - if needed manually implement handlers for common foreign notifications that simply ignore them. For foreign methods (not in lsp-types) wrappers could be added. FWIW, maybe you could simply ignore anything that is not of protols?

Impact

This makes protols unusable in polyglot projects where multiple LSP servers need to run simultaneously, which is a common development scenario.

Workaround

Currently, the only workaround is to use separate editor sessions for different file types, which significantly impacts developer workflow.

Current protols configuration:

return {
  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        -- Configure protols to only handle .proto files
        protols = {
          filetypes = { "proto" },
        },
-- Other server configurations     
    },
  },

  -- Ensure the necessary tools are installed through Mason
  {
    "williamboman/mason.nvim",
    opts = function(_, opts)
      opts.ensure_installed = opts.ensure_installed or {}
      vim.list_extend(opts.ensure_installed, {
        "protols", -- Protobuf support
      })
    end,
  },
}
  • I did use justrequire("lspconfig").protols.setup({}) for months before today with the same result...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions