ra_ap_rust_analyzer/
lib.rs

1//! Implementation of the LSP for rust-analyzer.
2//!
3//! This crate takes Rust-specific analysis results from ide and translates
4//! into LSP types.
5//!
6//! It also is the root of all state. `world` module defines the bulk of the
7//! state, and `main_loop` module defines the rules for modifying it.
8//!
9//! The `cli` submodule implements some batch-processing analysis, primarily as
10//! a debugging aid.
11
12extern crate ra_ap_rustc_type_ir as rustc_type_ir;
13
14/// Any toolchain less than this version will likely not work with rust-analyzer built from this revision.
15pub const MINIMUM_SUPPORTED_TOOLCHAIN_VERSION: semver::Version = semver::Version {
16    major: 1,
17    minor: 78,
18    patch: 0,
19    pre: semver::Prerelease::EMPTY,
20    build: semver::BuildMetadata::EMPTY,
21};
22
23pub mod cli;
24
25mod command;
26mod diagnostics;
27mod discover;
28mod flycheck;
29mod line_index;
30mod main_loop;
31mod mem_docs;
32mod op_queue;
33mod reload;
34mod target_spec;
35mod task_pool;
36mod test_runner;
37mod version;
38
39mod handlers {
40    pub(crate) mod dispatch;
41    pub(crate) mod notification;
42    pub(crate) mod request;
43}
44
45pub mod tracing {
46    pub mod config;
47    pub mod json;
48    pub use config::Config;
49    pub mod hprof;
50}
51
52pub mod config;
53mod global_state;
54pub mod lsp;
55use self::lsp::ext as lsp_ext;
56
57#[cfg(test)]
58mod integrated_benchmarks;
59
60use serde::de::DeserializeOwned;
61
62pub use crate::{
63    lsp::capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
64    version::version,
65};
66
67pub fn from_json<T: DeserializeOwned>(
68    what: &'static str,
69    json: &serde_json::Value,
70) -> anyhow::Result<T> {
71    serde_json::from_value(json.clone())
72        .map_err(|e| anyhow::format_err!("Failed to deserialize {what}: {e}; {json}"))
73}
74
75#[doc(hidden)]
76macro_rules! try_default_ {
77    ($it:expr $(,)?) => {
78        match $it {
79            Some(it) => it,
80            None => return Ok(Default::default()),
81        }
82    };
83}
84pub(crate) use try_default_ as try_default;
85
86#[cfg(feature = "dhat")]
87#[global_allocator]
88static ALLOC: dhat::Alloc = dhat::Alloc;
89
90#[cfg(feature = "dhat")]
91static DHAT_PROFILER: std::sync::Mutex<Option<dhat::Profiler>> = std::sync::Mutex::new(None);