diff --git a/kclvm/tools/src/LSP/src/state.rs b/kclvm/tools/src/LSP/src/state.rs index 36fa72db1..a3f51afcc 100644 --- a/kclvm/tools/src/LSP/src/state.rs +++ b/kclvm/tools/src/LSP/src/state.rs @@ -13,7 +13,6 @@ use lsp_types::{ }; use parking_lot::RwLock; use ra_ap_vfs::{FileId, Vfs}; -use ra_ap_vfs_notify::NotifyHandle; use std::collections::HashMap; use std::{sync::Arc, time::Instant}; @@ -103,7 +102,7 @@ impl LanguageServerState { let loader = { let (sender, _receiver) = unbounded::(); let handle: ra_ap_vfs_notify::NotifyHandle = - ra_ap_vfs::loader::Handle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); + ra_ap_vfs::loader::Handle::spawn(Box::new(move |msg| sender.send(msg).unwrap())); let handle = Box::new(handle) as Box; Handle { handle, _receiver } }; @@ -136,7 +135,7 @@ impl LanguageServerState { analysis: Analysis::default(), opened_files: IndexSet::new(), word_index_map, - loader + loader, } } diff --git a/kclvm/tools/src/LSP/src/tests.rs b/kclvm/tools/src/LSP/src/tests.rs index c2979ac11..e4ff5e745 100644 --- a/kclvm/tools/src/LSP/src/tests.rs +++ b/kclvm/tools/src/LSP/src/tests.rs @@ -582,6 +582,51 @@ fn notification_test() { } } +#[test] +fn close_file_test() { + let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let mut path = root.clone(); + + path.push("src/test_data/diagnostics.k"); + + let path = path.to_str().unwrap(); + let src = std::fs::read_to_string(path.clone()).unwrap(); + let server = Project {}.server(InitializeParams::default()); + + // Mock open file + server.notification::( + lsp_types::DidOpenTextDocumentParams { + text_document: TextDocumentItem { + uri: Url::from_file_path(path).unwrap(), + language_id: "KCL".to_string(), + version: 0, + text: src.clone(), + }, + }, + ); + + // Mock close file + server.notification::( + lsp_types::DidCloseTextDocumentParams { + text_document: TextDocumentIdentifier { + uri: Url::from_file_path(path).unwrap(), + }, + }, + ); + + // Mock reopen file + server.notification::( + lsp_types::DidOpenTextDocumentParams { + text_document: TextDocumentItem { + uri: Url::from_file_path(path).unwrap(), + language_id: "KCL".to_string(), + version: 0, + text: src, + }, + }, + ); +} + #[test] fn goto_def_test() { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));