Skip to content

Commit

Permalink
test: added snapshot test for document symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Jan 4, 2021
1 parent 5de87e5 commit 3a0bdaa
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 42 deletions.
7 changes: 6 additions & 1 deletion crates/mun_language_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log = "0.4"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
async-std = "1.6"
async-std = { version = "1.8.0", features=["attributes"] }
futures = "0.3"
anyhow = "1.0"
thiserror = "1.0"
Expand All @@ -32,3 +32,8 @@ num_cpus = "1.13.0"
mun_target = { version = "=0.2.0", path = "../mun_target" }
mun_syntax = { version = "=0.2.0", path = "../mun_syntax" }
mun_diagnostics = { version = "=0.1.0", path = "../mun_diagnostics" }

[dev-dependencies]
mun_test = { path = "../mun_test"}
tempdir = "0.3.7"
insta = "0.16"
3 changes: 1 addition & 2 deletions crates/mun_language_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ mod main_loop;
pub mod protocol;
mod symbol_kind;

pub use config::Config;
pub use config::{Config, FilesWatcher};
pub use main_loop::main_loop;

use crate::config::FilesWatcher;
use serde::de::DeserializeOwned;
use serde::Serialize;
use std::fmt;
Expand Down
39 changes: 23 additions & 16 deletions crates/mun_language_server/src/main_loop.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use crate::analysis::{Analysis, AnalysisSnapshot, Cancelable};
use crate::cancelation::is_canceled;
use crate::change::AnalysisChange;
use crate::config::{Config, FilesWatcher};
use crate::conversion::{convert_range, convert_symbol_kind, url_from_path_with_drive_lowercasing};
use crate::protocol::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
use crate::{LspError, Result};
use crate::{
analysis::{Analysis, AnalysisSnapshot, Cancelable},
cancelation::is_canceled,
change::AnalysisChange,
config::{Config, FilesWatcher},
conversion::{convert_range, convert_symbol_kind, url_from_path_with_drive_lowercasing},
protocol::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response},
LspError, Result,
};
use anyhow::anyhow;
use async_std::sync::RwLock;
use futures::channel::mpsc::{unbounded, Sender, UnboundedReceiver, UnboundedSender};
use futures::{SinkExt, StreamExt};
use lsp_types::notification::PublishDiagnostics;
use lsp_types::{DocumentSymbol, PublishDiagnosticsParams, Url};
use futures::{
channel::mpsc::{unbounded, Sender, UnboundedReceiver, UnboundedSender},
SinkExt, StreamExt,
};
use lsp_types::{notification::PublishDiagnostics, DocumentSymbol, PublishDiagnosticsParams, Url};
use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile};
use serde::{de::DeserializeOwned, Serialize};
use std::collections::HashSet;
use std::ops::Deref;
use std::sync::Arc;
use std::{collections::HashSet, ops::Deref, sync::Arc};

/// A `Task` is something that is send from async tasks to the entry point for processing. This
/// enables synchronizing resources like the connection with the client.
Expand Down Expand Up @@ -507,7 +508,7 @@ async fn handle_diagnostics(
lsp_diagnostics
};

sender
match sender
.send(Task::Notify(build_notification::<PublishDiagnostics>(
PublishDiagnosticsParams {
uri,
Expand All @@ -516,7 +517,13 @@ async fn handle_diagnostics(
},
)))
.await
.unwrap();
{
Ok(_) => {}
Err(err) if err.is_disconnected() => return Ok(()),
Err(err) => {
panic!("unable to send diagnostic notification: {}", err);
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/mun_language_server/src/protocol/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl Connection {
/// Creates a pair of connected connections. This enables in-process communication, especially
/// useful for testing.
pub fn memory() -> (Connection, Connection) {
let (s1, r1) = mpsc::channel(0);
let (s2, r2) = mpsc::channel(0);
let (s1, r1) = mpsc::channel(1);
let (s2, r2) = mpsc::channel(1);
(
Connection {
sender: s1,
Expand Down
33 changes: 33 additions & 0 deletions crates/mun_language_server/tests/document_symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
mod support;

#[test]
fn test_document_symbols() {
let mut server = support::Project::with_fixture(
r#"
//- /Mun.toml
[package]
name = "foo"
version = "0.0.0"
//- /src/mod.mun
fn main() -> i32 {}
struct Foo {}
type Bar = Foo;
"#,
)
.server();

let response = async_std::task::block_on(
server.send_request::<lsp_types::request::DocumentSymbolRequest>(
lsp_types::DocumentSymbolParams {
text_document: server.doc_id("src/mod.mun"),
work_done_progress_params: Default::default(),
partial_result_params: Default::default(),
},
),
);

insta::assert_debug_snapshot!(response);
}
6 changes: 3 additions & 3 deletions crates/mun_language_server/tests/initialization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod support;

#[test]
fn test_server() {
let _server = support::Server::new();
#[async_std::test]
async fn test_server() {
let _server = support::Project::with_fixture("").server();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
source: crates/mun_language_server/tests/document_symbols.rs
expression: response
---
Some(
Nested(
[
DocumentSymbol {
name: "main",
detail: Some(
"fn() -> i32",
),
kind: Function,
deprecated: None,
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 0,
character: 19,
},
},
selection_range: Range {
start: Position {
line: 0,
character: 3,
},
end: Position {
line: 0,
character: 7,
},
},
children: None,
},
DocumentSymbol {
name: "Foo",
detail: None,
kind: Struct,
deprecated: None,
range: Range {
start: Position {
line: 2,
character: 0,
},
end: Position {
line: 2,
character: 13,
},
},
selection_range: Range {
start: Position {
line: 2,
character: 7,
},
end: Position {
line: 2,
character: 10,
},
},
children: None,
},
DocumentSymbol {
name: "Bar",
detail: Some(
"Foo",
),
kind: TypeParameter,
deprecated: None,
range: Range {
start: Position {
line: 4,
character: 0,
},
end: Position {
line: 4,
character: 15,
},
},
selection_range: Range {
start: Position {
line: 4,
character: 5,
},
end: Position {
line: 4,
character: 8,
},
},
children: None,
},
],
),
)
Loading

0 comments on commit 3a0bdaa

Please sign in to comment.