mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-11 20:58:54 +00:00
modernize even more
This commit is contained in:
parent
f6e8b376d1
commit
28ddecf6c9
12 changed files with 29 additions and 70 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| {
|
||||||
|
|
|
@ -20,10 +20,6 @@
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
//#![warn(unreachable_pub)] // rust-lang/rust#47816
|
//#![warn(unreachable_pub)] // rust-lang/rust#47816
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate test_utils;
|
|
||||||
|
|
||||||
pub mod algo;
|
pub mod algo;
|
||||||
pub mod ast;
|
pub mod ast;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue