From 09b79463d71f3b144a0cfd878108a012c87464ca Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sat, 6 Feb 2021 13:39:01 +0100 Subject: feat(lsp): add asset cache regression test When we migrated away from all the locks, there was a regression that was not caught immediately. The tsc::get_asset() would attempt to modify the snapshot, but the problem was that the snapshot was a .clone() of the inner language server's assets, which meant that modifications to that where lost. When we then attempted to do a hover on those assets, the inner language servers assets didn't have the retrieved asset, and therefore would throw an error. --- cli/lsp/language_server.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'cli/lsp') diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 2050cf2b7..e22934dc3 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1934,6 +1934,51 @@ mod tests { harness.run().await; } + #[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), + ("hover_request_asset_01.json", LspResponse::RequestAny), + ( + "virtual_text_document_request.json", + LspResponse::RequestAny, + ), + ( + "hover_request_asset_02.json", + LspResponse::Request( + 4, + json!({ + "contents": [ + { + "language": "typescript", + "value": "interface Date", + }, + "Enables basic storage and retrieval of dates and times." + ], + "range": { + "start": { + "line": 109, + "character": 10, + }, + "end": { + "line": 109, + "character": 14, + } + } + }), + ), + ), + ( + "shutdown_request.json", + LspResponse::Request(3, json!(null)), + ), + ("exit_notification.json", LspResponse::None), + ]); + harness.run().await; + } + #[tokio::test] async fn test_hover_disabled() { let mut harness = LspTestHarness::new(vec![ -- cgit v1.2.3