diff options
-rw-r--r-- | crates/gen_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/lib.rs | 21 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/msg.rs | 19 | ||||
-rw-r--r-- | crates/gen_lsp_server/src/stdio.rs | 3 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_analysis/tests/tests.rs | 7 | ||||
-rw-r--r-- | crates/ra_cli/src/main.rs | 10 | ||||
-rw-r--r-- | crates/ra_editor/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/ra_editor/src/test_utils.rs | 5 | ||||
-rw-r--r-- | crates/ra_editor/src/typing.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 8 |
12 files changed, 29 insertions, 70 deletions
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index cf5c34a88..08b357b1e 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml | |||
@@ -1,4 +1,5 @@ | |||
1 | [package] | 1 | [package] |
2 | edition = "2018" | ||
2 | name = "gen_lsp_server" | 3 | name = "gen_lsp_server" |
3 | version = "0.1.0" | 4 | version = "0.1.0" |
4 | authors = ["Aleksey Kladov <[email protected]>"] | 5 | authors = ["Aleksey Kladov <[email protected]>"] |
diff --git a/crates/gen_lsp_server/src/lib.rs b/crates/gen_lsp_server/src/lib.rs index 5dab8f408..8779fbf0f 100644 --- a/crates/gen_lsp_server/src/lib.rs +++ b/crates/gen_lsp_server/src/lib.rs | |||
@@ -59,16 +59,7 @@ | |||
59 | //! } | 59 | //! } |
60 | //! ``` | 60 | //! ``` |
61 | 61 | ||
62 | #[macro_use] | 62 | use failure::{bail, format_err}; |
63 | extern crate failure; | ||
64 | #[macro_use] | ||
65 | extern crate log; | ||
66 | extern crate serde; | ||
67 | extern crate serde_json; | ||
68 | #[macro_use] | ||
69 | extern crate serde_derive; | ||
70 | extern crate crossbeam_channel; | ||
71 | extern crate languageserver_types; | ||
72 | 63 | ||
73 | mod msg; | 64 | mod msg; |
74 | mod stdio; | 65 | mod stdio; |
@@ -81,7 +72,7 @@ use languageserver_types::{ | |||
81 | }; | 72 | }; |
82 | 73 | ||
83 | pub type Result<T> = ::std::result::Result<T, failure::Error>; | 74 | pub type Result<T> = ::std::result::Result<T, failure::Error>; |
84 | pub use { | 75 | pub use crate::{ |
85 | msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, | 76 | msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError}, |
86 | stdio::{stdio_transport, Threads}, | 77 | stdio::{stdio_transport, Threads}, |
87 | }; | 78 | }; |
@@ -98,18 +89,18 @@ pub fn run_server( | |||
98 | sender: Sender<RawMessage>, | 89 | sender: Sender<RawMessage>, |
99 | server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>, | 90 | server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>, |
100 | ) -> Result<()> { | 91 | ) -> Result<()> { |
101 | info!("lsp server initializes"); | 92 | log::info!("lsp server initializes"); |
102 | let params = initialize(&receiver, &sender, caps)?; | 93 | let params = initialize(&receiver, &sender, caps)?; |
103 | info!("lsp server initialized, serving requests"); | 94 | log::info!("lsp server initialized, serving requests"); |
104 | server(params, &receiver, &sender)?; | 95 | server(params, &receiver, &sender)?; |
105 | info!("lsp server waiting for exit notification"); | 96 | log::info!("lsp server waiting for exit notification"); |
106 | match receiver.recv() { | 97 | match receiver.recv() { |
107 | Some(RawMessage::Notification(n)) => n | 98 | Some(RawMessage::Notification(n)) => n |
108 | .cast::<Exit>() | 99 | .cast::<Exit>() |
109 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, | 100 | .map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?, |
110 | m => bail!("unexpected message during shutdown: {:?}", m), | 101 | m => bail!("unexpected message during shutdown: {:?}", m), |
111 | } | 102 | } |
112 | info!("lsp server shutdown complete"); | 103 | log::info!("lsp server shutdown complete"); |
113 | Ok(()) | 104 | Ok(()) |
114 | } | 105 | } |
115 | 106 | ||
diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index e1b27c808..1e5384380 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs | |||
@@ -1,10 +1,11 @@ | |||
1 | use std::io::{BufRead, Write}; | 1 | use std::io::{BufRead, Write}; |
2 | 2 | ||
3 | use languageserver_types::{notification::Notification, request::Request}; | 3 | use languageserver_types::{notification::Notification, request::Request}; |
4 | use serde::{de::DeserializeOwned, Serialize}; | 4 | use serde_derive::{Deserialize, Serialize}; |
5 | use serde_json::{from_str, from_value, to_string, to_value, Value}; | 5 | use serde_json::{from_str, from_value, to_string, to_value, Value}; |
6 | use failure::{bail, format_err}; | ||
6 | 7 | ||
7 | use Result; | 8 | use crate::Result; |
8 | 9 | ||
9 | #[derive(Debug, Serialize, Deserialize, Clone)] | 10 | #[derive(Debug, Serialize, Deserialize, Clone)] |
10 | #[serde(untagged)] | 11 | #[serde(untagged)] |
@@ -91,7 +92,7 @@ impl RawRequest { | |||
91 | pub fn new<R>(id: u64, params: &R::Params) -> RawRequest | 92 | pub fn new<R>(id: u64, params: &R::Params) -> RawRequest |
92 | where | 93 | where |
93 | R: Request, | 94 | R: Request, |
94 | R::Params: Serialize, | 95 | R::Params: serde::Serialize, |
95 | { | 96 | { |
96 | RawRequest { | 97 | RawRequest { |
97 | id, | 98 | id, |
@@ -102,7 +103,7 @@ impl RawRequest { | |||
102 | pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> | 103 | pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest> |
103 | where | 104 | where |
104 | R: Request, | 105 | R: Request, |
105 | R::Params: DeserializeOwned, | 106 | R::Params: serde::de::DeserializeOwned, |
106 | { | 107 | { |
107 | if self.method != R::METHOD { | 108 | if self.method != R::METHOD { |
108 | return Err(self); | 109 | return Err(self); |
@@ -117,7 +118,7 @@ impl RawResponse { | |||
117 | pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse | 118 | pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse |
118 | where | 119 | where |
119 | R: Request, | 120 | R: Request, |
120 | R::Result: Serialize, | 121 | R::Result: serde::Serialize, |
121 | { | 122 | { |
122 | RawResponse { | 123 | RawResponse { |
123 | id, | 124 | id, |
@@ -143,7 +144,7 @@ impl RawNotification { | |||
143 | pub fn new<N>(params: &N::Params) -> RawNotification | 144 | pub fn new<N>(params: &N::Params) -> RawNotification |
144 | where | 145 | where |
145 | N: Notification, | 146 | N: Notification, |
146 | N::Params: Serialize, | 147 | N::Params: serde::Serialize, |
147 | { | 148 | { |
148 | RawNotification { | 149 | RawNotification { |
149 | method: N::METHOD.to_string(), | 150 | method: N::METHOD.to_string(), |
@@ -153,7 +154,7 @@ impl RawNotification { | |||
153 | pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> | 154 | pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification> |
154 | where | 155 | where |
155 | N: Notification, | 156 | N: Notification, |
156 | N::Params: DeserializeOwned, | 157 | N::Params: serde::de::DeserializeOwned, |
157 | { | 158 | { |
158 | if self.method != N::METHOD { | 159 | if self.method != N::METHOD { |
159 | return Err(self); | 160 | return Err(self); |
@@ -191,12 +192,12 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> { | |||
191 | buf.resize(size, 0); | 192 | buf.resize(size, 0); |
192 | inp.read_exact(&mut buf)?; | 193 | inp.read_exact(&mut buf)?; |
193 | let buf = String::from_utf8(buf)?; | 194 | let buf = String::from_utf8(buf)?; |
194 | debug!("< {}", buf); | 195 | log::debug!("< {}", buf); |
195 | Ok(Some(buf)) | 196 | Ok(Some(buf)) |
196 | } | 197 | } |
197 | 198 | ||
198 | fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> { | 199 | fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> { |
199 | debug!("> {}", msg); | 200 | log::debug!("> {}", msg); |
200 | write!(out, "Content-Length: {}\r\n\r\n", msg.len())?; | 201 | write!(out, "Content-Length: {}\r\n\r\n", msg.len())?; |
201 | out.write_all(msg.as_bytes())?; | 202 | out.write_all(msg.as_bytes())?; |
202 | out.flush()?; | 203 | out.flush()?; |
diff --git a/crates/gen_lsp_server/src/stdio.rs b/crates/gen_lsp_server/src/stdio.rs index 3d8a1712a..35d8e46d0 100644 --- a/crates/gen_lsp_server/src/stdio.rs +++ b/crates/gen_lsp_server/src/stdio.rs | |||
@@ -4,8 +4,9 @@ use std::{ | |||
4 | }; | 4 | }; |
5 | 5 | ||
6 | use crossbeam_channel::{bounded, Receiver, Sender}; | 6 | use crossbeam_channel::{bounded, Receiver, Sender}; |
7 | use failure::bail; | ||
7 | 8 | ||
8 | use {RawMessage, Result}; | 9 | use crate::{RawMessage, Result}; |
9 | 10 | ||
10 | pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { | 11 | pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { |
11 | let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16); | 12 | let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16); |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 90528edfd..4b8b10816 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -1,14 +1,6 @@ | |||
1 | //! ra_analyzer crate is the brain of Rust analyzer. It relies on the `salsa` | 1 | //! ra_analyzer crate is the brain of Rust analyzer. It relies on the `salsa` |
2 | //! crate, which provides and incremental on-demand database of facts. | 2 | //! crate, which provides and incremental on-demand database of facts. |
3 | 3 | ||
4 | extern crate fst; | ||
5 | extern crate ra_editor; | ||
6 | extern crate ra_syntax; | ||
7 | extern crate rayon; | ||
8 | extern crate relative_path; | ||
9 | extern crate rustc_hash; | ||
10 | extern crate salsa; | ||
11 | |||
12 | macro_rules! ctry { | 4 | macro_rules! ctry { |
13 | ($expr:expr) => { | 5 | ($expr:expr) => { |
14 | match $expr { | 6 | match $expr { |
diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 71d20dbe9..4ce2c5c85 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs | |||
@@ -1,10 +1,3 @@ | |||
1 | extern crate ra_analysis; | ||
2 | extern crate ra_editor; | ||
3 | extern crate ra_syntax; | ||
4 | extern crate relative_path; | ||
5 | extern crate rustc_hash; | ||
6 | extern crate test_utils; | ||
7 | |||
8 | use ra_syntax::TextRange; | 1 | use ra_syntax::TextRange; |
9 | use test_utils::assert_eq_dbg; | 2 | use test_utils::assert_eq_dbg; |
10 | 3 | ||
diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 5ca86df4d..939f7fe77 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs | |||
@@ -1,11 +1,3 @@ | |||
1 | extern crate clap; | ||
2 | #[macro_use] | ||
3 | extern crate failure; | ||
4 | extern crate join_to_string; | ||
5 | extern crate ra_editor; | ||
6 | extern crate ra_syntax; | ||
7 | extern crate tools; | ||
8 | |||
9 | use std::{fs, io::Read, path::Path, time::Instant}; | 1 | use std::{fs, io::Read, path::Path, time::Instant}; |
10 | 2 | ||
11 | use clap::{App, Arg, SubCommand}; | 3 | use clap::{App, Arg, SubCommand}; |
@@ -97,7 +89,7 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> { | |||
97 | *start_line <= line && line <= *start_line + t.text.lines().count() | 89 | *start_line <= line && line <= *start_line + t.text.lines().count() |
98 | }); | 90 | }); |
99 | let test = match test { | 91 | let test = match test { |
100 | None => bail!("No test found at line {} at {}", line, file.display()), | 92 | None => failure::bail!("No test found at line {} at {}", line, file.display()), |
101 | Some((_start_line, test)) => test, | 93 | Some((_start_line, test)) => test, |
102 | }; | 94 | }; |
103 | let file = SourceFileNode::parse(&test.text); | 95 | let file = SourceFileNode::parse(&test.text); |
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs index c6b116159..ce080ee97 100644 --- a/crates/ra_editor/src/lib.rs +++ b/crates/ra_editor/src/lib.rs | |||
@@ -1,12 +1,3 @@ | |||
1 | extern crate itertools; | ||
2 | extern crate join_to_string; | ||
3 | extern crate ra_syntax; | ||
4 | extern crate rustc_hash; | ||
5 | extern crate superslice; | ||
6 | #[cfg(test)] | ||
7 | #[macro_use] | ||
8 | extern crate test_utils as _test_utils; | ||
9 | |||
10 | mod code_actions; | 1 | mod code_actions; |
11 | mod edit; | 2 | mod edit; |
12 | mod extend_selection; | 3 | mod extend_selection; |
@@ -154,7 +145,7 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>( | |||
154 | #[cfg(test)] | 145 | #[cfg(test)] |
155 | mod tests { | 146 | mod tests { |
156 | use super::*; | 147 | use super::*; |
157 | use crate::test_utils::{add_cursor, assert_eq_dbg, extract_offset}; | 148 | use crate::test_utils::{add_cursor, assert_eq_dbg, extract_offset, assert_eq_text}; |
158 | 149 | ||
159 | #[test] | 150 | #[test] |
160 | fn test_highlighting() { | 151 | fn test_highlighting() { |
diff --git a/crates/ra_editor/src/test_utils.rs b/crates/ra_editor/src/test_utils.rs index cbeb6433b..f0a4f250a 100644 --- a/crates/ra_editor/src/test_utils.rs +++ b/crates/ra_editor/src/test_utils.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use crate::LocalEdit; | ||
2 | pub use crate::_test_utils::*; | ||
3 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 1 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; |
4 | 2 | ||
3 | use crate::LocalEdit; | ||
4 | pub use test_utils::*; | ||
5 | |||
5 | pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( | 6 | pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( |
6 | before: &str, | 7 | before: &str, |
7 | after: &str, | 8 | after: &str, |
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index f894d8392..9703e0371 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -238,7 +238,7 @@ fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { | |||
238 | #[cfg(test)] | 238 | #[cfg(test)] |
239 | mod tests { | 239 | mod tests { |
240 | use super::*; | 240 | use super::*; |
241 | use crate::test_utils::{add_cursor, check_action, extract_offset, extract_range}; | 241 | use crate::test_utils::{add_cursor, check_action, extract_offset, extract_range, assert_eq_text}; |
242 | 242 | ||
243 | fn check_join_lines(before: &str, after: &str) { | 243 | fn check_join_lines(before: &str, after: &str) { |
244 | check_action(before, after, |file, offset| { | 244 | check_action(before, after, |file, offset| { |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 56c61ae5d..0e5c9baad 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -20,10 +20,6 @@ | |||
20 | #![allow(missing_docs)] | 20 | #![allow(missing_docs)] |
21 | //#![warn(unreachable_pub)] // rust-lang/rust#47816 | 21 | //#![warn(unreachable_pub)] // rust-lang/rust#47816 |
22 | 22 | ||
23 | #[cfg(test)] | ||
24 | #[macro_use] | ||
25 | extern crate test_utils; | ||
26 | |||
27 | pub mod algo; | 23 | pub mod algo; |
28 | pub mod ast; | 24 | pub mod ast; |
29 | mod lexer; | 25 | mod lexer; |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index ddcb8f6f6..732fb0e4a 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -179,10 +179,10 @@ fn merge_errors( | |||
179 | 179 | ||
180 | #[cfg(test)] | 180 | #[cfg(test)] |
181 | mod tests { | 181 | mod tests { |
182 | use super::{ | 182 | use test_utils::{extract_range, assert_eq_text}; |
183 | super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, SourceFileNode}, | 183 | |
184 | reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef, | 184 | use crate::{SourceFileNode, text_utils::replace_range, utils::dump_tree }; |
185 | }; | 185 | use super::*; |
186 | 186 | ||
187 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) | 187 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) |
188 | where | 188 | where |