diff --git a/kclvm/tools/src/LSP/src/find_refs.rs b/kclvm/tools/src/LSP/src/find_refs.rs index 37ed99ea6..817c80539 100644 --- a/kclvm/tools/src/LSP/src/find_refs.rs +++ b/kclvm/tools/src/LSP/src/find_refs.rs @@ -1,385 +1,113 @@ -use std::sync::Arc; +use std::collections::HashSet; -use crate::from_lsp::{file_path_from_url, kcl_pos}; -use crate::goto_def::{find_def, goto_def}; use crate::to_lsp::lsp_location; -use crate::util::{compile_with_params, Params}; - -use crate::state::{KCLEntryCache, KCLVfs, KCLWordIndexMap}; -use anyhow::Result; -use kclvm_driver::toolchain; use kclvm_error::Position as KCLPos; use kclvm_sema::core::global_state::GlobalState; use lsp_types::Location; -use parking_lot::lock_api::RwLock; - -const FIND_REFS_LIMIT: usize = 20; -pub(crate) fn find_refs Result<(), anyhow::Error>>( - kcl_pos: &KCLPos, - include_declaration: bool, - word_index_map: KCLWordIndexMap, - vfs: Option, - logger: F, - gs: &GlobalState, - entry_cache: Option, -) -> Result, String> { - let def = find_def(kcl_pos, gs, true); - match def { - Some(def_ref) => match gs.get_symbols().get_symbol(def_ref) { - Some(obj) => { - let (start, end) = obj.get_range(); - // find all the refs of the def - if let Some(def_loc) = lsp_location(start.filename.clone(), &start, &end) { - Ok(find_refs_from_def( - vfs, - word_index_map, - def_loc, - obj.get_name(), - include_declaration, - Some(FIND_REFS_LIMIT), - logger, - entry_cache, - )) - } else { - Err(format!("Invalid file path: {0}", start.filename)) - } - } - None => Err(String::from( - "Found more than one definitions, reference not supported", - )), - }, - None => Err(String::from( - "Definition item not found, result in no reference", - )), - } -} - -pub(crate) fn find_refs_from_def Result<(), anyhow::Error>>( - vfs: Option, - word_index_map: KCLWordIndexMap, - def_loc: Location, - name: String, - include_declaration: bool, - limit: Option, - logger: F, - entry_cache: Option, -) -> Vec { - let mut ref_locations = vec![]; - for word_index in (*word_index_map.write()).values_mut() { - if let Some(mut locs) = word_index.get(name.as_str()).cloned() { - if let Some(limit) = limit { - if locs.len() >= limit { - let _ = logger(format!( - "Found more than {0} matched symbols, only the first {0} will be processed", - limit - )); - locs = locs[0..limit].to_vec(); - } - } - let matched_locs: Vec = locs - .into_iter() - .filter(|ref_loc| { - // from location to real def - // return if the real def location matches the def_loc - match file_path_from_url(&ref_loc.uri) { - Ok(file_path) => { - match compile_with_params(Params { - file: file_path.clone(), - module_cache: None, - scope_cache: None, - vfs: vfs.clone(), - gs_cache: None, - entry_cache: entry_cache.clone(), - tool: Arc::new(RwLock::new(toolchain::default())), - }) - .1 - { - Ok((_, gs)) => { - let ref_pos = kcl_pos(&file_path, ref_loc.range.start); - if *ref_loc == def_loc && !include_declaration { - return false; - } - // find def from the ref_pos - if let Some(real_def) = goto_def(&ref_pos, &gs) { - match real_def { - lsp_types::GotoDefinitionResponse::Scalar( - real_def_loc, - ) => real_def_loc == def_loc, - _ => false, - } - } else { - false - } - } - Err(err) => { - let _ = - logger(format!("{file_path} compilation failed: {}", err)); - false - } - } - } - Err(err) => { - let _ = logger(format!("compilation failed: {}", err)); - false +pub(crate) fn find_refs(kcl_pos: &KCLPos, gs: &GlobalState) -> Option> { + match gs.look_up_exact_symbol(kcl_pos) { + Some(symbol_ref) => match gs.get_symbols().get_symbol(symbol_ref) { + Some(symbol) => match symbol.get_definition() { + Some(def_ref) => { + if def_ref.get_id() == symbol_ref.get_id() { + if let Some(def) = gs.get_symbols().get_symbol(def_ref) { + let refs = def.get_references(); + let refs_locs: HashSet<(KCLPos, KCLPos)> = refs + .iter() + .filter_map(|symbol| { + gs.get_symbols() + .get_symbol(*symbol) + .map(|sym| sym.get_range()) + }) + .collect(); + return Some( + refs_locs + .iter() + .filter_map(|(start, end)| { + lsp_location(start.filename.clone(), &start, &end) + .map(|loc| loc) + }) + .collect(), + ); } } - }) - .collect(); - ref_locations.extend(matched_locs); - } - } - ref_locations + } + None => {} + }, + None => {} + }, + None => {} + }; + None } #[cfg(test)] mod tests { - use super::find_refs_from_def; - use crate::word_index::build_word_index; - use lsp_types::{Location, Position, Range, Url}; - use parking_lot::RwLock; - use std::collections::HashMap; - use std::path::PathBuf; - use std::sync::Arc; - - fn logger(msg: String) -> Result<(), anyhow::Error> { - println!("{}", msg); - anyhow::Ok(()) - } + use crate::find_refs::find_refs; + use crate::from_lsp::file_path_from_url; + use lsp_types::Location; + use std::path::{Path, PathBuf}; - fn check_locations_match(expect: Vec, actual: Vec) { - assert_eq!(expect, actual) - } + use crate::tests::compile_test_file; + use kclvm_error::Position as KCLPos; - fn setup_word_index_map(root: &str) -> HashMap>> { - HashMap::from([( - Url::from_file_path(root).unwrap(), - build_word_index(root, true).unwrap(), - )]) - } + #[macro_export] + macro_rules! find_ref_test_snapshot { + ($name:ident, $file:expr, $line:expr, $column: expr) => { + #[test] + fn $name() { + let (file, _program, _, gs) = compile_test_file($file); - #[test] - fn find_refs_from_variable_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut path = root.clone(); - path.push("src/test_data/find_refs_test/main.k"); - let path = path.to_str().unwrap(); - - match lsp_types::Url::from_file_path(path) { - Ok(url) => { - let def_loc = Location { - uri: url.clone(), - range: Range { - start: Position::new(0, 0), - end: Position::new(0, 1), - }, + let pos = KCLPos { + filename: file.clone(), + line: $line, + column: Some($column), }; - let expect = vec![ - Location { - uri: url.clone(), - range: Range { - start: Position::new(0, 0), - end: Position::new(0, 1), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(1, 4), - end: Position::new(1, 5), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(2, 4), - end: Position::new(2, 5), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(12, 14), - end: Position::new(12, 15), - }, - }, - ]; - check_locations_match( - expect, - find_refs_from_def( - None, - Arc::new(RwLock::new(setup_word_index_map(path))), - def_loc, - "a".to_string(), - true, - Some(20), - logger, - None, - ), - ); + let res = find_refs(&pos, &gs); + insta::assert_snapshot!(format!("{}", { fmt_resp(&res) })); } - Err(_) => unreachable!("file not found"), - } + }; } - #[test] - fn find_refs_include_declaration_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut path = root.clone(); - path.push("src/test_data/find_refs_test/main.k"); - let path = path.to_str().unwrap(); - match lsp_types::Url::from_file_path(path) { - Ok(url) => { - let def_loc = Location { - uri: url.clone(), - range: Range { - start: Position::new(0, 0), - end: Position::new(0, 1), - }, - }; - let expect = vec![ - Location { - uri: url.clone(), - range: Range { - start: Position::new(1, 4), - end: Position::new(1, 5), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(2, 4), - end: Position::new(2, 5), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(12, 14), - end: Position::new(12, 15), - }, - }, - ]; - check_locations_match( - expect, - find_refs_from_def( - None, - Arc::new(RwLock::new(setup_word_index_map(path))), - def_loc, - "a".to_string(), - false, - Some(20), - logger, - None, - ), - ); + fn fmt_resp(resp: &Option>) -> String { + let root_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + match resp { + Some(resp) => { + let mut res = String::new(); + for loc in resp { + let url = file_path_from_url(&loc.uri).unwrap(); + let got_path = Path::new(&url); + let relative_path = got_path.strip_prefix(root_path.clone()).unwrap(); + res.push_str(&format!( + "path: {:?}, range: {:?}\n", + relative_path, loc.range + )); + } + res } - Err(_) => unreachable!("file not found"), + None => "None".to_string(), } } - #[test] - fn find_refs_from_schema_name_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut path = root.clone(); - path.push("src/test_data/find_refs_test/main.k"); - let path = path.to_str().unwrap(); - match lsp_types::Url::from_file_path(path) { - Ok(url) => { - let def_loc = Location { - uri: url.clone(), - range: Range { - start: Position::new(4, 7), - end: Position::new(4, 11), - }, - }; - let expect = vec![ - Location { - uri: url.clone(), - range: Range { - start: Position::new(4, 7), - end: Position::new(4, 11), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(8, 7), - end: Position::new(8, 11), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(11, 7), - end: Position::new(11, 11), - }, - }, - ]; - check_locations_match( - expect, - find_refs_from_def( - None, - Arc::new(RwLock::new(setup_word_index_map(path))), - def_loc, - "Name".to_string(), - true, - Some(20), - logger, - None, - ), - ); - } - Err(_) => unreachable!("file not found"), - } - } + find_ref_test_snapshot!( + find_refs_variable_test, + "src/test_data/find_refs_test/main.k", + 1, + 1 + ); - #[test] - fn find_refs_from_schema_attr_test() { - let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let mut path = root.clone(); - path.push("src/test_data/find_refs_test/main.k"); - let path = path.to_str().unwrap(); - match lsp_types::Url::from_file_path(path) { - Ok(url) => { - let def_loc = Location { - uri: url.clone(), - range: Range { - start: Position::new(5, 4), - end: Position::new(5, 8), - }, - }; - let expect = vec![ - Location { - uri: url.clone(), - range: Range { - start: Position::new(5, 4), - end: Position::new(5, 8), - }, - }, - Location { - uri: url.clone(), - range: Range { - start: Position::new(12, 8), - end: Position::new(12, 12), - }, - }, - ]; - check_locations_match( - expect, - find_refs_from_def( - None, - Arc::new(RwLock::new(setup_word_index_map(path))), - def_loc, - "name".to_string(), - true, - Some(20), - logger, - None, - ), - ); - } - Err(_) => unreachable!("file not found"), - } - } + find_ref_test_snapshot!( + find_refs_schema_name_test, + "src/test_data/find_refs_test/main.k", + 5, + 8 + ); + + find_ref_test_snapshot!( + find_refs_schema_attr_test, + "src/test_data/find_refs_test/main.k", + 6, + 7 + ); } diff --git a/kclvm/tools/src/LSP/src/notification.rs b/kclvm/tools/src/LSP/src/notification.rs index d7be1b5a5..a01adfbcc 100644 --- a/kclvm/tools/src/LSP/src/notification.rs +++ b/kclvm/tools/src/LSP/src/notification.rs @@ -3,14 +3,10 @@ use lsp_types::notification::{ Cancel, DidChangeTextDocument, DidChangeWatchedFiles, DidCloseTextDocument, DidOpenTextDocument, DidSaveTextDocument, }; -use std::path::Path; use crate::{ - dispatcher::NotificationDispatcher, - from_lsp, - state::LanguageServerState, + dispatcher::NotificationDispatcher, from_lsp, state::LanguageServerState, util::apply_document_changes, - word_index::{build_word_index_with_content, word_index_add, word_index_subtract}, }; impl LanguageServerState { @@ -94,26 +90,11 @@ impl LanguageServerState { .ok_or(anyhow::anyhow!("Already checked that the file_id exists!"))?; let mut text = String::from_utf8(vfs.file_contents(file_id).to_vec())?; - let old_text = text.clone(); apply_document_changes(&mut text, content_changes); vfs.set_file_contents(path.into(), Some(text.clone().into_bytes())); self.opened_files .write() .insert(file_id, text_document.version); - // Update word index - let old_word_index = build_word_index_with_content(&old_text, &text_document.uri, true); - let new_word_index = build_word_index_with_content(&text, &text_document.uri, true); - let binding = from_lsp::file_path_from_url(&text_document.uri)?; - let file_path = Path::new(&binding); - let word_index_map = &mut *self.word_index_map.write(); - for (key, value) in word_index_map { - let workspace_folder_path = Path::new(key.path()); - if file_path.starts_with(workspace_folder_path) { - word_index_subtract(value, old_word_index.clone()); - word_index_add(value, new_word_index.clone()); - } - } - Ok(()) } diff --git a/kclvm/tools/src/LSP/src/request.rs b/kclvm/tools/src/LSP/src/request.rs index d6d6f03ea..88edd30e3 100644 --- a/kclvm/tools/src/LSP/src/request.rs +++ b/kclvm/tools/src/LSP/src/request.rs @@ -1,11 +1,9 @@ use anyhow::anyhow; use crossbeam_channel::Sender; -use kclvm_sema::info::is_valid_kcl_name; use lsp_server::RequestId; use lsp_types::{Location, SemanticTokensResult, TextEdit}; use ra_ap_vfs::{AbsPathBuf, VfsPath}; -use std::collections::HashMap; use std::sync::Arc; use std::time::Instant; @@ -264,7 +262,6 @@ pub(crate) fn handle_reference( params: lsp_types::ReferenceParams, sender: Sender, ) -> anyhow::Result>> { - let include_declaration = params.context.include_declaration; let file = file_path_from_url(¶ms.text_document_position.text_document.uri)?; let path = from_lsp::abs_path(¶ms.text_document_position.text_document.uri)?; @@ -277,23 +274,8 @@ pub(crate) fn handle_reference( Err(_) => return Ok(None), }; let pos = kcl_pos(&file, params.text_document_position.position); - let log = |msg: String| log_message(msg, &sender); - let entry_cache = snapshot.entry_cache.clone(); - match find_refs( - &pos, - include_declaration, - snapshot.word_index_map.clone(), - Some(snapshot.vfs.clone()), - log, - &db.gs, - Some(entry_cache), - ) { - core::result::Result::Ok(locations) => Ok(Some(locations)), - Err(msg) => { - log(format!("Find references failed: {msg}"))?; - Ok(None) - } - } + let res = find_refs(&pos, &db.gs); + Ok(res) } /// Called when a `textDocument/completion` request was received. @@ -403,63 +385,64 @@ pub(crate) fn handle_rename( params: lsp_types::RenameParams, sender: Sender, ) -> anyhow::Result> { - // 1. check the new name validity - let new_name = params.new_name; - if !is_valid_kcl_name(new_name.as_str()) { - return Err(anyhow!("Can not rename to: {new_name}, invalid name")); - } - - // 2. find all the references of the symbol - let file = file_path_from_url(¶ms.text_document_position.text_document.uri)?; - let path = from_lsp::abs_path(¶ms.text_document_position.text_document.uri)?; - if !snapshot.verify_request_path(&path.clone().into(), &sender) { - return Ok(None); - } - let db = match snapshot.get_db(&path.clone().into()) { - Ok(db) => db, - Err(_) => return Ok(None), - }; - let kcl_pos = kcl_pos(&file, params.text_document_position.position); - let log = |msg: String| log_message(msg, &sender); - let references = find_refs( - &kcl_pos, - true, - snapshot.word_index_map.clone(), - Some(snapshot.vfs.clone()), - log, - &db.gs, - Some(snapshot.entry_cache), - ); - match references { - Result::Ok(locations) => { - if locations.is_empty() { - let _ = log("Symbol not found".to_string()); - anyhow::Ok(None) - } else { - // 3. return the workspaceEdit to rename all the references with the new name - let mut workspace_edit = lsp_types::WorkspaceEdit::default(); - - let changes = locations.into_iter().fold( - HashMap::new(), - |mut map: HashMap>, location| { - let uri = location.uri; - map.entry(uri.clone()).or_default().push(TextEdit { - range: location.range, - new_text: new_name.clone(), - }); - map - }, - ); - workspace_edit.changes = Some(changes); - anyhow::Ok(Some(workspace_edit)) - } - } - Err(msg) => { - let err_msg = format!("Can not rename symbol: {msg}"); - log(err_msg.clone())?; - Err(anyhow!(err_msg)) - } - } + Ok(None) + // // 1. check the new name validity + // let new_name = params.new_name; + // if !is_valid_kcl_name(new_name.as_str()) { + // return Err(anyhow!("Can not rename to: {new_name}, invalid name")); + // } + + // // 2. find all the references of the symbol + // let file = file_path_from_url(¶ms.text_document_position.text_document.uri)?; + // let path = from_lsp::abs_path(¶ms.text_document_position.text_document.uri)?; + // if !snapshot.verify_request_path(&path.clone().into(), &sender) { + // return Ok(None); + // } + // let db = match snapshot.get_db(&path.clone().into()) { + // Ok(db) => db, + // Err(_) => return Ok(None), + // }; + // let kcl_pos = kcl_pos(&file, params.text_document_position.position); + // let log = |msg: String| log_message(msg, &sender); + // let references = find_refs( + // &kcl_pos, + // true, + // snapshot.word_index_map.clone(), + // Some(snapshot.vfs.clone()), + // log, + // &db.gs, + // Some(snapshot.entry_cache), + // ); + // match references { + // Result::Ok(locations) => { + // if locations.is_empty() { + // let _ = log("Symbol not found".to_string()); + // anyhow::Ok(None) + // } else { + // // 3. return the workspaceEdit to rename all the references with the new name + // let mut workspace_edit = lsp_types::WorkspaceEdit::default(); + + // let changes = locations.into_iter().fold( + // HashMap::new(), + // |mut map: HashMap>, location| { + // let uri = location.uri; + // map.entry(uri.clone()).or_default().push(TextEdit { + // range: location.range, + // new_text: new_name.clone(), + // }); + // map + // }, + // ); + // workspace_edit.changes = Some(changes); + // anyhow::Ok(Some(workspace_edit)) + // } + // } + // Err(msg) => { + // let err_msg = format!("Can not rename symbol: {msg}"); + // log(err_msg.clone())?; + // Err(anyhow!(err_msg)) + // } + // } } pub(crate) fn handle_inlay_hint( diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_from_variable_test.snap.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_from_variable_test.snap.new new file mode 100644 index 000000000..e15971972 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_from_variable_test.snap.new @@ -0,0 +1,8 @@ +--- +source: tools/src/LSP/src/find_refs.rs +assertion_line: 87 +expression: "format!(\"{}\", { fmt_resp(& res) })" +--- +path: "src/test_data/find_refs_test/main.k", range: Range { start: Position { line: 12, character: 14 }, end: Position { line: 12, character: 15 } } +path: "src/test_data/find_refs_test/main.k", range: Range { start: Position { line: 2, character: 4 }, end: Position { line: 2, character: 5 } } +path: "src/test_data/find_refs_test/main.k", range: Range { start: Position { line: 1, character: 4 }, end: Position { line: 1, character: 5 } } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_schema_attr_test.snap.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_schema_attr_test.snap.new new file mode 100644 index 000000000..ff80f4ba0 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_schema_attr_test.snap.new @@ -0,0 +1,6 @@ +--- +source: tools/src/LSP/src/find_refs.rs +assertion_line: 107 +expression: "format!(\"{}\", { fmt_resp(& res) })" +--- +path: "src/test_data/find_refs_test/main.k", range: Range { start: Position { line: 12, character: 8 }, end: Position { line: 12, character: 12 } } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_schema_name_test.snap.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_schema_name_test.snap.new new file mode 100644 index 000000000..835c2b347 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__find_refs__tests__find_refs_schema_name_test.snap.new @@ -0,0 +1,7 @@ +--- +source: tools/src/LSP/src/find_refs.rs +assertion_line: 100 +expression: "format!(\"{}\", { fmt_resp(& res) })" +--- +path: "src/test_data/find_refs_test/main.k", range: Range { start: Position { line: 11, character: 7 }, end: Position { line: 11, character: 11 } } +path: "src/test_data/find_refs_test/main.k", range: Range { start: Position { line: 8, character: 7 }, end: Position { line: 8, character: 11 } } diff --git a/kclvm/tools/src/LSP/src/state.rs b/kclvm/tools/src/LSP/src/state.rs index afa45c28e..ef011a027 100644 --- a/kclvm/tools/src/LSP/src/state.rs +++ b/kclvm/tools/src/LSP/src/state.rs @@ -1,9 +1,6 @@ use crate::analysis::{Analysis, AnalysisDatabase, DocumentVersion}; -use crate::from_lsp::file_path_from_url; use crate::to_lsp::{kcl_diag_to_lsp_diags, url}; use crate::util::{compile_with_params, get_file_name, to_json, Params}; -use crate::word_index::build_word_index; -use anyhow::Result; use crossbeam_channel::{select, unbounded, Receiver, Sender}; use kclvm_driver::toolchain::{self, Toolchain}; use kclvm_driver::CompileUnitOptions; @@ -12,10 +9,9 @@ use kclvm_sema::core::global_state::GlobalState; use kclvm_sema::resolver::scope::KCLScopeCache; use lsp_server::RequestId; use lsp_server::{ReqQueue, Request, Response}; -use lsp_types::Url; use lsp_types::{ notification::{Notification, PublishDiagnostics}, - Diagnostic, InitializeParams, Location, PublishDiagnosticsParams, + Diagnostic, InitializeParams, PublishDiagnosticsParams, }; use parking_lot::RwLock; use ra_ap_vfs::{ChangeKind, ChangedFile, FileId, Vfs}; @@ -49,7 +45,6 @@ pub(crate) struct Handle { } pub(crate) type KCLVfs = Arc>; -pub(crate) type KCLWordIndexMap = Arc>>>>; pub(crate) type KCLEntryCache = Arc)>>>; pub(crate) type KCLToolChain = Arc>; @@ -79,8 +74,6 @@ pub(crate) struct LanguageServerState { pub loader: Handle, Receiver>, /// request retry time pub request_retry: Arc>>, - /// The word index map - pub word_index_map: KCLWordIndexMap, /// KCL parse cache pub module_cache: KCLModuleCache, /// KCL resolver cache @@ -104,8 +97,6 @@ pub(crate) struct LanguageServerSnapshot { pub opened_files: Arc>>, /// request retry time pub request_retry: Arc>>, - /// The word index map - pub word_index_map: KCLWordIndexMap, /// KCL parse cache pub module_cache: KCLModuleCache, /// KCL resolver cache @@ -139,7 +130,7 @@ impl LanguageServerState { shutdown_requested: false, analysis: Analysis::default(), opened_files: Arc::new(RwLock::new(HashMap::new())), - word_index_map: Arc::new(RwLock::new(HashMap::new())), + // word_index_map: Arc::new(RwLock::new(HashMap::new())), loader, module_cache: KCLModuleCache::default(), scope_cache: KCLScopeCache::default(), @@ -149,12 +140,12 @@ impl LanguageServerState { request_retry: Arc::new(RwLock::new(HashMap::new())), }; - let word_index_map = state.word_index_map.clone(); - state.thread_pool.execute(move || { - if let Err(err) = update_word_index_state(word_index_map, initialize_params, true) { - log_message(err.to_string(), &task_sender); - } - }); + // // let word_index_map = state.word_index_map.clone(); + // state.thread_pool.execute(move || { + // if let Err(err) = update_word_index_state(word_index_map, initialize_params, true) { + // log_message(err.to_string(), &task_sender); + // } + // }); state } @@ -381,7 +372,7 @@ impl LanguageServerState { vfs: self.vfs.clone(), db: self.analysis.db.clone(), opened_files: self.opened_files.clone(), - word_index_map: self.word_index_map.clone(), + // word_index_map: self.word_index_map.clone(), module_cache: self.module_cache.clone(), scope_cache: self.scope_cache.clone(), entry_cache: self.entry_cache.clone(), @@ -412,24 +403,3 @@ pub(crate) fn log_message(message: String, sender: &Sender) -> anyhow::Res )))?; Ok(()) } - -fn update_word_index_state( - word_index_map: KCLWordIndexMap, - initialize_params: InitializeParams, - prune: bool, -) -> Result<()> { - if let Some(workspace_folders) = initialize_params.workspace_folders { - for folder in workspace_folders { - let path = file_path_from_url(&folder.uri)?; - if let Ok(word_index) = build_word_index(&path, prune) { - word_index_map.write().insert(folder.uri, word_index); - } - } - } else if let Some(root_uri) = initialize_params.root_uri { - let path = file_path_from_url(&root_uri)?; - if let Ok(word_index) = build_word_index(path, prune) { - word_index_map.write().insert(root_uri, word_index); - } - } - Ok(()) -}