mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
[ty] Add rule link to server diagnostics (#18128)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
2abcd86c57
commit
b86960f18c
1 changed files with 14 additions and 3 deletions
|
@ -4,7 +4,7 @@ use lsp_types::request::DocumentDiagnosticRequest;
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
Diagnostic, DiagnosticSeverity, DiagnosticTag, DocumentDiagnosticParams,
|
Diagnostic, DiagnosticSeverity, DiagnosticTag, DocumentDiagnosticParams,
|
||||||
DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport,
|
DocumentDiagnosticReport, DocumentDiagnosticReportResult, FullDocumentDiagnosticReport,
|
||||||
NumberOrString, Range, RelatedFullDocumentDiagnosticReport, Url,
|
NumberOrString, Range, RelatedFullDocumentDiagnosticReport,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::document::ToRangeExt;
|
use crate::document::ToRangeExt;
|
||||||
|
@ -22,7 +22,7 @@ impl RequestHandler for DocumentDiagnosticRequestHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BackgroundDocumentRequestHandler for DocumentDiagnosticRequestHandler {
|
impl BackgroundDocumentRequestHandler for DocumentDiagnosticRequestHandler {
|
||||||
fn document_url(params: &DocumentDiagnosticParams) -> Cow<Url> {
|
fn document_url(params: &DocumentDiagnosticParams) -> Cow<lsp_types::Url> {
|
||||||
Cow::Borrowed(¶ms.text_document.uri)
|
Cow::Borrowed(¶ms.text_document.uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,12 +105,23 @@ fn to_lsp_diagnostic(
|
||||||
})
|
})
|
||||||
.filter(|mapped_tags| !mapped_tags.is_empty());
|
.filter(|mapped_tags| !mapped_tags.is_empty());
|
||||||
|
|
||||||
|
let code_description = diagnostic
|
||||||
|
.id()
|
||||||
|
.is_lint()
|
||||||
|
.then(|| {
|
||||||
|
Some(lsp_types::CodeDescription {
|
||||||
|
href: lsp_types::Url::parse(&format!("https://ty.dev/rules#{}", diagnostic.id()))
|
||||||
|
.ok()?,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
|
||||||
Diagnostic {
|
Diagnostic {
|
||||||
range,
|
range,
|
||||||
severity: Some(severity),
|
severity: Some(severity),
|
||||||
tags,
|
tags,
|
||||||
code: Some(NumberOrString::String(diagnostic.id().to_string())),
|
code: Some(NumberOrString::String(diagnostic.id().to_string())),
|
||||||
code_description: None,
|
code_description,
|
||||||
source: Some("ty".into()),
|
source: Some("ty".into()),
|
||||||
message: diagnostic.concise_message().to_string(),
|
message: diagnostic.concise_message().to_string(),
|
||||||
related_information: None,
|
related_information: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue