Skip to content

Add LSP diagnostics to completion requests #448

@AndiLavera

Description

@AndiLavera

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Completion (aka next edit prediction, ai autocomplete, ai tab complete, etc) would benefit from LSP diagnostics.

Prior Art

Cursor

Info pulled from minified JS via an Agent. Take with a grain of salt.

Example JSON

The following JSON snippet is an example payload based on the keys in the bundle. This unfortunately was not logged or pulled from a running application.

{
  "linterErrors": {
    "relativeWorkspacePath": "src/parser.rs",
    "errors": [
      {
        "message": "expected `;`, found `}`",
        "source": "rustc",
        "uri": "file:///project/src/parser.rs",
        "severity": "ERROR",
        "range": {
          "startPosition": { "line": 42, "column": 5 },
          "endPosition": { "line": 42, "column": 6 }
        },
        "relatedInformation": []
      }
    ]
  },
  "lspSuggestedItems": { "suggestions": [{ "label": "parse_expr" }] },
  "parameterHints": [
    {
      "label": "fn read(path: &Path) -> Result<String, Error>",
      "documentation": "Reads the entire file into a string."
    }
  ],
  "lspContexts": []
}

(Real requests include many non-LSP fields: currentFile, diff histories, workspaceId, codeResults, timing, etc.)

Scope
  • linterErrors is for the current file only.
  • additionalFiles (visible-range snippets, paths, open files, recently viewed, etc.) can include other buffers when enableRvfTracking is enabled.

Zed

Zed is open source! Much easier to read. Zed sends LSP context in the user prompt. It looks like LSP diagnostics get serialized to a token friendly format and embedded into the prompt.

Link to Diagnostic type def
Link to collect_diagnostics
Link to user prompt type def

Zed also sends related_files from go to definition (from users cursor) and type defintions.

Outstanding Questions

  • What LSP info should be included in the completion request
    • Should the selected diagnostics be configurable in ECA config?
  • Would any other request types benefit from LSP information?
  • Should diagnostics be limited to the file being editted or should it include full workspace diagnostics?
    • It looks like Cursor and zed both support this but have booleans to enable. There is probably a reason for the boolean. May be good to test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions