Skip to content

Pull diagnostics overwriting publish diagnostics #968

Closed

Description

@n1kolasM

Some LSP servers provide pull diagnostic support and publish diagnostics for different sources (e.g. rust-analyzer, rust-lang/rust-analyzer#18709 (comment)) and currently diagnostics will override each other.

Different sources of diagnostics should be processed separately (at least pull diagnostics with provided identifier should be processed separately from publish diagnostics and pull diagnostics with other identifiers).

Activity

  1. angelozerr commented on Apr 16, 2025

    @angelozerr
    Contributor

    Is there any chance to have a contribution for this issue?

  2. added
    bug
    on Apr 16, 2025
  3. n1kolasM commented on Apr 16, 2025

    @n1kolasM
    Author

    We have no plans to fix it yet, just disabling pull diagnostics in Huly Code for now

  4. angelozerr commented on Apr 16, 2025

    @angelozerr
    Contributor

    Ok no problem, could you explain how to reproduce this issue?

  5. n1kolasM commented on Apr 16, 2025

    @n1kolasM
    Author
    1. Create new rust project using cargo init and open it in IDEA
    2. Setup rust-analyzer lsp server, minimal version 2024-10-28, minimal version with added identifier for pull diagnostics 2025-03-03
    3. Open src/main.rs, replace file contents with
    fn main() {
        println!(None);
        let 
    }

    and use Ctrl-S to save file

    Expected result:
    Diagnostics highlighting None and let

    Actual result:
    Diagnostics highlighting only let

    Partial trace

    [Trace - 12:34:22] Sending notification 'textDocument/didSave'
    Params: {
      "textDocument": {
        "uri": "file:///sample-rust-project/src/main.rs"
      },
      "text": "fn main() {\n    println!(None);\n    let\n}"
    }
    [Trace - 12:34:22] Received notification 'textDocument/publishDiagnostics'
    Params: {
      "uri": "file:///sample-rust-project/src/main.rs",
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 3,
              "character": 0
            },
            "end": {
              "line": 3,
              "character": 1
            }
          },
          "severity": 1,
          "source": "rustc",
          "message": "expected pattern, found `}`\nexpected pattern",
          "data": {
            "rendered": "error: expected pattern, found `}`\n --\u003e src/main.rs:4:1\n  |\n4 | }\n  | ^ expected pattern\n\n"
          }
        }
      ],
      "version": 3
    }
    [Trace - 12:34:22] Received notification 'textDocument/publishDiagnostics'
    Params: {
      "uri": "file:///sample-rust-project/src/main.rs",
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 3,
              "character": 0
            },
            "end": {
              "line": 3,
              "character": 1
            }
          },
          "severity": 1,
          "source": "rustc",
          "message": "expected pattern, found `}`\nexpected pattern",
          "data": {
            "rendered": "error: expected pattern, found `}`\n --\u003e src/main.rs:4:1\n  |\n4 | }\n  | ^ expected pattern\n\n"
          }
        },
        {
          "range": {
            "start": {
              "line": 1,
              "character": 13
            },
            "end": {
              "line": 1,
              "character": 17
            }
          },
          "severity": 1,
          "source": "rustc",
          "message": "format argument must be a string literal",
          "relatedInformation": [
            {
              "location": {
                "uri": "file:///sample-rust-project/src/main.rs",
                "range": {
                  "start": {
                    "line": 1,
                    "character": 13
                  },
                  "end": {
                    "line": 1,
                    "character": 13
                  }
                }
              },
              "message": "you might be missing a string literal to format with: `\"{}\", `"
            }
          ],
          "data": {
            "rendered": "error: format argument must be a string literal\n --\u003e src/main.rs:2:14\n  |\n2 |     println!(None);\n  |              ^^^^\n  |\nhelp: you might be missing a string literal to format with\n  |\n2 |     println!(\"{}\", None);\n  |              +++++\n\n"
          }
        },
        {
          "range": {
            "start": {
              "line": 1,
              "character": 13
            },
            "end": {
              "line": 1,
              "character": 13
            }
          },
          "severity": 4,
          "source": "rustc",
          "message": "you might be missing a string literal to format with: `\"{}\", `",
          "relatedInformation": [
            {
              "location": {
                "uri": "file:///sample-rust-project/src/main.rs",
                "range": {
                  "start": {
                    "line": 1,
                    "character": 13
                  },
                  "end": {
                    "line": 1,
                    "character": 17
                  }
                }
              },
              "message": "original diagnostic"
            }
          ]
        }
      ],
      "version": 3
    }
    [Trace - 12:34:22] Sending request 'textDocument/diagnostic - (284)'.
    Params: {
      "textDocument": {
        "uri": "file:///sample-rust-project/src/main.rs"
      }
    }
    [Trace - 12:34:22] Received response 'textDocument/diagnostic - (284)' in 1ms.
    Result: {
      "kind": "full",
      "resultId": "rust-analyzer",
      "items": [
        {
          "range": {
            "start": {
              "line": 2,
              "character": 7
            },
            "end": {
              "line": 2,
              "character": 7
            }
          },
          "severity": 1,
          "code": "syntax-error",
          "codeDescription": {
            "href": "https://doc.rust-lang.org/stable/reference/"
          },
          "source": "rust-analyzer",
          "message": "Syntax Error: expected pattern"
        },
        {
          "range": {
            "start": {
              "line": 2,
              "character": 7
            },
            "end": {
              "line": 2,
              "character": 7
            }
          },
          "severity": 1,
          "code": "syntax-error",
          "codeDescription": {
            "href": "https://doc.rust-lang.org/stable/reference/"
          },
          "source": "rust-analyzer",
          "message": "Syntax Error: expected SEMICOLON"
        }
      ]
    }
    

  6. angelozerr commented on Apr 16, 2025

    @angelozerr
    Contributor

    Thanks for your detailled explanation!

    Let me investigate to implement a fix.

  7. self-assigned this
    on Apr 16, 2025
  8. added 2 commits that reference this issue on Apr 17, 2025
    76f0231
    1c70c5b
  9. moved this to In Progress in Java Toolingon Apr 17, 2025
  10. added 2 commits that reference this issue on Apr 18, 2025
    048b3e0
    d82f0be
  11. 5 remaining items

  12. added 10 commits that reference this issue on Apr 18, 2025
    2a6c291
    8b8bab1
    23d4783
    00b2e80
    3533dfb
    5b0804e
    09c6dbc
    becf373
    19236f1
    69f57d6
  13. moved this from In Progress to Done in Java Toolingon Apr 18, 2025
  14. added a commit that references this issue on Apr 18, 2025
    73a6fa6
  15. angelozerr commented on Apr 19, 2025

    @angelozerr
    Contributor

    @n1kolasM it should work. I have used your LSP traces to write tests and I have tested quicly with your sample andit is working.

    The only thing that I have noticed is that the first time (when file is opened in the editor), you don't see error from pull diagnostics because rust analyzer send an empty testDocument/diagnostics.

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

Metadata

Metadata

Assignees

Labels

bugdiagnostic

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions