aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-24 23:35:22 +0100
committerAleksey Kladov <[email protected]>2020-06-25 00:02:08 +0100
commit012a7e57b9744bd8a40bdfe45ddb56954d559117 (patch)
treee104e716c008927054214b604a75cf5df3c0f4b7
parent19b063e055e9621a3af93b9bc6cfa20150ab0824 (diff)
Reduce visibility
-rw-r--r--crates/rust-analyzer/src/global_state.rs10
-rw-r--r--crates/rust-analyzer/src/lib.rs22
-rw-r--r--crates/rust-analyzer/src/main_loop.rs37
3 files changed, 29 insertions, 40 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index ad5f94e87..0b42b88ac 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -167,7 +167,7 @@ impl GlobalState {
167 res 167 res
168 } 168 }
169 169
170 pub fn update_configuration(&mut self, config: Config) { 170 pub(crate) fn update_configuration(&mut self, config: Config) {
171 self.analysis_host.update_lru_capacity(config.lru_capacity); 171 self.analysis_host.update_lru_capacity(config.lru_capacity);
172 if config.check != self.config.check { 172 if config.check != self.config.check {
173 self.flycheck = 173 self.flycheck =
@@ -177,7 +177,7 @@ impl GlobalState {
177 self.config = config; 177 self.config = config;
178 } 178 }
179 179
180 pub fn process_changes(&mut self) -> bool { 180 pub(crate) fn process_changes(&mut self) -> bool {
181 let change = { 181 let change = {
182 let mut change = AnalysisChange::new(); 182 let mut change = AnalysisChange::new();
183 let (vfs, line_endings_map) = &mut *self.vfs.write(); 183 let (vfs, line_endings_map) = &mut *self.vfs.write();
@@ -215,7 +215,7 @@ impl GlobalState {
215 true 215 true
216 } 216 }
217 217
218 pub fn snapshot(&self) -> GlobalStateSnapshot { 218 pub(crate) fn snapshot(&self) -> GlobalStateSnapshot {
219 GlobalStateSnapshot { 219 GlobalStateSnapshot {
220 config: self.config.clone(), 220 config: self.config.clone(),
221 workspaces: Arc::clone(&self.workspaces), 221 workspaces: Arc::clone(&self.workspaces),
@@ -226,11 +226,11 @@ impl GlobalState {
226 } 226 }
227 } 227 }
228 228
229 pub fn maybe_collect_garbage(&mut self) { 229 pub(crate) fn maybe_collect_garbage(&mut self) {
230 self.analysis_host.maybe_collect_garbage() 230 self.analysis_host.maybe_collect_garbage()
231 } 231 }
232 232
233 pub fn collect_garbage(&mut self) { 233 pub(crate) fn collect_garbage(&mut self) {
234 self.analysis_host.collect_garbage() 234 self.analysis_host.collect_garbage()
235 } 235 }
236 236
diff --git a/crates/rust-analyzer/src/lib.rs b/crates/rust-analyzer/src/lib.rs
index 9757a16a3..d6cd04303 100644
--- a/crates/rust-analyzer/src/lib.rs
+++ b/crates/rust-analyzer/src/lib.rs
@@ -37,12 +37,32 @@ use serde::de::DeserializeOwned;
37pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>; 37pub type Result<T, E = Box<dyn std::error::Error + Send + Sync>> = std::result::Result<T, E>;
38pub use crate::{ 38pub use crate::{
39 caps::server_capabilities, 39 caps::server_capabilities,
40 main_loop::LspError,
41 main_loop::{main_loop, show_message}, 40 main_loop::{main_loop, show_message},
42}; 41};
42use std::fmt;
43 43
44pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> { 44pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> {
45 let res = T::deserialize(&json) 45 let res = T::deserialize(&json)
46 .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?; 46 .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?;
47 Ok(res) 47 Ok(res)
48} 48}
49
50#[derive(Debug)]
51struct LspError {
52 code: i32,
53 message: String,
54}
55
56impl LspError {
57 fn new(code: i32, message: String) -> LspError {
58 LspError { code, message }
59 }
60}
61
62impl fmt::Display for LspError {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
65 }
66}
67
68impl std::error::Error for LspError {}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 02e188b02..1787e8c16 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -1,9 +1,7 @@
1//! The main loop of `rust-analyzer` responsible for dispatching LSP 1//! The main loop of `rust-analyzer` responsible for dispatching LSP
2//! requests/replies and notifications back to the client. 2//! requests/replies and notifications back to the client.
3use std::{ 3use std::{
4 env, 4 env, fmt,
5 error::Error,
6 fmt,
7 ops::Range, 5 ops::Range,
8 panic, 6 panic,
9 sync::Arc, 7 sync::Arc,
@@ -28,31 +26,9 @@ use crate::{
28 global_state::{file_id_to_url, GlobalState, GlobalStateSnapshot, Status}, 26 global_state::{file_id_to_url, GlobalState, GlobalStateSnapshot, Status},
29 handlers, lsp_ext, 27 handlers, lsp_ext,
30 request_metrics::RequestMetrics, 28 request_metrics::RequestMetrics,
31 Result, 29 LspError, Result,
32}; 30};
33 31
34#[derive(Debug)]
35pub struct LspError {
36 pub code: i32,
37 pub message: String,
38}
39
40impl LspError {
41 pub const UNKNOWN_FILE: i32 = -32900;
42
43 pub fn new(code: i32, message: String) -> LspError {
44 LspError { code, message }
45 }
46}
47
48impl fmt::Display for LspError {
49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50 write!(f, "Language Server request failed with {}. ({})", self.code, self.message)
51 }
52}
53
54impl Error for LspError {}
55
56pub fn main_loop(config: Config, connection: Connection) -> Result<()> { 32pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
57 log::info!("initial config: {:#?}", config); 33 log::info!("initial config: {:#?}", config);
58 34
@@ -848,14 +824,7 @@ where
848 let response = match result { 824 let response = match result {
849 Ok(resp) => Response::new_ok(id, &resp), 825 Ok(resp) => Response::new_ok(id, &resp),
850 Err(e) => match e.downcast::<LspError>() { 826 Err(e) => match e.downcast::<LspError>() {
851 Ok(lsp_error) => { 827 Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message),
852 if lsp_error.code == LspError::UNKNOWN_FILE {
853 // Work-around for https://github.com/rust-analyzer/rust-analyzer/issues/1521
854 Response::new_ok(id, ())
855 } else {
856 Response::new_err(id, lsp_error.code, lsp_error.message)
857 }
858 }
859 Err(e) => { 828 Err(e) => {
860 if is_canceled(&e) { 829 if is_canceled(&e) {
861 Response::new_err( 830 Response::new_err(