mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-14 08:57:34 +00:00
Auto merge of #14810 - Veykril:inline-module, r=Veykril
internal: Inline handlers module
This commit is contained in:
commit
2f8cd66fb4
4 changed files with 58 additions and 59 deletions
|
@ -38,18 +38,18 @@ pub fn layout_of_adt_query(
|
||||||
.map(|(fd, _)| layout_of_ty(db, &field_ty(db, def, fd, &subst), cx.krate))
|
.map(|(fd, _)| layout_of_ty(db, &field_ty(db, def, fd, &subst), cx.krate))
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
};
|
};
|
||||||
let (variants, is_enum, is_union, repr) = match def {
|
let (variants, repr) = match def {
|
||||||
AdtId::StructId(s) => {
|
AdtId::StructId(s) => {
|
||||||
let data = db.struct_data(s);
|
let data = db.struct_data(s);
|
||||||
let mut r = SmallVec::<[_; 1]>::new();
|
let mut r = SmallVec::<[_; 1]>::new();
|
||||||
r.push(handle_variant(s.into(), &data.variant_data)?);
|
r.push(handle_variant(s.into(), &data.variant_data)?);
|
||||||
(r, false, false, data.repr.unwrap_or_default())
|
(r, data.repr.unwrap_or_default())
|
||||||
}
|
}
|
||||||
AdtId::UnionId(id) => {
|
AdtId::UnionId(id) => {
|
||||||
let data = db.union_data(id);
|
let data = db.union_data(id);
|
||||||
let mut r = SmallVec::new();
|
let mut r = SmallVec::new();
|
||||||
r.push(handle_variant(id.into(), &data.variant_data)?);
|
r.push(handle_variant(id.into(), &data.variant_data)?);
|
||||||
(r, false, true, data.repr.unwrap_or_default())
|
(r, data.repr.unwrap_or_default())
|
||||||
}
|
}
|
||||||
AdtId::EnumId(e) => {
|
AdtId::EnumId(e) => {
|
||||||
let data = db.enum_data(e);
|
let data = db.enum_data(e);
|
||||||
|
@ -63,19 +63,19 @@ pub fn layout_of_adt_query(
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Result<SmallVec<_>, _>>()?;
|
.collect::<Result<SmallVec<_>, _>>()?;
|
||||||
(r, true, false, data.repr.unwrap_or_default())
|
(r, data.repr.unwrap_or_default())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let variants =
|
let variants =
|
||||||
variants.iter().map(|x| x.iter().collect::<Vec<_>>()).collect::<SmallVec<[_; 1]>>();
|
variants.iter().map(|x| x.iter().collect::<Vec<_>>()).collect::<SmallVec<[_; 1]>>();
|
||||||
let variants = variants.iter().map(|x| x.iter().collect()).collect();
|
let variants = variants.iter().map(|x| x.iter().collect()).collect();
|
||||||
if is_union {
|
if matches!(def, AdtId::UnionId(..)) {
|
||||||
cx.layout_of_union(&repr, &variants).ok_or(LayoutError::Unknown)
|
cx.layout_of_union(&repr, &variants).ok_or(LayoutError::Unknown)
|
||||||
} else {
|
} else {
|
||||||
cx.layout_of_struct_or_enum(
|
cx.layout_of_struct_or_enum(
|
||||||
&repr,
|
&repr,
|
||||||
&variants,
|
&variants,
|
||||||
is_enum,
|
matches!(def, AdtId::EnumId(..)),
|
||||||
is_unsafe_cell(db, def),
|
is_unsafe_cell(db, def),
|
||||||
layout_scalar_valid_range(db, def),
|
layout_scalar_valid_range(db, def),
|
||||||
|min, max| repr_discr(&dl, &repr, min, max).unwrap_or((Integer::I8, false)),
|
|min, max| repr_discr(&dl, &repr, min, max).unwrap_or((Integer::I8, false)),
|
||||||
|
@ -95,7 +95,7 @@ pub fn layout_of_adt_query(
|
||||||
// .iter_enumerated()
|
// .iter_enumerated()
|
||||||
// .any(|(i, v)| v.discr != ty::VariantDiscr::Relative(i.as_u32()))
|
// .any(|(i, v)| v.discr != ty::VariantDiscr::Relative(i.as_u32()))
|
||||||
repr.inhibit_enum_layout_opt(),
|
repr.inhibit_enum_layout_opt(),
|
||||||
!is_enum
|
!matches!(def, AdtId::EnumId(..))
|
||||||
&& variants
|
&& variants
|
||||||
.iter()
|
.iter()
|
||||||
.next()
|
.next()
|
||||||
|
|
|
@ -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 dispatch;
|
||||||
mod from_proto;
|
mod from_proto;
|
||||||
mod global_state;
|
mod global_state;
|
||||||
mod handlers;
|
|
||||||
mod line_index;
|
mod line_index;
|
||||||
mod lsp_utils;
|
mod lsp_utils;
|
||||||
mod main_loop;
|
mod main_loop;
|
||||||
|
@ -38,6 +37,11 @@ mod task_pool;
|
||||||
mod to_proto;
|
mod to_proto;
|
||||||
mod version;
|
mod version;
|
||||||
|
|
||||||
|
mod handlers {
|
||||||
|
pub(crate) mod notification;
|
||||||
|
pub(crate) mod request;
|
||||||
|
}
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod lsp_ext;
|
pub mod lsp_ext;
|
||||||
|
|
||||||
|
|
|
@ -764,15 +764,55 @@ impl GlobalState {
|
||||||
|
|
||||||
let snapshot = self.snapshot();
|
let snapshot = self.snapshot();
|
||||||
self.task_pool.handle.spawn(move || {
|
self.task_pool.handle.spawn(move || {
|
||||||
|
let _p = profile::span("publish_diagnostics");
|
||||||
let diagnostics = subscriptions
|
let diagnostics = subscriptions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|file_id| {
|
.filter_map(|file_id| {
|
||||||
crate::handlers::publish_diagnostics(&snapshot, file_id)
|
let line_index = snapshot.file_line_index(file_id).ok()?;
|
||||||
.ok()
|
Some((
|
||||||
.map(|diags| (file_id, diags))
|
file_id,
|
||||||
|
line_index,
|
||||||
|
snapshot
|
||||||
|
.analysis
|
||||||
|
.diagnostics(
|
||||||
|
&snapshot.config.diagnostics(),
|
||||||
|
ide::AssistResolveStrategy::None,
|
||||||
|
file_id,
|
||||||
|
)
|
||||||
|
.ok()?,
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.map(|(file_id, line_index, it)| {
|
||||||
Task::Diagnostics(diagnostics)
|
(
|
||||||
})
|
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…
Reference in a new issue