Skip to content

Definition request failures are reported as textDocument/declaration errors #1486

Closed

Description

@bodiam

Summary

textDocument/definition failures can be reported to users as textDocument/declaration failures. This makes it look like the client sent a declaration request even when the JSON-RPC traffic shows that the actual request was textDocument/definition.

I opened a small fix in #1485.

What I observed

While debugging Nix language server integration with nixd, the IDE showed this error:

Error while consuming 'textDocument/declaration' with language server 'nixd'
org.eclipse.lsp4j.jsonrpc.ResponseErrorException: unknown node type for definition

However, LSP traffic logging showed that the IDE was sending textDocument/definition, not textDocument/declaration:

{"jsonrpc":"2.0","id":"14","method":"textDocument/definition","params":{"textDocument":{"uri":"file:///.../devshell.nix"},"position":{"line":3,"character":12}}}

The language server then returned an error for that same definition request:

{"error":{"code":-32001,"message":"unknown node type for definition"},"id":"14","jsonrpc":"2.0"}

Root cause

LSPDefinitionSupport#getDefinitionFor calls TextDocumentService.definition(params), but passes LSPRequestConstants.TEXT_DOCUMENT_DECLARATION into CancellationSupport.execute(...).

That means CancellationSupport logs/reports definition request failures using the declaration request name.

Current code:

return cancellationSupport.execute(languageServer
                .getTextDocumentService()
                .definition(params), languageServer, LSPRequestConstants.TEXT_DOCUMENT_DECLARATION)
        .thenApplyAsync(locations -> LSPIJUtils.getLocations(locations, languageServer));

Expected code:

return cancellationSupport.execute(languageServer
                .getTextDocumentService()
                .definition(params), languageServer, LSPRequestConstants.TEXT_DOCUMENT_DEFINITION)
        .thenApplyAsync(locations -> LSPIJUtils.getLocations(locations, languageServer));

Impact

Users and plugin authors may chase declaration capability issues when the failing request is actually definition. In my case, nixd did not advertise declarationProvider, so the reported method made the diagnosis misleading until raw LSP traffic was inspected.

This may also explain reports like #1434 where the visible error mentions textDocument/declaration.

Verification

For #1485 I verified the patch with:

./gradlew compileJava

Activity

  1. bodiam commented on May 9, 2026

    @bodiam
    ContributorAuthor

    Hi @angelozerr, apologies for creating this AI PRs, but this is an issue I encountered while developing an IntelliJ plugin. I've tested it, and the PR fixes the issue. I tried creating a test for it, but the test is quite nasty, I don't think you'd appreciate it much.

  2. angelozerr commented on May 9, 2026

    @angelozerr
    Contributor

    Thanks @bodiam ! I merged your PR. When https://github.com/redhat-developer/lsp4ij/actions/runs/25597066966 will be finished (soon) you will able to install nighty build

  3. angelozerr commented on May 9, 2026

    @angelozerr
    Contributor

    Fixed with #1485

  4. added this to the 0.20.0 milestone on May 9, 2026
  5. added
    bug
    on May 9, 2026
  6. angelozerr commented on May 9, 2026

    @angelozerr
    Contributor

    While debugging Nix language server integration with nixd, the IDE showed this error:

    Where is your plugin?

  7. bodiam commented on May 10, 2026

    @bodiam
    ContributorAuthor

    While debugging Nix language server integration with nixd, the IDE showed this error:

    Where is your plugin?

    Thanks for merging this!

    I had published the plugin, but then I found a few issues (this being one of them), so I had to remove the plugin and fix those issues. I'm currently going through a few open source Nix projects to validate the plugin and fix another few issues I found while doing it, so I expect the plugin to be available this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions