Skip to content

Commit b86960f

Browse files
[ty] Add rule link to server diagnostics (#18128)
Co-authored-by: Micha Reiser <micha@reiser.io>
1 parent 2abcd86 commit b86960f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

crates/ty_server/src/server/api/requests/diagnostic.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use lsp_types::request::DocumentDiagnosticRequest;
44
use lsp_types::{
55
Diagnostic, DiagnosticSeverity, DiagnosticTag, DocumentDiagnosticParams,
66
DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport,
7-
NumberOrString, Range, RelatedFullDocumentDiagnosticReport, Url,
7+
NumberOrString, Range, RelatedFullDocumentDiagnosticReport,
88
};
99

1010
use crate::document::ToRangeExt;
@@ -22,7 +22,7 @@ impl RequestHandler for DocumentDiagnosticRequestHandler {
2222
}
2323

2424
impl BackgroundDocumentRequestHandler for DocumentDiagnosticRequestHandler {
25-
fn document_url(params: &DocumentDiagnosticParams) -> Cow<Url> {
25+
fn document_url(params: &DocumentDiagnosticParams) -> Cow<lsp_types::Url> {
2626
Cow::Borrowed(&params.text_document.uri)
2727
}
2828

@@ -105,12 +105,23 @@ fn to_lsp_diagnostic(
105105
})
106106
.filter(|mapped_tags| !mapped_tags.is_empty());
107107

108+
let code_description = diagnostic
109+
.id()
110+
.is_lint()
111+
.then(|| {
112+
Some(lsp_types::CodeDescription {
113+
href: lsp_types::Url::parse(&format!("https://ty.dev/rules#{}", diagnostic.id()))
114+
.ok()?,
115+
})
116+
})
117+
.flatten();
118+
108119
Diagnostic {
109120
range,
110121
severity: Some(severity),
111122
tags,
112123
code: Some(NumberOrString::String(diagnostic.id().to_string())),
113-
code_description: None,
124+
code_description,
114125
source: Some("ty".into()),
115126
message: diagnostic.concise_message().to_string(),
116127
related_information: None,

0 commit comments

Comments
 (0)