-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam
committed
May 26, 2023
1 parent
774e54d
commit 7e5d118
Showing
6 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,3 +161,7 @@ impl AnalyzerHost { | |
Ok(()) | ||
} | ||
} | ||
|
||
// Unit test fixtures. | ||
#[cfg(test)] | ||
mod tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod unit_tests; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::sync::Arc; | ||
|
||
use analyzer_abstractions::lsp_types::{ | ||
Position, TextDocumentIdentifier, TextDocumentPositionParams, Url, WorkDoneProgressParams, | ||
}; | ||
use serde_json::Value; | ||
|
||
use crate::{ | ||
fs::LspEnumerableFileSystem, | ||
fsm::LspProtocolMachine, | ||
json_rpc::message::{Message, Notification, Request}, | ||
lsp::{request::RequestManager, state::LspServerState}, | ||
}; | ||
|
||
#[test] | ||
fn test_lsp_states() { | ||
let rm = RequestManager::new(async_channel::unbounded::<Message>()); | ||
let mut lsp = | ||
LspProtocolMachine::new(None, rm.clone(), Arc::new(Box::new(LspEnumerableFileSystem::new(rm.clone())))); | ||
assert_eq!(lsp.current_state(), LspServerState::ActiveUninitialized); | ||
assert_eq!(lsp.is_active(), true); | ||
|
||
let mut params = serde_json::json!(analyzer_abstractions::lsp_types::InitializeParams { ..Default::default() }); | ||
let mut message = Message::Request(Request { id: 0.into(), method: String::from("initialize"), params: params }); | ||
let mut output = async_io::block_on(lsp.process_message(Arc::new(message))); | ||
assert!(output.is_ok()); | ||
assert_eq!(lsp.current_state(), LspServerState::Initializing); | ||
assert_eq!(lsp.is_active(), true); | ||
|
||
let url = Url::parse("https://example.net").unwrap(); | ||
let hover_params = analyzer_abstractions::lsp_types::HoverParams { | ||
text_document_position_params: TextDocumentPositionParams { | ||
text_document: TextDocumentIdentifier { uri: url }, | ||
position: Position { line: 0, character: 0 }, | ||
}, | ||
work_done_progress_params: WorkDoneProgressParams { work_done_token: None }, | ||
}; | ||
params = serde_json::json!(hover_params); | ||
message = Message::Request(Request { id: 0.into(), method: String::from("textDocument/hover"), params: params }); | ||
output = async_io::block_on(lsp.process_message(Arc::new(message))); | ||
assert!(output.is_ok()); | ||
assert_eq!(lsp.current_state(), LspServerState::Initializing); | ||
assert_eq!(lsp.is_active(), true); | ||
|
||
params = serde_json::json!(analyzer_abstractions::lsp_types::InitializedParams {}); | ||
message = Message::Notification(Notification { method: String::from("initialized"), params: params }); | ||
output = async_io::block_on(lsp.process_message(Arc::new(message))); | ||
assert!(output.is_ok()); | ||
assert_eq!(lsp.current_state(), LspServerState::ActiveInitialized); | ||
assert_eq!(lsp.is_active(), true); | ||
|
||
params = serde_json::json!(hover_params); | ||
message = Message::Notification(Notification { method: String::from("textDocument/hover"), params: params }); | ||
output = async_io::block_on(lsp.process_message(Arc::new(message))); | ||
assert!(output.is_err()); | ||
assert_eq!(lsp.current_state(), LspServerState::ActiveInitialized); | ||
assert_eq!(lsp.is_active(), true); | ||
|
||
message = Message::Request(Request { id: 0.into(), method: String::from("shutdown"), params: Value::Null }); | ||
output = async_io::block_on(lsp.process_message(Arc::new(message))); | ||
assert!(output.is_ok()); | ||
assert_eq!(lsp.current_state(), LspServerState::ShuttingDown); | ||
assert_eq!(lsp.is_active(), true); | ||
|
||
message = Message::Notification(Notification { method: String::from("exit"), params: Value::Null }); | ||
output = async_io::block_on(lsp.process_message(Arc::new(message))); | ||
assert!(output.is_ok()); | ||
assert_eq!(lsp.current_state(), LspServerState::Stopped); | ||
assert_eq!(lsp.is_active(), false); | ||
} |