summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/lsp/documents.rs5
-rw-r--r--cli/lsp/language_server.rs833
2 files changed, 658 insertions, 180 deletions
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index ef37396a2..bdf80c5a8 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -124,10 +124,7 @@ impl DocumentCache {
}
pub fn close(&mut self, specifier: &ModuleSpecifier) {
- if let Some(mut doc) = self.docs.get_mut(specifier) {
- doc.version = None;
- doc.dependencies = None;
- }
+ self.docs.remove(specifier);
}
pub fn contains_key(&self, specifier: &ModuleSpecifier) -> bool {
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs
index 275a0873d..ce16f8705 100644
--- a/cli/lsp/language_server.rs
+++ b/cli/lsp/language_server.rs
@@ -2398,6 +2398,7 @@ mod tests {
use std::fs;
use std::task::Poll;
use std::time::Instant;
+ use tempfile::TempDir;
use tower_test::mock::Spawn;
enum LspResponse<V>
@@ -2412,7 +2413,13 @@ mod tests {
RequestFixture(u64, String),
}
- type LspTestHarnessRequest = (&'static str, LspResponse<fn(Value)>);
+ enum LspFixture {
+ None,
+ Path(&'static str),
+ Value(Value),
+ }
+
+ type LspTestHarnessRequest = (LspFixture, LspResponse<fn(Value)>);
struct LspTestHarness {
requests: Vec<LspTestHarnessRequest>,
@@ -2427,19 +2434,25 @@ mod tests {
}
async fn run(&mut self) {
- for (req_path_str, expected) in self.requests.iter() {
+ for (value_or_str, expected) in self.requests.iter() {
assert_eq!(self.service.poll_ready(), Poll::Ready(Ok(())));
let fixtures_path = test_util::root_path().join("cli/tests/lsp");
assert!(fixtures_path.is_dir());
let response: Result<Option<jsonrpc::Outgoing>, ExitedError> =
- if req_path_str.is_empty() {
- Ok(None)
- } else {
- let req_path = fixtures_path.join(req_path_str);
- let req_str = fs::read_to_string(req_path).unwrap();
- let req: jsonrpc::Incoming =
- serde_json::from_str(&req_str).unwrap();
- self.service.call(req).await
+ match value_or_str {
+ LspFixture::None => Ok(None),
+ LspFixture::Path(req_path_str) => {
+ let req_path = fixtures_path.join(req_path_str);
+ let req_str = fs::read_to_string(req_path).unwrap();
+ let req: jsonrpc::Incoming =
+ serde_json::from_str(&req_str).unwrap();
+ self.service.call(req).await
+ }
+ LspFixture::Value(value) => {
+ let req: jsonrpc::Incoming =
+ serde_json::from_value(value.clone()).unwrap();
+ self.service.call(req).await
+ }
};
match response {
Ok(result) => match expected {
@@ -2487,13 +2500,22 @@ mod tests {
#[tokio::test]
async fn test_startup_shutdown() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "shutdown_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2501,11 +2523,20 @@ mod tests {
#[tokio::test]
async fn test_hover() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification.json", LspResponse::None),
(
- "hover_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request.json"),
LspResponse::Request(
2,
json!({
@@ -2530,10 +2561,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2541,16 +2575,28 @@ mod tests {
#[tokio::test]
async fn test_hover_asset() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_asset.json", LspResponse::None),
- ("definition_request_asset.json", LspResponse::RequestAny),
(
- "virtual_text_document_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_asset.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("definition_request_asset.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("virtual_text_document_request.json"),
LspResponse::RequestAny,
),
(
- "hover_request_asset.json",
+ LspFixture::Path("hover_request_asset.json"),
LspResponse::Request(
5,
json!({
@@ -2575,10 +2621,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2586,15 +2635,30 @@ mod tests {
#[tokio::test]
async fn test_hover_disabled() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request_disabled.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification.json", LspResponse::None),
- ("hover_request.json", LspResponse::Request(2, json!(null))),
(
- "shutdown_request.json",
+ LspFixture::Path("initialize_request_disabled.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request.json"),
+ LspResponse::Request(2, json!(null)),
+ ),
+ (
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2602,11 +2666,20 @@ mod tests {
#[tokio::test]
async fn test_hover_unstable_disabled() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_unstable.json", LspResponse::None),
(
- "hover_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_unstable.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request.json"),
LspResponse::Request(
2,
json!({
@@ -2630,10 +2703,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2641,11 +2717,20 @@ mod tests {
#[tokio::test]
async fn test_hover_unstable_enabled() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request_unstable.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_unstable.json", LspResponse::None),
(
- "hover_request.json",
+ LspFixture::Path("initialize_request_unstable.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_unstable.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request.json"),
LspResponse::Request(
2,
json!({
@@ -2670,10 +2755,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2681,12 +2769,24 @@ mod tests {
#[tokio::test]
async fn test_hover_change_mbc() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_mbc.json", LspResponse::None),
- ("did_change_notification_mbc.json", LspResponse::None),
(
- "hover_request_mbc.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_mbc.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_change_notification_mbc.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request_mbc.json"),
LspResponse::Request(
2,
json!({
@@ -2711,10 +2811,190 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
+ LspResponse::Request(3, json!(null)),
+ ),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
+ ]);
+ harness.run().await;
+ }
+
+ #[derive(Deserialize)]
+ struct HoverResponse {
+ pub result: Option<Hover>,
+ }
+
+ #[tokio::test]
+ async fn test_hover_closed_document() {
+ let temp_dir = TempDir::new()
+ .expect("could not create temp dir")
+ .into_path();
+ let a_path = temp_dir.join("a.ts");
+ fs::write(a_path, r#"export const a = "a";"#)
+ .expect("could not write file");
+ let b_path = temp_dir.join("b.ts");
+ fs::write(&b_path, r#"export * from "./a.ts";"#)
+ .expect("could not write file");
+ let b_specifier =
+ Url::from_file_path(b_path).expect("could not convert path");
+ let c_path = temp_dir.join("c.ts");
+ fs::write(&c_path, "import { a } from \"./b.ts\";\nconsole.log(a);\n")
+ .expect("could not write file");
+ let c_specifier =
+ Url::from_file_path(c_path).expect("could not convert path");
+
+ let mut harness = LspTestHarness::new(vec![
+ (
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Value(json!({
+ "jsonrpc": "2.0",
+ "method": "textDocument/didOpen",
+ "params": {
+ "textDocument": {
+ "uri": b_specifier,
+ "languageId": "typescript",
+ "version": 1,
+ "text": r#"export * from "./a.ts";"#
+ }
+ }
+ })),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Value(json!({
+ "jsonrpc": "2.0",
+ "method": "textDocument/didOpen",
+ "params": {
+ "textDocument": {
+ "uri": c_specifier,
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import { a } from \"./b.ts\";\nconsole.log(a);\n",
+ }
+ }
+ })),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Value(json!({
+ "jsonrpc": "2.0",
+ "id": 2,
+ "method": "textDocument/hover",
+ "params": {
+ "textDocument": {
+ "uri": c_specifier,
+ },
+ "position": {
+ "line": 0,
+ "character": 10
+ }
+ }
+ })),
+ LspResponse::RequestAssert(|value| {
+ let resp: HoverResponse = serde_json::from_value(value).unwrap();
+ if let Some(hover) = resp.result {
+ assert_eq!(
+ hover,
+ Hover {
+ contents: HoverContents::Array(vec![
+ MarkedString::LanguageString(LanguageString {
+ language: "typescript".to_string(),
+ value: "(alias) const a: \"a\"\nimport a".to_string()
+ }),
+ MarkedString::String("".to_string()),
+ ]),
+ range: Some(Range {
+ start: Position {
+ line: 0,
+ character: 9,
+ },
+ end: Position {
+ line: 0,
+ character: 10,
+ }
+ }),
+ }
+ );
+ } else {
+ panic!("no response");
+ }
+ }),
+ ),
+ (
+ LspFixture::Value(json!({
+ "jsonrpc": "2.0",
+ "method": "textDocument/didClose",
+ "params": {
+ "textDocument": {
+ "uri": b_specifier,
+ }
+ }
+ })),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Value(json!({
+ "jsonrpc": "2.0",
+ "id": 4,
+ "method": "textDocument/hover",
+ "params": {
+ "textDocument": {
+ "uri": c_specifier,
+ },
+ "position": {
+ "line": 0,
+ "character": 10
+ }
+ }
+ })),
+ LspResponse::RequestAssert(|value| {
+ let resp: HoverResponse = serde_json::from_value(value).unwrap();
+ if let Some(hover) = resp.result {
+ assert_eq!(
+ hover,
+ Hover {
+ contents: HoverContents::Array(vec![
+ MarkedString::LanguageString(LanguageString {
+ language: "typescript".to_string(),
+ value: "(alias) const a: \"a\"\nimport a".to_string()
+ }),
+ MarkedString::String("".to_string()),
+ ]),
+ range: Some(Range {
+ start: Position {
+ line: 0,
+ character: 9,
+ },
+ end: Position {
+ line: 0,
+ character: 10,
+ }
+ }),
+ }
+ );
+ } else {
+ panic!("no response");
+ }
+ }),
+ ),
+ (
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2722,14 +3002,20 @@ mod tests {
#[tokio::test]
async fn test_call_hierarchy() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "prepare_call_hierarchy_did_open_notification.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("prepare_call_hierarchy_did_open_notification.json"),
LspResponse::None,
),
(
- "prepare_call_hierarchy_request.json",
+ LspFixture::Path("prepare_call_hierarchy_request.json"),
LspResponse::Request(
2,
json!([
@@ -2763,7 +3049,7 @@ mod tests {
),
),
(
- "incoming_calls_request.json",
+ LspFixture::Path("incoming_calls_request.json"),
LspResponse::Request(
4,
json!([
@@ -2811,7 +3097,7 @@ mod tests {
),
),
(
- "outgoing_calls_request.json",
+ LspFixture::Path("outgoing_calls_request.json"),
LspResponse::Request(
5,
json!([
@@ -2859,10 +3145,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2870,11 +3159,20 @@ mod tests {
#[tokio::test]
async fn test_format_mbc() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_mbc_fmt.json", LspResponse::None),
(
- "formatting_request_mbc_fmt.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_mbc_fmt.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("formatting_request_mbc_fmt.json"),
LspResponse::Request(
2,
json!([
@@ -2934,10 +3232,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -2945,20 +3246,50 @@ mod tests {
#[tokio::test]
async fn test_large_doc_change() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_large.json", LspResponse::None),
- ("did_change_notification_large.json", LspResponse::None),
- ("did_change_notification_large_02.json", LspResponse::None),
- ("did_change_notification_large_03.json", LspResponse::None),
- ("hover_request_large_01.json", LspResponse::RequestAny),
- ("hover_request_large_02.json", LspResponse::RequestAny),
- ("hover_request_large_03.json", LspResponse::RequestAny),
- (
- "shutdown_request.json",
+ (
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_large.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_change_notification_large.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_change_notification_large_02.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_change_notification_large_03.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request_large_01.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("hover_request_large_02.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("hover_request_large_03.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
let time = Instant::now();
harness.run().await;
@@ -2971,14 +3302,20 @@ mod tests {
#[tokio::test]
async fn test_folding_range() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "folding_range_did_open_notification.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("folding_range_did_open_notification.json"),
LspResponse::None,
),
(
- "folding_range_request.json",
+ LspFixture::Path("folding_range_request.json"),
LspResponse::Request(
2,
json!([
@@ -3008,10 +3345,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3019,11 +3359,20 @@ mod tests {
#[tokio::test]
async fn test_rename() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("rename_did_open_notification.json", LspResponse::None),
(
- "rename_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("rename_did_open_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("rename_request.json"),
LspResponse::Request(
2,
json!({
@@ -3062,10 +3411,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3073,14 +3425,20 @@ mod tests {
#[tokio::test]
async fn test_selection_range() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "selection_range_did_open_notification.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("selection_range_did_open_notification.json"),
LspResponse::None,
),
(
- "selection_range_request.json",
+ LspFixture::Path("selection_range_request.json"),
LspResponse::Request(
2,
json!([{
@@ -3170,10 +3528,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3181,14 +3542,20 @@ mod tests {
#[tokio::test]
async fn test_code_lens_request() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "did_open_notification_cl_references.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
LspResponse::None,
),
(
- "code_lens_request.json",
+ LspFixture::Path("did_open_notification_cl_references.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("code_lens_request.json"),
LspResponse::Request(
2,
json!([
@@ -3228,7 +3595,7 @@ mod tests {
),
),
(
- "code_lens_resolve_request.json",
+ LspFixture::Path("code_lens_resolve_request.json"),
LspResponse::Request(
4,
json!({
@@ -3272,10 +3639,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3283,14 +3653,20 @@ mod tests {
#[tokio::test]
async fn test_signature_help() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "signature_help_did_open_notification.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
LspResponse::None,
),
(
- "signature_help_request_01.json",
+ LspFixture::Path("signature_help_did_open_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("signature_help_request_01.json"),
LspResponse::Request(
1,
json!({
@@ -3316,11 +3692,11 @@ mod tests {
),
),
(
- "signature_help_did_change_notification.json",
+ LspFixture::Path("signature_help_did_change_notification.json"),
LspResponse::None,
),
(
- "signature_help_request_02.json",
+ LspFixture::Path("signature_help_request_02.json"),
LspResponse::Request(
2,
json!({
@@ -3346,10 +3722,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3357,11 +3736,20 @@ mod tests {
#[tokio::test]
async fn test_code_lens_impl_request() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_cl_impl.json", LspResponse::None),
(
- "code_lens_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_cl_impl.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("code_lens_request.json"),
LspResponse::Request(
2,
json!([
@@ -3417,7 +3805,7 @@ mod tests {
),
),
(
- "code_lens_resolve_request_impl.json",
+ LspFixture::Path("code_lens_resolve_request_impl.json"),
LspResponse::Request(
4,
json!({
@@ -3461,10 +3849,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3482,16 +3873,28 @@ mod tests {
#[tokio::test]
async fn test_code_lens_non_doc_nav_tree() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_asset.json", LspResponse::None),
- ("references_request_asset.json", LspResponse::RequestAny),
(
- "virtual_text_document_request.json",
+ LspFixture::Path("initialize_request.json"),
LspResponse::RequestAny,
),
(
- "code_lens_request_asset.json",
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_asset.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("references_request_asset.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("virtual_text_document_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("code_lens_request_asset.json"),
LspResponse::RequestAssert(|value| {
let resp: CodeLensResponse = serde_json::from_value(value).unwrap();
let lenses = resp.result.unwrap();
@@ -3499,7 +3902,7 @@ mod tests {
}),
),
(
- "code_lens_resolve_request_asset.json",
+ LspFixture::Path("code_lens_resolve_request_asset.json"),
LspResponse::RequestAssert(|value| {
let resp: CodeLensResolveResponse =
serde_json::from_value(value).unwrap();
@@ -3507,10 +3910,13 @@ mod tests {
}),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3518,26 +3924,38 @@ mod tests {
#[tokio::test]
async fn test_code_actions() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_code_action.json", LspResponse::None),
- ("", LspResponse::Delay(500)),
(
- "code_action_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_code_action.json"),
+ LspResponse::None,
+ ),
+ (LspFixture::None, LspResponse::Delay(500)),
+ (
+ LspFixture::Path("code_action_request.json"),
LspResponse::RequestFixture(2, "code_action_response.json".to_string()),
),
(
- "code_action_resolve_request.json",
+ LspFixture::Path("code_action_resolve_request.json"),
LspResponse::RequestFixture(
4,
"code_action_resolve_request_response.json".to_string(),
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3545,21 +3963,33 @@ mod tests {
#[tokio::test]
async fn test_code_actions_deno_cache() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_cache.json", LspResponse::None),
(
- "code_action_request_cache.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_cache.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("code_action_request_cache.json"),
LspResponse::RequestFixture(
2,
"code_action_response_cache.json".to_string(),
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3572,11 +4002,20 @@ mod tests {
#[tokio::test]
async fn test_completions() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification_completions.json", LspResponse::None),
(
- "completion_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_completions.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("completion_request.json"),
LspResponse::RequestAssert(|value| {
let response: CompletionResult =
serde_json::from_value(value).unwrap();
@@ -3591,7 +4030,7 @@ mod tests {
}),
),
(
- "completion_resolve_request.json",
+ LspFixture::Path("completion_resolve_request.json"),
LspResponse::Request(
4,
json!({
@@ -3608,10 +4047,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3619,14 +4061,20 @@ mod tests {
#[tokio::test]
async fn test_completions_optional() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "did_open_notification_completion_optional.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification_completion_optional.json"),
LspResponse::None,
),
(
- "completion_request_optional.json",
+ LspFixture::Path("completion_request_optional.json"),
LspResponse::Request(
2,
json!({
@@ -3652,7 +4100,7 @@ mod tests {
),
),
(
- "completion_resolve_request_optional.json",
+ LspFixture::Path("completion_resolve_request_optional.json"),
LspResponse::Request(
4,
json!({
@@ -3670,10 +4118,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3682,14 +4133,20 @@ mod tests {
async fn test_completions_registry() {
let _g = test_util::http_server();
let mut harness = LspTestHarness::new(vec![
- ("initialize_request_registry.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "did_open_notification_completion_registry.json",
+ LspFixture::Path("initialize_request_registry.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
LspResponse::None,
),
(
- "completion_request_registry.json",
+ LspFixture::Path("did_open_notification_completion_registry.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("completion_request_registry.json"),
LspResponse::RequestAssert(|value| {
let response: CompletionResult =
serde_json::from_value(value).unwrap();
@@ -3702,7 +4159,7 @@ mod tests {
}),
),
(
- "completion_resolve_request_registry.json",
+ LspFixture::Path("completion_resolve_request_registry.json"),
LspResponse::Request(
4,
json!({
@@ -3728,10 +4185,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3740,14 +4200,20 @@ mod tests {
async fn test_completion_registry_empty_specifier() {
let _g = test_util::http_server();
let mut harness = LspTestHarness::new(vec![
- ("initialize_request_registry.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
(
- "did_open_notification_completion_registry_02.json",
+ LspFixture::Path("initialize_request_registry.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
LspResponse::None,
),
(
- "completion_request_registry_02.json",
+ LspFixture::Path("did_open_notification_completion_registry_02.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("completion_request_registry_02.json"),
LspResponse::Request(
2,
json!({
@@ -3791,10 +4257,13 @@ mod tests {
),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}
@@ -3811,11 +4280,20 @@ mod tests {
#[tokio::test]
async fn test_deno_performance_request() {
let mut harness = LspTestHarness::new(vec![
- ("initialize_request.json", LspResponse::RequestAny),
- ("initialized_notification.json", LspResponse::None),
- ("did_open_notification.json", LspResponse::None),
(
- "hover_request.json",
+ LspFixture::Path("initialize_request.json"),
+ LspResponse::RequestAny,
+ ),
+ (
+ LspFixture::Path("initialized_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("did_open_notification.json"),
+ LspResponse::None,
+ ),
+ (
+ LspFixture::Path("hover_request.json"),
LspResponse::Request(
2,
json!({
@@ -3840,7 +4318,7 @@ mod tests {
),
),
(
- "performance_request.json",
+ LspFixture::Path("performance_request.json"),
LspResponse::RequestAssert(|value| {
let resp: PerformanceResponse =
serde_json::from_value(value).unwrap();
@@ -3851,10 +4329,13 @@ mod tests {
}),
),
(
- "shutdown_request.json",
+ LspFixture::Path("shutdown_request.json"),
LspResponse::Request(3, json!(null)),
),
- ("exit_notification.json", LspResponse::None),
+ (
+ LspFixture::Path("exit_notification.json"),
+ LspResponse::None,
+ ),
]);
harness.run().await;
}