mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
store messages in tests
This commit is contained in:
parent
d752455637
commit
7fad13de73
2 changed files with 17 additions and 7 deletions
|
@ -9,7 +9,7 @@ use languageserver_types::{
|
||||||
|
|
||||||
use Result;
|
use Result;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum RawMessage {
|
pub enum RawMessage {
|
||||||
Request(RawRequest),
|
Request(RawRequest),
|
||||||
|
@ -17,14 +17,14 @@ pub enum RawMessage {
|
||||||
Response(RawResponse),
|
Response(RawResponse),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct RawRequest {
|
pub struct RawRequest {
|
||||||
pub id: u64,
|
pub id: u64,
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub params: Value,
|
pub params: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct RawResponse {
|
pub struct RawResponse {
|
||||||
// JSON RPC allows this to be null if it was impossible
|
// JSON RPC allows this to be null if it was impossible
|
||||||
// to decode the request's id. Ignore this special case
|
// to decode the request's id. Ignore this special case
|
||||||
|
@ -36,7 +36,7 @@ pub struct RawResponse {
|
||||||
pub error: Option<RawResponseError>,
|
pub error: Option<RawResponseError>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct RawResponseError {
|
pub struct RawResponseError {
|
||||||
pub code: i32,
|
pub code: i32,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
|
@ -44,6 +44,7 @@ pub struct RawResponseError {
|
||||||
pub data: Option<Value>,
|
pub data: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub enum ErrorCode {
|
pub enum ErrorCode {
|
||||||
ParseError = -32700,
|
ParseError = -32700,
|
||||||
|
@ -58,7 +59,7 @@ pub enum ErrorCode {
|
||||||
RequestCancelled = -32800,
|
RequestCancelled = -32800,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct RawNotification {
|
pub struct RawNotification {
|
||||||
pub method: String,
|
pub method: String,
|
||||||
pub params: Value,
|
pub params: Value,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
thread,
|
thread,
|
||||||
cell::Cell,
|
cell::{Cell, RefCell},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ pub fn project(fixture: &str) -> Server {
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
req_id: Cell<u64>,
|
req_id: Cell<u64>,
|
||||||
|
messages: RefCell<Vec<RawMessage>>,
|
||||||
dir: TempDir,
|
dir: TempDir,
|
||||||
sender: Option<Sender<RawMessage>>,
|
sender: Option<Sender<RawMessage>>,
|
||||||
receiver: Receiver<RawMessage>,
|
receiver: Receiver<RawMessage>,
|
||||||
|
@ -71,6 +72,7 @@ impl Server {
|
||||||
let res = Server {
|
let res = Server {
|
||||||
req_id: Cell::new(1),
|
req_id: Cell::new(1),
|
||||||
dir,
|
dir,
|
||||||
|
messages: Default::default(),
|
||||||
sender: Some(client_sender),
|
sender: Some(client_sender),
|
||||||
receiver: client_receiver,
|
receiver: client_receiver,
|
||||||
server: Some(server),
|
server: Some(server),
|
||||||
|
@ -129,7 +131,7 @@ impl Server {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.send(RawMessage::Request(r));
|
.send(RawMessage::Request(r));
|
||||||
|
|
||||||
while let Some(msg) = self.receiver.recv() {
|
while let Some(msg) = self.recv() {
|
||||||
match msg {
|
match msg {
|
||||||
RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
|
RawMessage::Request(req) => panic!("unexpected request: {:?}", req),
|
||||||
RawMessage::Notification(_) => (),
|
RawMessage::Notification(_) => (),
|
||||||
|
@ -144,6 +146,13 @@ impl Server {
|
||||||
}
|
}
|
||||||
panic!("no response");
|
panic!("no response");
|
||||||
}
|
}
|
||||||
|
fn recv(&self) -> Option<RawMessage> {
|
||||||
|
self.receiver.recv()
|
||||||
|
.map(|msg| {
|
||||||
|
self.messages.borrow_mut().push(msg.clone());
|
||||||
|
msg
|
||||||
|
})
|
||||||
|
}
|
||||||
fn send_notification(&self, not: RawNotification) {
|
fn send_notification(&self, not: RawNotification) {
|
||||||
|
|
||||||
self.sender.as_ref()
|
self.sender.as_ref()
|
||||||
|
|
Loading…
Reference in a new issue