|
| 1 | +//! Available remote procedure call (RPC) interfaces. |
| 2 | +
|
| 3 | +use std::collections::{HashMap, HashSet}; |
| 4 | +use std::path::PathBuf; |
| 5 | + |
| 6 | +use jsonrpc_derive::rpc; |
| 7 | +use serde::{Deserialize, Serialize}; |
| 8 | + |
| 9 | +pub use jsonrpc_core::{Error, Result}; |
| 10 | + |
| 11 | +// Separated because #[rpc] macro generated a `gen_client` mod and so two |
| 12 | +// interfaces cannot be derived in the same scope due to a generated name clash |
| 13 | +/// RPC interface for an overriden file loader to be used inside `rustc`. |
| 14 | +pub mod file_loader { |
| 15 | + use super::*; |
| 16 | + // Expanded via #[rpc] |
| 17 | + pub use gen_client::Client; |
| 18 | + pub use rpc_impl_Rpc::gen_server::Rpc as Server; |
| 19 | + |
| 20 | + #[rpc] |
| 21 | + /// RPC interface for an overriden file loader to be used inside `rustc`. |
| 22 | + pub trait Rpc { |
| 23 | + /// Query the existence of a file. |
| 24 | + #[rpc(name = "file_exists")] |
| 25 | + fn file_exists(&self, path: PathBuf) -> Result<bool>; |
| 26 | + |
| 27 | + /// Returns an absolute path to a file, if possible. |
| 28 | + #[rpc(name = "abs_path")] |
| 29 | + fn abs_path(&self, path: PathBuf) -> Result<Option<PathBuf>>; |
| 30 | + |
| 31 | + /// Read the contents of an UTF-8 file into memory. |
| 32 | + #[rpc(name = "read_file")] |
| 33 | + fn read_file(&self, path: PathBuf) -> Result<String>; |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +// Separated because #[rpc] macro generated a `gen_client` mod and so two |
| 38 | +// interfaces cannot be derived in the same scope due to a generated name clash |
| 39 | +/// RPC interface to feed back data from `rustc` instances. |
| 40 | +pub mod callbacks { |
| 41 | + use super::*; |
| 42 | + // Expanded via #[rpc] |
| 43 | + pub use gen_client::Client; |
| 44 | + pub use rpc_impl_Rpc::gen_server::Rpc as Server; |
| 45 | + |
| 46 | + #[rpc] |
| 47 | + /// RPC interface to feed back data from `rustc` instances. |
| 48 | + pub trait Rpc { |
| 49 | + /// Hands back computed analysis data for the compiled crate |
| 50 | + #[rpc(name = "complete_analysis")] |
| 51 | + fn complete_analysis(&self, analysis: rls_data::Analysis) -> Result<()>; |
| 52 | + |
| 53 | + /// Hands back computed input files for the compiled crate |
| 54 | + #[rpc(name = "input_files")] |
| 55 | + fn input_files(&self, input_files: HashMap<PathBuf, HashSet<Crate>>) -> Result<()>; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +/// Build system-agnostic, basic compilation unit |
| 60 | +#[derive(PartialEq, Eq, Hash, Debug, Clone, Deserialize, Serialize)] |
| 61 | +pub struct Crate { |
| 62 | + /// Crate name |
| 63 | + pub name: String, |
| 64 | + /// Optional path to a crate root |
| 65 | + pub src_path: Option<PathBuf>, |
| 66 | + /// Edition in which a given crate is compiled |
| 67 | + pub edition: Edition, |
| 68 | + /// From rustc; mainly used to group other properties used to disambiguate a |
| 69 | + /// given compilation unit. |
| 70 | + pub disambiguator: (u64, u64), |
| 71 | +} |
| 72 | + |
| 73 | +/// Rust edition |
| 74 | +#[derive(PartialEq, Eq, Hash, Debug, PartialOrd, Ord, Copy, Clone, Deserialize, Serialize)] |
| 75 | +pub enum Edition { |
| 76 | + /// Rust 2015 |
| 77 | + Edition2015, |
| 78 | + /// Rust 2018 |
| 79 | + Edition2018, |
| 80 | +} |
0 commit comments