mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Reduce visibility
This commit is contained in:
parent
19b063e055
commit
012a7e57b9
3 changed files with 29 additions and 40 deletions
|
@ -167,7 +167,7 @@ impl GlobalState {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_configuration(&mut self, config: Config) {
|
pub(crate) fn update_configuration(&mut self, config: Config) {
|
||||||
self.analysis_host.update_lru_capacity(config.lru_capacity);
|
self.analysis_host.update_lru_capacity(config.lru_capacity);
|
||||||
if config.check != self.config.check {
|
if config.check != self.config.check {
|
||||||
self.flycheck =
|
self.flycheck =
|
||||||
|
@ -177,7 +177,7 @@ impl GlobalState {
|
||||||
self.config = config;
|
self.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_changes(&mut self) -> bool {
|
pub(crate) fn process_changes(&mut self) -> bool {
|
||||||
let change = {
|
let change = {
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
let (vfs, line_endings_map) = &mut *self.vfs.write();
|
let (vfs, line_endings_map) = &mut *self.vfs.write();
|
||||||
|
@ -215,7 +215,7 @@ impl GlobalState {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn snapshot(&self) -> GlobalStateSnapshot {
|
pub(crate) fn snapshot(&self) -> GlobalStateSnapshot {
|
||||||
GlobalStateSnapshot {
|
GlobalStateSnapshot {
|
||||||
config: self.config.clone(),
|
config: self.config.clone(),
|
||||||
workspaces: Arc::clone(&self.workspaces),
|
workspaces: Arc::clone(&self.workspaces),
|
||||||
|
@ -226,11 +226,11 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maybe_collect_garbage(&mut self) {
|
pub(crate) fn maybe_collect_garbage(&mut self) {
|
||||||
self.analysis_host.maybe_collect_garbage()
|
self.analysis_host.maybe_collect_garbage()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collect_garbage(&mut self) {
|
pub(crate) fn collect_garbage(&mut self) {
|
||||||
self.analysis_host.collect_garbage()
|
self.analysis_host.collect_garbage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,32 @@ use serde::de::DeserializeOwned;
|
||||||
pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
|
pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
caps::server_capabilities,
|
caps::server_capabilities,
|
||||||
main_loop::LspError,
|
|
||||||
main_loop::{main_loop, show_message},
|
main_loop::{main_loop, show_message},
|
||||||
};
|
};
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
|
pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
|
||||||
let res = T::deserialize(&json)
|
let res = T::deserialize(&json)
|
||||||
.map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
|
.map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct LspError {
|
||||||
|
code: i32,
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LspError {
|
||||||
|
fn new(code: i32, message: String) -> LspError {
|
||||||
|
LspError { code, message }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for LspError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for LspError {}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
//! The main loop of `rust-analyzer` responsible for dispatching LSP
|
//! The main loop of `rust-analyzer` responsible for dispatching LSP
|
||||||
//! requests/replies and notifications back to the client.
|
//! requests/replies and notifications back to the client.
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
env, fmt,
|
||||||
error::Error,
|
|
||||||
fmt,
|
|
||||||
ops::Range,
|
ops::Range,
|
||||||
panic,
|
panic,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
@ -28,31 +26,9 @@ use crate::{
|
||||||
global_state::{file_id_to_url, GlobalState, GlobalStateSnapshot, Status},
|
global_state::{file_id_to_url, GlobalState, GlobalStateSnapshot, Status},
|
||||||
handlers, lsp_ext,
|
handlers, lsp_ext,
|
||||||
request_metrics::RequestMetrics,
|
request_metrics::RequestMetrics,
|
||||||
Result,
|
LspError, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct LspError {
|
|
||||||
pub code: i32,
|
|
||||||
pub message: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LspError {
|
|
||||||
pub const UNKNOWN_FILE: i32 = -32900;
|
|
||||||
|
|
||||||
pub fn new(code: i32, message: String) -> LspError {
|
|
||||||
LspError { code, message }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for LspError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for LspError {}
|
|
||||||
|
|
||||||
pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
|
pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
|
||||||
log::info!("initial config: {:#?}", config);
|
log::info!("initial config: {:#?}", config);
|
||||||
|
|
||||||
|
@ -848,14 +824,7 @@ where
|
||||||
let response = match result {
|
let response = match result {
|
||||||
Ok(resp) => Response::new_ok(id, &resp),
|
Ok(resp) => Response::new_ok(id, &resp),
|
||||||
Err(e) => match e.downcast::<LspError>() {
|
Err(e) => match e.downcast::<LspError>() {
|
||||||
Ok(lsp_error) => {
|
Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message),
|
||||||
if lsp_error.code == LspError::UNKNOWN_FILE {
|
|
||||||
// Work-around for https://github.com/rust-analyzer/rust-analyzer/issues/1521
|
|
||||||
Response::new_ok(id, ())
|
|
||||||
} else {
|
|
||||||
Response::new_err(id, lsp_error.code, lsp_error.message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if is_canceled(&e) {
|
if is_canceled(&e) {
|
||||||
Response::new_err(
|
Response::new_err(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue