Skip to content

Unprompted opening of noogle.dev #818

@JojOatXGME

Description

@JojOatXGME

Describe the bug

At the beginning of the year, I got the following bug report for using nixd in IntelliJ at NixOS/nix-idea#98:

Following #764 when using a recent nixd (e.g. from nixpkgs/unstable) whenever the cursor is on a symbol from lib.* and ANY key or mouse button is pressed, a new browser tab opens with https://noogle.dev/f/lib/abc

(A workaround has been implemented at NixOS/nix-idea#100 by @Meallia.)

I looked at some documentation, and I think nixd is actually not following the LSP specification. Specifically, nixd seems to treat codeAction/resolve at Controller::onCodeActionResolve as a signal, that the code action has been executed. However, that does not match the documentation by Microsoft:

The request is sent from the client to the server to resolve additional information for a given code action. This is usually used to compute the edit property of a code action to avoid its unnecessary computation during the textDocument/codeAction request.
Language Server Protocol Specification - 3.17

According to this documentation, codeAction/resolve only exists to allow for some lazy loading. It does not signal that the action is executed. While VSCode my only care about the edit property once it executes the actions, other IDEs my call this method early. Either because they do not implement lazy loading, or because they may for example want to show a preview of the changes.

Suggestion

After scanning over the specification, I suspect a correct implementation would need to follow the following steps, but I might be wrong since I am not very familiar with the language server protocol.

  • Define the availability of a command in the server capabilities:

    {
      ...
      "executeCommandProvider": {
        "commands": ["noogle.dev"]
      },
      ...
    }
  • Implement handler for the new command in workspace/executeCommand (This should match the current implementation of codeAction/resolve.)

  • Provide the "command" in the CodeAction body (you no-longer need "data"):

    {
      "title": "Open Noogle documentation for ...",
      "kind": "refactor",
      "command": {
        "title": "???",
        "command": "noogle.dev",
        "arguments": ["https://noogle.dev/..."]
      }
    }

To Reproduce

  1. Start IntelliJ
  2. Install the plugin nix-idea 0.4.0.19 or earlier
  3. Use nixd as the language server in Settings → Languages & Frameworks → Nix → Language Server (LSP)
  4. Navigate with the cursor to any usage of lib.* in a *.nix file

Expected behavior

Allow for normal navigation using the mouse or arrow keys.

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions