rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.19k stars 1.59k forks source link

textDocument/publishDiagnostics: empty diagnostic messages #18174

Open andreaskrath opened 3 weeks ago

andreaskrath commented 3 weeks ago

I have a question regarding some empty diagnostic messages. As can be seen in the picture below, I am getting diagnostics on all enum variant fields in this scenario, however the diagnostics are just a whitespace character for the first two tuple fields (this is the reason there is a line, but no message).

Image

Looking at the rust-analyzer information, this can also be seen with multiple instances of the message key having a value of a whitespace character.

I am wondering if this is the intended behaviour, and the diagnostic "highlights" are just to indicate that there are three fields, with the third containing the message - or if there is supposed to be information on the first two fields, or if they are even supposed to be marked at all?

{
   "jsonrpc":"2.0",
   "method":"textDocument/publishDiagnostics",
   "params":{
      "uri":"file:///home/krath/Documents/kasm/src/instruction/mod.rs",
      "diagnostics":[
         {
            "range":{
               "start":{
                  "line":46,
                  "character":4
               },
               "end":{
                  "line":46,
                  "character":8
               }
            },
            "severity":4,
            "code":"E0061",
            "codeDescription":{
               "href":"https://doc.rust-lang.org/error-index.html#E0061"
            },
            "source":"rustc",
            "message":"tuple variant defined here",
            "relatedInformation":[
               {
                  "location":{
                     "uri":"file:///home/krath/Documents/kasm/src/decode/jump.rs",
                     "range":{
                        "start":{
                           "line":14,
                           "character":11
                        },
                        "end":{
                           "line":14,
                           "character":28
                        }
                     }
                  },
                  "message":"original diagnostic"
               }
            ]
         },
         {
            "range":{
               "start":{
                  "line":46,
                  "character":9
               },
               "end":{
                  "line":46,
                  "character":13
               }
            },
            "severity":4,
            "code":"E0023",
            "codeDescription":{
               "href":"https://doc.rust-lang.org/error-index.html#E0023"
            },
            "source":"rustc",
            "message":" ",
            "relatedInformation":[
               {
                  "location":{
                     "uri":"file:///home/krath/Documents/kasm/src/execute/mod.rs",
                     "range":{
                        "start":{
                           "line":43,
                           "character":40
                        },
                        "end":{
                           "line":43,
                           "character":47
                        }
                     }
                  },
                  "message":"original diagnostic"
               }
            ]
         },
         {
            "range":{
               "start":{
                  "line":46,
                  "character":15
               },
               "end":{
                  "line":46,
                  "character":28
               }
            },
            "severity":4,
            "code":"E0023",
            "codeDescription":{
               "href":"https://doc.rust-lang.org/error-index.html#E0023"
            },
            "source":"rustc",
            "message":" ",
            "relatedInformation":[
               {
                  "location":{
                     "uri":"file:///home/krath/Documents/kasm/src/execute/mod.rs",
                     "range":{
                        "start":{
                           "line":43,
                           "character":40
                        },
                        "end":{
                           "line":43,
                           "character":47
                        }
                     }
                  },
                  "message":"original diagnostic"
               }
            ]
         },
         {
            "range":{
               "start":{
                  "line":46,
                  "character":30
               },
               "end":{
                  "line":46,
                  "character":46
               }
            },
            "severity":4,
            "code":"E0023",
            "codeDescription":{
               "href":"https://doc.rust-lang.org/error-index.html#E0023"
            },
            "source":"rustc",
            "message":"tuple variant has 3 fields",
            "relatedInformation":[
               {
                  "location":{
                     "uri":"file:///home/krath/Documents/kasm/src/execute/mod.rs",
                     "range":{
                        "start":{
                           "line":43,
                           "character":40
                        },
                        "end":{
                           "line":43,
                           "character":47
                        }
                     }
                  },
                  "message":"original diagnostic"
               }
            ]
         }
      ],
      "version":0
   }
}
Veykril commented 3 weeks ago

We might be incorrectly destructing the subspans here, we shouldn't be producing empty diagnostics here I think