mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
internal: Inline handlers module
This commit is contained in:
parent
cace5bb35d
commit
9e80c8571d
4 changed files with 58 additions and 59 deletions
|
@ -1,45 +0,0 @@
|
|||
//! This module is responsible for implementing handlers for Language Server
|
||||
//! Protocol. The majority of requests are fulfilled by calling into the
|
||||
//! `ide` crate.
|
||||
|
||||
use ide::AssistResolveStrategy;
|
||||
use lsp_types::{Diagnostic, DiagnosticTag, NumberOrString, Url};
|
||||
|
||||
use vfs::FileId;
|
||||
|
||||
use crate::{global_state::GlobalStateSnapshot, to_proto, Result};
|
||||
|
||||
pub(crate) mod request;
|
||||
pub(crate) mod notification;
|
||||
|
||||
pub(crate) fn publish_diagnostics(
|
||||
snap: &GlobalStateSnapshot,
|
||||
file_id: FileId,
|
||||
) -> Result<Vec<Diagnostic>> {
|
||||
let _p = profile::span("publish_diagnostics");
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
|
||||
let diagnostics: Vec<Diagnostic> = snap
|
||||
.analysis
|
||||
.diagnostics(&snap.config.diagnostics(), AssistResolveStrategy::None, file_id)?
|
||||
.into_iter()
|
||||
.map(|d| Diagnostic {
|
||||
range: to_proto::range(&line_index, d.range),
|
||||
severity: Some(to_proto::diagnostic_severity(d.severity)),
|
||||
code: Some(NumberOrString::String(d.code.as_str().to_string())),
|
||||
code_description: Some(lsp_types::CodeDescription {
|
||||
href: Url::parse(&format!(
|
||||
"https://rust-analyzer.github.io/manual.html#{}",
|
||||
d.code.as_str()
|
||||
))
|
||||
.unwrap(),
|
||||
}),
|
||||
source: Some("rust-analyzer".to_string()),
|
||||
message: d.message,
|
||||
related_information: None,
|
||||
tags: if d.unused { Some(vec![DiagnosticTag::UNNECESSARY]) } else { None },
|
||||
data: None,
|
||||
})
|
||||
.collect();
|
||||
Ok(diagnostics)
|
||||
}
|
|
@ -25,7 +25,6 @@ mod diff;
|
|||
mod dispatch;
|
||||
mod from_proto;
|
||||
mod global_state;
|
||||
mod handlers;
|
||||
mod line_index;
|
||||
mod lsp_utils;
|
||||
mod main_loop;
|
||||
|
@ -38,6 +37,11 @@ mod task_pool;
|
|||
mod to_proto;
|
||||
mod version;
|
||||
|
||||
mod handlers {
|
||||
pub(crate) mod notification;
|
||||
pub(crate) mod request;
|
||||
}
|
||||
|
||||
pub mod config;
|
||||
pub mod lsp_ext;
|
||||
|
||||
|
|
|
@ -764,15 +764,55 @@ impl GlobalState {
|
|||
|
||||
let snapshot = self.snapshot();
|
||||
self.task_pool.handle.spawn(move || {
|
||||
let _p = profile::span("publish_diagnostics");
|
||||
let diagnostics = subscriptions
|
||||
.into_iter()
|
||||
.filter_map(|file_id| {
|
||||
crate::handlers::publish_diagnostics(&snapshot, file_id)
|
||||
.ok()
|
||||
.map(|diags| (file_id, diags))
|
||||
let line_index = snapshot.file_line_index(file_id).ok()?;
|
||||
Some((
|
||||
file_id,
|
||||
line_index,
|
||||
snapshot
|
||||
.analysis
|
||||
.diagnostics(
|
||||
&snapshot.config.diagnostics(),
|
||||
ide::AssistResolveStrategy::None,
|
||||
file_id,
|
||||
)
|
||||
.ok()?,
|
||||
))
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
Task::Diagnostics(diagnostics)
|
||||
})
|
||||
.map(|(file_id, line_index, it)| {
|
||||
(
|
||||
file_id,
|
||||
it.into_iter()
|
||||
.map(move |d| lsp_types::Diagnostic {
|
||||
range: crate::to_proto::range(&line_index, d.range),
|
||||
severity: Some(crate::to_proto::diagnostic_severity(d.severity)),
|
||||
code: Some(lsp_types::NumberOrString::String(
|
||||
d.code.as_str().to_string(),
|
||||
)),
|
||||
code_description: Some(lsp_types::CodeDescription {
|
||||
href: lsp_types::Url::parse(&format!(
|
||||
"https://rust-analyzer.github.io/manual.html#{}",
|
||||
d.code.as_str()
|
||||
))
|
||||
.unwrap(),
|
||||
}),
|
||||
source: Some("rust-analyzer".to_string()),
|
||||
message: d.message,
|
||||
related_information: None,
|
||||
tags: if d.unused {
|
||||
Some(vec![lsp_types::DiagnosticTag::UNNECESSARY])
|
||||
} else {
|
||||
None
|
||||
},
|
||||
data: None,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
});
|
||||
Task::Diagnostics(diagnostics.collect())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue