ra_ap_rust_analyzer/
lib.rs1#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]
13
14#[cfg(feature = "in-rust-tree")]
15extern crate rustc_driver as _;
16
17extern crate ra_ap_rustc_type_ir as rustc_type_ir;
18
19pub const MINIMUM_SUPPORTED_TOOLCHAIN_VERSION: semver::Version = semver::Version {
24 major: 1,
25 minor: 78,
26 patch: 0,
27 pre: semver::Prerelease::EMPTY,
28 build: semver::BuildMetadata::EMPTY,
29};
30
31pub mod cli;
32
33mod command;
34mod diagnostics;
35mod discover;
36mod flycheck;
37mod line_index;
38mod main_loop;
39mod mem_docs;
40mod op_queue;
41mod reload;
42mod target_spec;
43mod task_pool;
44mod test_runner;
45mod version;
46
47mod handlers {
48 pub(crate) mod dispatch;
49 pub(crate) mod notification;
50 pub(crate) mod request;
51}
52
53pub mod tracing {
54 pub mod config;
55 pub mod json;
56 pub use config::Config;
57 pub mod hprof;
58}
59
60pub mod config;
61mod global_state;
62pub mod lsp;
63use self::lsp::ext as lsp_ext;
64
65#[cfg(test)]
66mod integrated_benchmarks;
67
68use serde::de::DeserializeOwned;
69
70pub use crate::{
71 lsp::capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
72 version::version,
73};
74
75pub fn from_json<T: DeserializeOwned>(
76 what: &'static str,
77 json: &serde_json::Value,
78) -> anyhow::Result<T> {
79 serde_json::from_value(json.clone())
80 .map_err(|e| anyhow::format_err!("Failed to deserialize {what}: {e}; {json}"))
81}
82
83#[doc(hidden)]
84macro_rules! try_default_ {
85 ($it:expr $(,)?) => {
86 match $it {
87 Some(it) => it,
88 None => return Ok(Default::default()),
89 }
90 };
91}
92pub(crate) use try_default_ as try_default;
93
94#[cfg(feature = "dhat")]
95#[global_allocator]
96static ALLOC: dhat::Alloc = dhat::Alloc;
97
98#[cfg(feature = "dhat")]
99static DHAT_PROFILER: std::sync::Mutex<Option<dhat::Profiler>> = std::sync::Mutex::new(None);