mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Merge #260
260: Modernize r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
8e60e751cb
27 changed files with 82 additions and 180 deletions
|
@ -1,4 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
|
edition = "2018"
|
||||||
name = "gen_lsp_server"
|
name = "gen_lsp_server"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
|
@ -59,16 +59,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#[macro_use]
|
use failure::{bail, format_err};
|
||||||
extern crate failure;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
extern crate crossbeam_channel;
|
|
||||||
extern crate languageserver_types;
|
|
||||||
|
|
||||||
mod msg;
|
mod msg;
|
||||||
mod stdio;
|
mod stdio;
|
||||||
|
@ -81,7 +72,7 @@ use languageserver_types::{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
||||||
pub use {
|
pub use crate::{
|
||||||
msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError},
|
msg::{ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse, RawResponseError},
|
||||||
stdio::{stdio_transport, Threads},
|
stdio::{stdio_transport, Threads},
|
||||||
};
|
};
|
||||||
|
@ -98,18 +89,18 @@ pub fn run_server(
|
||||||
sender: Sender<RawMessage>,
|
sender: Sender<RawMessage>,
|
||||||
server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>,
|
server: impl FnOnce(InitializeParams, &Receiver<RawMessage>, &Sender<RawMessage>) -> Result<()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
info!("lsp server initializes");
|
log::info!("lsp server initializes");
|
||||||
let params = initialize(&receiver, &sender, caps)?;
|
let params = initialize(&receiver, &sender, caps)?;
|
||||||
info!("lsp server initialized, serving requests");
|
log::info!("lsp server initialized, serving requests");
|
||||||
server(params, &receiver, &sender)?;
|
server(params, &receiver, &sender)?;
|
||||||
info!("lsp server waiting for exit notification");
|
log::info!("lsp server waiting for exit notification");
|
||||||
match receiver.recv() {
|
match receiver.recv() {
|
||||||
Some(RawMessage::Notification(n)) => n
|
Some(RawMessage::Notification(n)) => n
|
||||||
.cast::<Exit>()
|
.cast::<Exit>()
|
||||||
.map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?,
|
.map_err(|n| format_err!("unexpected notification during shutdown: {:?}", n))?,
|
||||||
m => bail!("unexpected message during shutdown: {:?}", m),
|
m => bail!("unexpected message during shutdown: {:?}", m),
|
||||||
}
|
}
|
||||||
info!("lsp server shutdown complete");
|
log::info!("lsp server shutdown complete");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use std::io::{BufRead, Write};
|
use std::io::{BufRead, Write};
|
||||||
|
|
||||||
use languageserver_types::{notification::Notification, request::Request};
|
use languageserver_types::{notification::Notification, request::Request};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::{from_str, from_value, to_string, to_value, Value};
|
use serde_json::{from_str, from_value, to_string, to_value, Value};
|
||||||
|
use failure::{bail, format_err};
|
||||||
|
|
||||||
use Result;
|
use crate::Result;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
|
@ -91,7 +92,7 @@ impl RawRequest {
|
||||||
pub fn new<R>(id: u64, params: &R::Params) -> RawRequest
|
pub fn new<R>(id: u64, params: &R::Params) -> RawRequest
|
||||||
where
|
where
|
||||||
R: Request,
|
R: Request,
|
||||||
R::Params: Serialize,
|
R::Params: serde::Serialize,
|
||||||
{
|
{
|
||||||
RawRequest {
|
RawRequest {
|
||||||
id,
|
id,
|
||||||
|
@ -102,7 +103,7 @@ impl RawRequest {
|
||||||
pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest>
|
pub fn cast<R>(self) -> ::std::result::Result<(u64, R::Params), RawRequest>
|
||||||
where
|
where
|
||||||
R: Request,
|
R: Request,
|
||||||
R::Params: DeserializeOwned,
|
R::Params: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
if self.method != R::METHOD {
|
if self.method != R::METHOD {
|
||||||
return Err(self);
|
return Err(self);
|
||||||
|
@ -117,7 +118,7 @@ impl RawResponse {
|
||||||
pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse
|
pub fn ok<R>(id: u64, result: &R::Result) -> RawResponse
|
||||||
where
|
where
|
||||||
R: Request,
|
R: Request,
|
||||||
R::Result: Serialize,
|
R::Result: serde::Serialize,
|
||||||
{
|
{
|
||||||
RawResponse {
|
RawResponse {
|
||||||
id,
|
id,
|
||||||
|
@ -143,7 +144,7 @@ impl RawNotification {
|
||||||
pub fn new<N>(params: &N::Params) -> RawNotification
|
pub fn new<N>(params: &N::Params) -> RawNotification
|
||||||
where
|
where
|
||||||
N: Notification,
|
N: Notification,
|
||||||
N::Params: Serialize,
|
N::Params: serde::Serialize,
|
||||||
{
|
{
|
||||||
RawNotification {
|
RawNotification {
|
||||||
method: N::METHOD.to_string(),
|
method: N::METHOD.to_string(),
|
||||||
|
@ -153,7 +154,7 @@ impl RawNotification {
|
||||||
pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification>
|
pub fn cast<N>(self) -> ::std::result::Result<N::Params, RawNotification>
|
||||||
where
|
where
|
||||||
N: Notification,
|
N: Notification,
|
||||||
N::Params: DeserializeOwned,
|
N::Params: serde::de::DeserializeOwned,
|
||||||
{
|
{
|
||||||
if self.method != N::METHOD {
|
if self.method != N::METHOD {
|
||||||
return Err(self);
|
return Err(self);
|
||||||
|
@ -191,12 +192,12 @@ fn read_msg_text(inp: &mut impl BufRead) -> Result<Option<String>> {
|
||||||
buf.resize(size, 0);
|
buf.resize(size, 0);
|
||||||
inp.read_exact(&mut buf)?;
|
inp.read_exact(&mut buf)?;
|
||||||
let buf = String::from_utf8(buf)?;
|
let buf = String::from_utf8(buf)?;
|
||||||
debug!("< {}", buf);
|
log::debug!("< {}", buf);
|
||||||
Ok(Some(buf))
|
Ok(Some(buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> {
|
fn write_msg_text(out: &mut impl Write, msg: &str) -> Result<()> {
|
||||||
debug!("> {}", msg);
|
log::debug!("> {}", msg);
|
||||||
write!(out, "Content-Length: {}\r\n\r\n", msg.len())?;
|
write!(out, "Content-Length: {}\r\n\r\n", msg.len())?;
|
||||||
out.write_all(msg.as_bytes())?;
|
out.write_all(msg.as_bytes())?;
|
||||||
out.flush()?;
|
out.flush()?;
|
||||||
|
|
|
@ -4,8 +4,9 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||||
|
use failure::bail;
|
||||||
|
|
||||||
use {RawMessage, Result};
|
use crate::{RawMessage, Result};
|
||||||
|
|
||||||
pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) {
|
pub fn stdio_transport() -> (Receiver<RawMessage>, Sender<RawMessage>, Threads) {
|
||||||
let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16);
|
let (writer_sender, mut writer_receiver) = bounded::<RawMessage>(16);
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
//! ra_analyzer crate is the brain of Rust analyzer. It relies on the `salsa`
|
//! ra_analyzer crate is the brain of Rust analyzer. It relies on the `salsa`
|
||||||
//! crate, which provides and incremental on-demand database of facts.
|
//! crate, which provides and incremental on-demand database of facts.
|
||||||
|
|
||||||
extern crate fst;
|
|
||||||
extern crate ra_editor;
|
|
||||||
extern crate ra_syntax;
|
|
||||||
extern crate rayon;
|
|
||||||
extern crate relative_path;
|
|
||||||
extern crate rustc_hash;
|
|
||||||
extern crate salsa;
|
|
||||||
|
|
||||||
macro_rules! ctry {
|
macro_rules! ctry {
|
||||||
($expr:expr) => {
|
($expr:expr) => {
|
||||||
match $expr {
|
match $expr {
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
extern crate ra_analysis;
|
|
||||||
extern crate ra_editor;
|
|
||||||
extern crate ra_syntax;
|
|
||||||
extern crate relative_path;
|
|
||||||
extern crate rustc_hash;
|
|
||||||
extern crate test_utils;
|
|
||||||
|
|
||||||
use ra_syntax::TextRange;
|
use ra_syntax::TextRange;
|
||||||
use test_utils::assert_eq_dbg;
|
use test_utils::assert_eq_dbg;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
extern crate clap;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
extern crate join_to_string;
|
|
||||||
extern crate ra_editor;
|
|
||||||
extern crate ra_syntax;
|
|
||||||
extern crate tools;
|
|
||||||
|
|
||||||
use std::{fs, io::Read, path::Path, time::Instant};
|
use std::{fs, io::Read, path::Path, time::Instant};
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
|
@ -97,7 +89,7 @@ fn render_test(file: &Path, line: usize) -> Result<(String, String)> {
|
||||||
*start_line <= line && line <= *start_line + t.text.lines().count()
|
*start_line <= line && line <= *start_line + t.text.lines().count()
|
||||||
});
|
});
|
||||||
let test = match test {
|
let test = match test {
|
||||||
None => bail!("No test found at line {} at {}", line, file.display()),
|
None => failure::bail!("No test found at line {} at {}", line, file.display()),
|
||||||
Some((_start_line, test)) => test,
|
Some((_start_line, test)) => test,
|
||||||
};
|
};
|
||||||
let file = SourceFileNode::parse(&test.text);
|
let file = SourceFileNode::parse(&test.text);
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
extern crate itertools;
|
|
||||||
extern crate join_to_string;
|
|
||||||
extern crate ra_syntax;
|
|
||||||
extern crate rustc_hash;
|
|
||||||
extern crate superslice;
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate test_utils as _test_utils;
|
|
||||||
|
|
||||||
mod code_actions;
|
mod code_actions;
|
||||||
mod edit;
|
mod edit;
|
||||||
mod extend_selection;
|
mod extend_selection;
|
||||||
|
@ -154,7 +145,7 @@ pub fn find_node_at_offset<'a, N: AstNode<'a>>(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{add_cursor, assert_eq_dbg, extract_offset};
|
use crate::test_utils::{add_cursor, assert_eq_dbg, extract_offset, assert_eq_text};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_highlighting() {
|
fn test_highlighting() {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::LocalEdit;
|
|
||||||
pub use crate::_test_utils::*;
|
|
||||||
use ra_syntax::{SourceFileNode, TextRange, TextUnit};
|
use ra_syntax::{SourceFileNode, TextRange, TextUnit};
|
||||||
|
|
||||||
|
use crate::LocalEdit;
|
||||||
|
pub use test_utils::*;
|
||||||
|
|
||||||
pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>(
|
pub fn check_action<F: Fn(&SourceFileNode, TextUnit) -> Option<LocalEdit>>(
|
||||||
before: &str,
|
before: &str,
|
||||||
after: &str,
|
after: &str,
|
||||||
|
|
|
@ -238,7 +238,7 @@ fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::{add_cursor, check_action, extract_offset, extract_range};
|
use crate::test_utils::{add_cursor, check_action, extract_offset, extract_range, assert_eq_text};
|
||||||
|
|
||||||
fn check_join_lines(before: &str, after: &str) {
|
fn check_join_lines(before: &str, after: &str) {
|
||||||
check_action(before, after, |file, offset| {
|
check_action(before, after, |file, offset| {
|
||||||
|
|
|
@ -1,30 +1,3 @@
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
extern crate languageserver_types;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate crossbeam_channel;
|
|
||||||
extern crate rayon;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate cargo_metadata;
|
|
||||||
extern crate drop_bomb;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate failure_derive;
|
|
||||||
extern crate im;
|
|
||||||
extern crate relative_path;
|
|
||||||
extern crate rustc_hash;
|
|
||||||
extern crate url_serde;
|
|
||||||
extern crate walkdir;
|
|
||||||
|
|
||||||
extern crate gen_lsp_server;
|
|
||||||
extern crate ra_analysis;
|
|
||||||
extern crate ra_editor;
|
|
||||||
extern crate ra_syntax;
|
|
||||||
|
|
||||||
mod caps;
|
mod caps;
|
||||||
mod conv;
|
mod conv;
|
||||||
mod main_loop;
|
mod main_loop;
|
||||||
|
|
|
@ -1,15 +1,5 @@
|
||||||
#[macro_use]
|
use serde_derive::Deserialize;
|
||||||
extern crate log;
|
use serde::Deserialize as _D;
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate flexi_logger;
|
|
||||||
extern crate gen_lsp_server;
|
|
||||||
extern crate ra_lsp_server;
|
|
||||||
|
|
||||||
use serde::Deserialize;
|
|
||||||
use flexi_logger::{Duplicate, Logger};
|
use flexi_logger::{Duplicate, Logger};
|
||||||
use gen_lsp_server::{run_server, stdio_transport};
|
use gen_lsp_server::{run_server, stdio_transport};
|
||||||
use ra_lsp_server::Result;
|
use ra_lsp_server::Result;
|
||||||
|
@ -21,15 +11,15 @@ fn main() -> Result<()> {
|
||||||
.log_to_file()
|
.log_to_file()
|
||||||
.directory("log")
|
.directory("log")
|
||||||
.start()?;
|
.start()?;
|
||||||
info!("lifecycle: server started");
|
log::info!("lifecycle: server started");
|
||||||
match ::std::panic::catch_unwind(main_inner) {
|
match ::std::panic::catch_unwind(main_inner) {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
info!("lifecycle: terminating process with {:?}", res);
|
log::info!("lifecycle: terminating process with {:?}", res);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
error!("server panicked");
|
log::error!("server panicked");
|
||||||
bail!("server panicked")
|
failure::bail!("server panicked")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,8 +50,8 @@ fn main_inner() -> Result<()> {
|
||||||
ra_lsp_server::main_loop(false, root, publish_decorations, r, s)
|
ra_lsp_server::main_loop(false, root, publish_decorations, r, s)
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
info!("shutting down IO...");
|
log::info!("shutting down IO...");
|
||||||
threads.join()?;
|
threads.join()?;
|
||||||
info!("... IO is down");
|
log::info!("... IO is down");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod subscriptions;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
use crossbeam_channel::{unbounded, select, Receiver, Sender};
|
||||||
use gen_lsp_server::{
|
use gen_lsp_server::{
|
||||||
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
|
handle_shutdown, ErrorCode, RawMessage, RawNotification, RawRequest, RawResponse,
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,8 @@ use ra_analysis::{Canceled, FileId, LibraryData};
|
||||||
use rayon::{self, ThreadPool};
|
use rayon::{self, ThreadPool};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
use failure::{format_err, bail};
|
||||||
|
use failure_derive::Fail;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
main_loop::subscriptions::Subscriptions,
|
main_loop::subscriptions::Subscriptions,
|
||||||
|
@ -54,14 +56,14 @@ pub fn main_loop(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let pool = rayon::ThreadPoolBuilder::new()
|
let pool = rayon::ThreadPoolBuilder::new()
|
||||||
.num_threads(4)
|
.num_threads(4)
|
||||||
.panic_handler(|_| error!("thread panicked :("))
|
.panic_handler(|_| log::error!("thread panicked :("))
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (task_sender, task_receiver) = unbounded::<Task>();
|
let (task_sender, task_receiver) = unbounded::<Task>();
|
||||||
let (fs_worker, fs_watcher) = vfs::roots_loader();
|
let (fs_worker, fs_watcher) = vfs::roots_loader();
|
||||||
let (ws_worker, ws_watcher) = workspace_loader();
|
let (ws_worker, ws_watcher) = workspace_loader();
|
||||||
|
|
||||||
info!("server initialized, serving requests");
|
log::info!("server initialized, serving requests");
|
||||||
let mut state = ServerWorldState::default();
|
let mut state = ServerWorldState::default();
|
||||||
|
|
||||||
let mut pending_requests = FxHashSet::default();
|
let mut pending_requests = FxHashSet::default();
|
||||||
|
@ -82,12 +84,12 @@ pub fn main_loop(
|
||||||
&mut subs,
|
&mut subs,
|
||||||
);
|
);
|
||||||
|
|
||||||
info!("waiting for tasks to finish...");
|
log::info!("waiting for tasks to finish...");
|
||||||
task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
|
task_receiver.for_each(|task| on_task(task, msg_sender, &mut pending_requests));
|
||||||
info!("...tasks have finished");
|
log::info!("...tasks have finished");
|
||||||
info!("joining threadpool...");
|
log::info!("joining threadpool...");
|
||||||
drop(pool);
|
drop(pool);
|
||||||
info!("...threadpool has finished");
|
log::info!("...threadpool has finished");
|
||||||
|
|
||||||
let fs_res = fs_watcher.stop();
|
let fs_res = fs_watcher.stop();
|
||||||
let ws_res = ws_watcher.stop();
|
let ws_res = ws_watcher.stop();
|
||||||
|
@ -126,7 +128,7 @@ fn main_loop_inner(
|
||||||
Ws(Result<CargoWorkspace>),
|
Ws(Result<CargoWorkspace>),
|
||||||
Lib(LibraryData),
|
Lib(LibraryData),
|
||||||
}
|
}
|
||||||
trace!("selecting");
|
log::trace!("selecting");
|
||||||
let event = select! {
|
let event = select! {
|
||||||
recv(msg_receiver, msg) => match msg {
|
recv(msg_receiver, msg) => match msg {
|
||||||
Some(msg) => Event::Msg(msg),
|
Some(msg) => Event::Msg(msg),
|
||||||
|
@ -147,7 +149,7 @@ fn main_loop_inner(
|
||||||
match event {
|
match event {
|
||||||
Event::Task(task) => on_task(task, msg_sender, pending_requests),
|
Event::Task(task) => on_task(task, msg_sender, pending_requests),
|
||||||
Event::Fs(root, events) => {
|
Event::Fs(root, events) => {
|
||||||
info!("fs change, {}, {} events", root.display(), events.len());
|
log::info!("fs change, {}, {} events", root.display(), events.len());
|
||||||
if root == ws_root {
|
if root == ws_root {
|
||||||
state.apply_fs_changes(events);
|
state.apply_fs_changes(events);
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,9 +157,9 @@ fn main_loop_inner(
|
||||||
let sender = libdata_sender.clone();
|
let sender = libdata_sender.clone();
|
||||||
pool.spawn(move || {
|
pool.spawn(move || {
|
||||||
let start = ::std::time::Instant::now();
|
let start = ::std::time::Instant::now();
|
||||||
info!("indexing {} ... ", root.display());
|
log::info!("indexing {} ... ", root.display());
|
||||||
let data = LibraryData::prepare(files, resolver);
|
let data = LibraryData::prepare(files, resolver);
|
||||||
info!("indexed {:?} {}", start.elapsed(), root.display());
|
log::info!("indexed {:?} {}", start.elapsed(), root.display());
|
||||||
sender.send(data);
|
sender.send(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -195,14 +197,14 @@ fn main_loop_inner(
|
||||||
.map(|(_idx, root)| root);
|
.map(|(_idx, root)| root);
|
||||||
|
|
||||||
for root in unique {
|
for root in unique {
|
||||||
debug!("sending root, {}", root.display());
|
log::debug!("sending root, {}", root.display());
|
||||||
fs_worker.send(root.to_owned());
|
fs_worker.send(root.to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.set_workspaces(workspaces);
|
state.set_workspaces(workspaces);
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
Err(e) => warn!("loading workspace failed: {}", e),
|
Err(e) => log::warn!("loading workspace failed: {}", e),
|
||||||
},
|
},
|
||||||
Event::Lib(lib) => {
|
Event::Lib(lib) => {
|
||||||
feedback(internal_mode, "library loaded", msg_sender);
|
feedback(internal_mode, "library loaded", msg_sender);
|
||||||
|
@ -217,7 +219,7 @@ fn main_loop_inner(
|
||||||
match on_request(state, pending_requests, pool, &task_sender, req)? {
|
match on_request(state, pending_requests, pool, &task_sender, req)? {
|
||||||
None => (),
|
None => (),
|
||||||
Some(req) => {
|
Some(req) => {
|
||||||
error!("unknown request: {:?}", req);
|
log::error!("unknown request: {:?}", req);
|
||||||
let resp = RawResponse::err(
|
let resp = RawResponse::err(
|
||||||
req.id,
|
req.id,
|
||||||
ErrorCode::MethodNotFound as i32,
|
ErrorCode::MethodNotFound as i32,
|
||||||
|
@ -231,7 +233,7 @@ fn main_loop_inner(
|
||||||
on_notification(msg_sender, state, pending_requests, subs, not)?;
|
on_notification(msg_sender, state, pending_requests, subs, not)?;
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
RawMessage::Response(resp) => error!("unexpected response: {:?}", resp),
|
RawMessage::Response(resp) => log::error!("unexpected response: {:?}", resp),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -370,7 +372,7 @@ fn on_notification(
|
||||||
}
|
}
|
||||||
Err(not) => not,
|
Err(not) => not,
|
||||||
};
|
};
|
||||||
error!("unhandled notification: {:?}", not);
|
log::error!("unhandled notification: {:?}", not);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +457,7 @@ fn update_file_notifications_on_threadpool(
|
||||||
match handlers::publish_diagnostics(&world, file_id) {
|
match handlers::publish_diagnostics(&world, file_id) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if !is_canceled(&e) {
|
if !is_canceled(&e) {
|
||||||
error!("failed to compute diagnostics: {:?}", e);
|
log::error!("failed to compute diagnostics: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
|
@ -467,7 +469,7 @@ fn update_file_notifications_on_threadpool(
|
||||||
match handlers::publish_decorations(&world, file_id) {
|
match handlers::publish_decorations(&world, file_id) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if !is_canceled(&e) {
|
if !is_canceled(&e) {
|
||||||
error!("failed to compute decorations: {:?}", e);
|
log::error!("failed to compute decorations: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(params) => {
|
Ok(params) => {
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use serde_derive::Serialize;
|
||||||
use cargo_metadata::{metadata_run, CargoOpt};
|
use cargo_metadata::{metadata_run, CargoOpt};
|
||||||
use ra_syntax::SmolStr;
|
use ra_syntax::SmolStr;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
use failure::{format_err, bail};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
thread_watcher::{ThreadWatcher, Worker},
|
|
||||||
Result,
|
Result,
|
||||||
|
thread_watcher::{ThreadWatcher, Worker},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use serde_derive::{Serialize, Deserialize};
|
||||||
use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
|
use languageserver_types::{Location, Position, Range, TextDocumentIdentifier, Url};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use url_serde;
|
use url_serde;
|
||||||
|
|
|
@ -9,6 +9,7 @@ use ra_analysis::{
|
||||||
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
|
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FileResolver, LibraryData,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
use failure::{bail, format_err};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
path_map::{PathMap, Root},
|
path_map::{PathMap, Root},
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::thread;
|
||||||
|
|
||||||
use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
|
use crossbeam_channel::{bounded, unbounded, Receiver, Sender};
|
||||||
use drop_bomb::DropBomb;
|
use drop_bomb::DropBomb;
|
||||||
|
use failure::format_err;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ impl ThreadWatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(mut self) -> Result<()> {
|
pub fn stop(mut self) -> Result<()> {
|
||||||
info!("waiting for {} to finish ...", self.name);
|
log::info!("waiting for {} to finish ...", self.name);
|
||||||
let name = self.name;
|
let name = self.name;
|
||||||
self.bomb.defuse();
|
self.bomb.defuse();
|
||||||
let res = self
|
let res = self
|
||||||
|
@ -56,8 +57,8 @@ impl ThreadWatcher {
|
||||||
.join()
|
.join()
|
||||||
.map_err(|_| format_err!("ThreadWatcher {} died", name));
|
.map_err(|_| format_err!("ThreadWatcher {} died", name));
|
||||||
match &res {
|
match &res {
|
||||||
Ok(()) => info!("... {} terminated with ok", name),
|
Ok(()) => log::info!("... {} terminated with ok", name),
|
||||||
Err(_) => error!("... {} terminated with err", name),
|
Err(_) => log::error!("... {} terminated with err", name),
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,9 @@ pub fn roots_loader() -> (Worker<PathBuf, (PathBuf, Vec<FileEvent>)>, ThreadWatc
|
||||||
|input_receiver, output_sender| {
|
|input_receiver, output_sender| {
|
||||||
input_receiver
|
input_receiver
|
||||||
.map(|path| {
|
.map(|path| {
|
||||||
debug!("loading {} ...", path.as_path().display());
|
log::debug!("loading {} ...", path.as_path().display());
|
||||||
let events = load_root(path.as_path());
|
let events = load_root(path.as_path());
|
||||||
debug!("... loaded {}", path.as_path().display());
|
log::debug!("... loaded {}", path.as_path().display());
|
||||||
(path, events)
|
(path, events)
|
||||||
})
|
})
|
||||||
.for_each(|it| output_sender.send(it))
|
.for_each(|it| output_sender.send(it))
|
||||||
|
@ -41,7 +41,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
|
||||||
let entry = match entry {
|
let entry = match entry {
|
||||||
Ok(entry) => entry,
|
Ok(entry) => entry,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("watcher error: {}", e);
|
log::warn!("watcher error: {}", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ fn load_root(path: &Path) -> Vec<FileEvent> {
|
||||||
let text = match fs::read_to_string(path) {
|
let text = match fs::read_to_string(path) {
|
||||||
Ok(text) => text,
|
Ok(text) => text,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
warn!("watcher error: {}", e);
|
log::warn!("watcher error: {}", e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
#[macro_use]
|
|
||||||
extern crate crossbeam_channel;
|
|
||||||
extern crate flexi_logger;
|
|
||||||
extern crate gen_lsp_server;
|
|
||||||
extern crate languageserver_types;
|
|
||||||
extern crate ra_lsp_server;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
extern crate tempdir;
|
|
||||||
|
|
||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
use ra_lsp_server::req::{Runnables, RunnablesParams};
|
use ra_lsp_server::req::{Runnables, RunnablesParams};
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam_channel::{after, Receiver};
|
use crossbeam_channel::{after, select, Receiver};
|
||||||
use flexi_logger::Logger;
|
use flexi_logger::Logger;
|
||||||
use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
|
use gen_lsp_server::{RawMessage, RawNotification, RawRequest};
|
||||||
use languageserver_types::{
|
use languageserver_types::{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
edition = "2015"
|
edition = "2018"
|
||||||
name = "ra_syntax"
|
name = "ra_syntax"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
|
||||||
|
|
|
@ -20,17 +20,6 @@
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
//#![warn(unreachable_pub)] // rust-lang/rust#47816
|
//#![warn(unreachable_pub)] // rust-lang/rust#47816
|
||||||
|
|
||||||
extern crate arrayvec;
|
|
||||||
extern crate drop_bomb;
|
|
||||||
extern crate itertools;
|
|
||||||
extern crate parking_lot;
|
|
||||||
extern crate rowan;
|
|
||||||
extern crate unicode_xid;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate test_utils;
|
|
||||||
|
|
||||||
pub mod algo;
|
pub mod algo;
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
|
@ -48,11 +37,11 @@ pub mod utils;
|
||||||
mod validation;
|
mod validation;
|
||||||
mod yellow;
|
mod yellow;
|
||||||
|
|
||||||
|
pub use rowan::{SmolStr, TextRange, TextUnit};
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
ast::AstNode,
|
ast::AstNode,
|
||||||
lexer::{tokenize, Token},
|
lexer::{tokenize, Token},
|
||||||
reparsing::AtomEdit,
|
reparsing::AtomEdit,
|
||||||
rowan::{SmolStr, TextRange, TextUnit},
|
|
||||||
syntax_kinds::SyntaxKind,
|
syntax_kinds::SyntaxKind,
|
||||||
yellow::{
|
yellow::{
|
||||||
Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location,
|
Direction, OwnedRoot, RefRoot, SyntaxError, SyntaxNode, SyntaxNodeRef, TreeRoot, WalkEvent, Location,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
use drop_bomb::DropBomb;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
drop_bomb::DropBomb,
|
|
||||||
parser_impl::ParserImpl,
|
parser_impl::ParserImpl,
|
||||||
token_set::TokenSet,
|
token_set::TokenSet,
|
||||||
SyntaxKind::{self, ERROR},
|
SyntaxKind::{self, ERROR},
|
||||||
|
|
|
@ -179,10 +179,10 @@ fn merge_errors(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use test_utils::{extract_range, assert_eq_text};
|
||||||
super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, SourceFileNode},
|
|
||||||
reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef,
|
use crate::{SourceFileNode, text_utils::replace_range, utils::dump_tree };
|
||||||
};
|
use super::*;
|
||||||
|
|
||||||
fn do_check<F>(before: &str, replace_with: &str, reparser: F)
|
fn do_check<F>(before: &str, replace_with: &str, reparser: F)
|
||||||
where
|
where
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
extern crate difference;
|
use std::fmt;
|
||||||
extern crate itertools;
|
|
||||||
extern crate text_unit;
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::fmt;
|
|
||||||
use text_unit::{TextRange, TextUnit};
|
use text_unit::{TextRange, TextUnit};
|
||||||
|
|
||||||
pub use self::difference::Changeset as __Changeset;
|
pub use difference::Changeset as __Changeset;
|
||||||
|
|
||||||
pub const CURSOR_MARKER: &str = "<|>";
|
pub const CURSOR_MARKER: &str = "<|>";
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
extern crate failure;
|
|
||||||
extern crate itertools;
|
|
||||||
extern crate teraron;
|
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
|
@ -12,7 +8,7 @@ use itertools::Itertools;
|
||||||
|
|
||||||
pub use teraron::{Mode, Overwrite, Verify};
|
pub use teraron::{Mode, Overwrite, Verify};
|
||||||
|
|
||||||
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
pub type Result<T> = std::result::Result<T, failure::Error>;
|
||||||
|
|
||||||
pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
|
pub const GRAMMAR: &str = "crates/ra_syntax/src/grammar.ron";
|
||||||
pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera";
|
pub const SYNTAX_KINDS: &str = "crates/ra_syntax/src/syntax_kinds/generated.rs.tera";
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
extern crate clap;
|
|
||||||
extern crate failure;
|
|
||||||
extern crate teraron;
|
|
||||||
extern crate tools;
|
|
||||||
extern crate walkdir;
|
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
|
||||||
use failure::bail;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs,
|
fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use clap::{App, Arg, SubCommand};
|
||||||
|
use failure::bail;
|
||||||
|
|
||||||
use tools::{collect_tests, generate, run, run_rustfmt, Mode, Overwrite, Result, Test, Verify};
|
use tools::{collect_tests, generate, run, run_rustfmt, Mode, Overwrite, Result, Test, Verify};
|
||||||
|
|
||||||
const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
|
const GRAMMAR_DIR: &str = "./crates/ra_syntax/src/grammar";
|
||||||
|
|
Loading…
Reference in a new issue