diff --git a/crates/lang_srv/src/analysis.rs b/crates/lang_srv/src/analysis.rs index 5ec9ba2e6a..83cfc5b6b9 100644 --- a/crates/lang_srv/src/analysis.rs +++ b/crates/lang_srv/src/analysis.rs @@ -1,5 +1,5 @@ use std::{ - collections::{HashMap}, + collections::HashMap, path::{Path, PathBuf}, sync::Arc, }; @@ -12,7 +12,7 @@ use roc_collections::{MutMap, MutSet}; use roc_load::{CheckedModule, LoadedModule}; use roc_module::symbol::{Interns, ModuleId, Symbol}; use roc_packaging::cache::{self, RocCacheDir}; -use roc_region::all::{LineInfo}; +use roc_region::all::LineInfo; use roc_reporting::report::RocDocAllocator; use roc_solve_problem::TypeError; use roc_types::{ @@ -44,7 +44,7 @@ pub(super) struct AnalyzedModule { module_id: ModuleId, interns: Interns, subs: Subs, - other_subs: Arc>>, + other_modules_subs: Arc>>, abilities: AbilitiesStore, declarations: Declarations, // We need this because ModuleIds are not stable between compilations, so a ModuleId visible to @@ -106,10 +106,10 @@ pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec { solved, abilities_store, docs_by_module, - + exposed_imports, mut imports, - + exposes, .. } = module; @@ -119,15 +119,16 @@ pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec { abilities_store, }); debug!("exposed_imports: {:#?}", &exposed_imports); + //We take the imports from each module, lookup the symbol within that module's list of exposed symbols and then get the type info for that import let exposed_imports: HashMap<_, _> = exposed_imports .into_iter() - .map(|(id, symbols)| { + .map(|(module_id, symbols)| { ( - id, + module_id, symbols .into_iter() .filter_map(|(symbol, _)| { - exposes.get(&id)?.iter().find(|(symb, _)| { + exposes.get(&module_id)?.iter().find(|(symb, _)| { //TODO this seems to not be comparing proprely so we aren't getting any exposed imports symb == &symbol }) @@ -137,14 +138,16 @@ pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec { ) }) .collect(); + //Create a list let exposed: HashMap<_, _> = exposes .into_iter() .map(|(id, symbols)| (id, Arc::new(symbols))) .collect(); + //Combine the subs from all modules let all_subs = Arc::new(Mutex::new( typechecked .iter() - .map(|(k, v)| (k.clone(), v.solved_subs.0.clone())) + .map(|(k, v)| (*k, v.solved_subs.0.clone())) .collect::>(), )); let mut builder = AnalyzedDocumentBuilder { @@ -253,6 +256,8 @@ impl<'a> AnalyzedDocumentBuilder<'a> { let abilities; let declarations; let aliases; + + //lookup the type info for each import from the module where it was exposed let imports = self .imports .remove(&module_id) @@ -288,7 +293,7 @@ impl<'a> AnalyzedDocumentBuilder<'a> { abilities, declarations, module_id, - other_subs: self.all_subs.clone(), + other_modules_subs: self.all_subs.clone(), interns: self.interns.clone(), module_id_to_url: self.module_id_to_url.clone(), }; diff --git a/crates/lang_srv/src/analysis/analysed_doc.rs b/crates/lang_srv/src/analysis/analysed_doc.rs index 210dc8ed42..dfc44ddc2a 100644 --- a/crates/lang_srv/src/analysis/analysed_doc.rs +++ b/crates/lang_srv/src/analysis/analysed_doc.rs @@ -228,7 +228,7 @@ impl AnalyzedDocument { exposed_imports, aliases, imports, - other_subs, + other_modules_subs, .. } = self.module()?; @@ -245,14 +245,11 @@ impl AnalyzedDocument { info!("Getting module dot completion"); //TODO: this doesn't work with builtins for some reason Some(get_upper_case_completion_items( - position, symbol_prefix, module_id, interns, - &mut subs.clone(), imports, - aliases, - other_subs, + other_modules_subs, true, )) } else { @@ -260,10 +257,10 @@ impl AnalyzedDocument { field_completion( position, symbol_prefix, - &declarations, - &interns, + declarations, + interns, &mut subs.clone(), - &module_id, + module_id, ) } } else { @@ -274,14 +271,11 @@ impl AnalyzedDocument { if is_module_or_type_completion { info!("Getting module completion"); let completions = get_upper_case_completion_items( - position, symbol_prefix, module_id, interns, - &mut subs.clone(), imports, - aliases, - other_subs, + other_modules_subs, true, ); Some(completions) diff --git a/crates/lang_srv/src/server.rs b/crates/lang_srv/src/server.rs index 4d33d2d678..27158b17f8 100644 --- a/crates/lang_srv/src/server.rs +++ b/crates/lang_srv/src/server.rs @@ -400,8 +400,8 @@ mod tests { info!("doc is:\n{0}", change); inner.change(&url, change, 1).await.unwrap(); - let comp1 = get_completion_labels(reg, &url, position).await; - comp1 + + get_completion_labels(reg, &url, position).await } ///Test that completion works properly when we apply an "as" pattern to an identifier @@ -491,9 +491,8 @@ mod tests { #[tokio::test] async fn test_completion_fun_params() { let actual = completion_test( - indoc! {r#" - main =\param1,param2-> - "#}, + indoc! {r"main =\param1,param2-> + "}, "par", Position::new(4, 3), ) @@ -512,9 +511,8 @@ mod tests { #[tokio::test] async fn test_completion_closure() { let actual = completion_test( - indoc! {r#" - main =[]|>List.map\param1,param2-> - "#}, + indoc! {r"main =[]|>List.map\param1,param2-> + "}, "par", Position::new(4, 3), )