aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/gen_lsp_server/Cargo.toml1
-rw-r--r--crates/gen_lsp_server/src/lib.rs21
-rw-r--r--crates/gen_lsp_server/src/msg.rs19
-rw-r--r--crates/gen_lsp_server/src/stdio.rs3
-rw-r--r--crates/ra_analysis/src/lib.rs8
-rw-r--r--crates/ra_analysis/tests/tests.rs7
-rw-r--r--crates/ra_cli/src/main.rs10
-rw-r--r--crates/ra_editor/src/lib.rs11
-rw-r--r--crates/ra_editor/src/test_utils.rs5
-rw-r--r--crates/ra_editor/src/typing.rs2
-rw-r--r--crates/ra_syntax/src/lib.rs4
-rw-r--r--crates/ra_syntax/src/reparsing.rs8
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]
2edition = "2018"
2name = "gen_lsp_server" 3name = "gen_lsp_server"
3version = "0.1.0" 4version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"] 5authors = ["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] 62use failure::{bail, format_err};
63extern crate failure;
64#[macro_use]
65extern crate log;
66extern crate serde;
67extern crate serde_json;
68#[macro_use]
69extern crate serde_derive;
70extern crate crossbeam_channel;
71extern crate languageserver_types;
72 63
73mod msg; 64mod msg;
74mod stdio; 65mod stdio;
@@ -81,7 +72,7 @@ use languageserver_types::{
81}; 72};
82 73
83pub type Result<T> = ::std::result::Result<T, failure::Error>; 74pub type Result<T> = ::std::result::Result<T, failure::Error>;
84pub use { 75pub 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 @@
1use std::io::{BufRead, Write}; 1use std::io::{BufRead, Write};
2 2
3use languageserver_types::{notification::Notification, request::Request}; 3use languageserver_types::{notification::Notification, request::Request};
4use serde::{de::DeserializeOwned, Serialize}; 4use serde_derive::{Deserialize, Serialize};
5use serde_json::{from_str, from_value, to_string, to_value, Value}; 5use serde_json::{from_str, from_value, to_string, to_value, Value};
6use failure::{bail, format_err};
6 7
7use Result; 8use 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
198fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> { 199fn 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
6use crossbeam_channel::{bounded, Receiver, Sender}; 6use crossbeam_channel::{bounded, Receiver, Sender};
7use failure::bail;
7 8
8use {RawMessage, Result}; 9use crate::{RawMessage, Result};
9 10
10pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) { 11pub 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
4extern crate fst;
5extern crate ra_editor;
6extern crate ra_syntax;
7extern crate rayon;
8extern crate relative_path;
9extern crate rustc_hash;
10extern crate salsa;
11
12macro_rules! ctry { 4macro_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 @@
1extern crate ra_analysis;
2extern crate ra_editor;
3extern crate ra_syntax;
4extern crate relative_path;
5extern crate rustc_hash;
6extern crate test_utils;
7
8use ra_syntax::TextRange; 1use ra_syntax::TextRange;
9use test_utils::assert_eq_dbg; 2use 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 @@
1extern crate clap;
2#[macro_use]
3extern crate failure;
4extern crate join_to_string;
5extern crate ra_editor;
6extern crate ra_syntax;
7extern crate tools;
8
9use std::{fs, io::Read, path::Path, time::Instant}; 1use std::{fs, io::Read, path::Path, time::Instant};
10 2
11use clap::{App, Arg, SubCommand}; 3use 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 @@
1extern crate itertools;
2extern crate join_to_string;
3extern crate ra_syntax;
4extern crate rustc_hash;
5extern crate superslice;
6#[cfg(test)]
7#[macro_use]
8extern crate test_utils as _test_utils;
9
10mod code_actions; 1mod code_actions;
11mod edit; 2mod edit;
12mod extend_selection; 3mod extend_selection;
@@ -154,7 +145,7 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>(
154#[cfg(test)] 145#[cfg(test)]
155mod tests { 146mod 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 @@
1use crate::LocalEdit;
2pub use crate::_test_utils::*;
3use ra_syntax::{SourceFileNode, TextRange, TextUnit}; 1use ra_syntax::{SourceFileNode, TextRange, TextUnit};
4 2
3use crate::LocalEdit;
4pub use test_utils::*;
5
5pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>( 6pub 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)]
239mod tests { 239mod 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]
25extern crate test_utils;
26
27pub mod algo; 23pub mod algo;
28pub mod ast; 24pub mod ast;
29mod lexer; 25mod 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)]
181mod tests { 181mod 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