@@ -10,7 +10,9 @@ use std::{
1010} ;
1111
1212use ariadne:: { Cache , Report , ReportBuilder , ReportKind , Source } ;
13- use lsp_types:: { DiagnosticTag , TextDocumentIdentifier , VersionedTextDocumentIdentifier } ;
13+ use lsp_types:: {
14+ DiagnosticTag , NumberOrString , TextDocumentIdentifier , VersionedTextDocumentIdentifier ,
15+ } ;
1416use pathdiff:: diff_paths;
1517
1618use crate :: pretty:: { Doc , SimplePretty } ;
@@ -421,7 +423,7 @@ pub struct Diagnostic(Box<DiagnosticInner>);
421423#[ derive( Debug ) ]
422424struct DiagnosticInner {
423425 kind : ReportKind < ' static > ,
424- code : Option < u32 > ,
426+ code : Option < NumberOrString > ,
425427 msg : Option < String > ,
426428 note : Option < String > ,
427429 location : Span ,
@@ -449,8 +451,8 @@ impl Diagnostic {
449451 self
450452 }
451453
452- /// Give this diagnostic a numerical code that may be used to more precisely look up the error in documentation .
453- pub fn with_code ( mut self , code : u32 ) -> Self {
454+ /// Give this diagnostic a code.
455+ pub fn with_code ( mut self , code : NumberOrString ) -> Self {
454456 self . 0 . code = Some ( code) ;
455457 self
456458 }
@@ -499,6 +501,10 @@ impl Diagnostic {
499501 let span = files. char_span ( self . 0 . location ) ;
500502 let mut builder = Report :: build ( self . 0 . kind , span) ;
501503 if let Some ( code) = self . 0 . code {
504+ let code = match code {
505+ NumberOrString :: Number ( code) => code. to_string ( ) ,
506+ NumberOrString :: String ( code) => code,
507+ } ;
502508 builder = builder. with_code ( code) ;
503509 }
504510 if let Some ( msg) = self . 0 . msg {
@@ -522,13 +528,10 @@ impl Diagnostic {
522528 let severity = match self . 0 . kind {
523529 ReportKind :: Error => lsp_types:: DiagnosticSeverity :: ERROR ,
524530 ReportKind :: Warning => lsp_types:: DiagnosticSeverity :: WARNING ,
525- ReportKind :: Advice => lsp_types:: DiagnosticSeverity :: HINT ,
531+ ReportKind :: Advice => lsp_types:: DiagnosticSeverity :: INFORMATION ,
526532 _ => lsp_types:: DiagnosticSeverity :: ERROR ,
527533 } ;
528- let code = self
529- . 0
530- . code
531- . map ( |code| lsp_types:: NumberOrString :: Number ( code as i32 ) ) ;
534+ let code = self . 0 . code . clone ( ) ;
532535 let message = self
533536 . 0
534537 . msg
@@ -597,7 +600,11 @@ impl Diagnostic {
597600/// exists to make debugging easier.
598601impl Display for Diagnostic {
599602 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
600- if let Some ( code) = self . 0 . code {
603+ if let Some ( code) = & self . 0 . code {
604+ let code = match code {
605+ NumberOrString :: Number ( code) => & code. to_string ( ) ,
606+ NumberOrString :: String ( code) => code,
607+ } ;
601608 write ! ( f, "[{}] " , code) ?;
602609 }
603610 write ! ( f, "{}: " , self . 0 . kind) ?;
0 commit comments