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
12/// Any toolchain less than this version will likely not work with rust-analyzer built from this revision.
13pub const MINIMUM_SUPPORTED_TOOLCHAIN_VERSION: semver::Version = semver::Version {
14    major: 1,
15    minor: 78,
16    patch: 0,
17    pre: semver::Prerelease::EMPTY,
18    build: semver::BuildMetadata::EMPTY,
19};
20
21pub mod cli;
22
23mod command;
24mod diagnostics;
25mod discover;
26mod flycheck;
27mod hack_recover_crate_name;
28mod line_index;
29mod main_loop;
30mod mem_docs;
31mod op_queue;
32mod reload;
33mod target_spec;
34mod task_pool;
35mod test_runner;
36mod version;
37
38mod handlers {
39    pub(crate) mod dispatch;
40    pub(crate) mod notification;
41    pub(crate) mod request;
42}
43
44pub mod tracing {
45    pub mod config;
46    pub mod json;
47    pub use config::Config;
48    pub mod hprof;
49}
50
51pub mod config;
52mod global_state;
53pub mod lsp;
54use self::lsp::ext as lsp_ext;
55
56#[cfg(test)]
57mod integrated_benchmarks;
58
59use serde::de::DeserializeOwned;
60
61pub use crate::{
62    lsp::capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
63    version::version,
64};
65
66pub fn from_json<T: DeserializeOwned>(
67    what: &'static str,
68    json: &serde_json::Value,
69) -> anyhow::Result<T> {
70    serde_json::from_value(json.clone())
71        .map_err(|e| anyhow::format_err!("Failed to deserialize {what}: {e}; {json}"))
72}
73
74#[doc(hidden)]
75macro_rules! try_default_ {
76    ($it:expr $(,)?) => {
77        match $it {
78            Some(it) => it,
79            None => return Ok(Default::default()),
80        }
81    };
82}
83pub(crate) use try_default_ as try_default;