cleanup and comment for clarity

This commit is contained in:
Eli Dowling 2024-02-11 13:09:44 +10:00 committed by faldor20
parent b98633f1ba
commit 4a872a3ccf
No known key found for this signature in database
GPG key ID: F2216079B890CD57
3 changed files with 27 additions and 30 deletions

View file

@ -1,5 +1,5 @@
use std::{ use std::{
collections::{HashMap}, collections::HashMap,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::Arc, sync::Arc,
}; };
@ -12,7 +12,7 @@ use roc_collections::{MutMap, MutSet};
use roc_load::{CheckedModule, LoadedModule}; use roc_load::{CheckedModule, LoadedModule};
use roc_module::symbol::{Interns, ModuleId, Symbol}; use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_packaging::cache::{self, RocCacheDir}; use roc_packaging::cache::{self, RocCacheDir};
use roc_region::all::{LineInfo}; use roc_region::all::LineInfo;
use roc_reporting::report::RocDocAllocator; use roc_reporting::report::RocDocAllocator;
use roc_solve_problem::TypeError; use roc_solve_problem::TypeError;
use roc_types::{ use roc_types::{
@ -44,7 +44,7 @@ pub(super) struct AnalyzedModule {
module_id: ModuleId, module_id: ModuleId,
interns: Interns, interns: Interns,
subs: Subs, subs: Subs,
other_subs: Arc<Mutex<HashMap<ModuleId, Subs>>>, other_modules_subs: Arc<Mutex<HashMap<ModuleId, Subs>>>,
abilities: AbilitiesStore, abilities: AbilitiesStore,
declarations: Declarations, declarations: Declarations,
// We need this because ModuleIds are not stable between compilations, so a ModuleId visible to // We need this because ModuleIds are not stable between compilations, so a ModuleId visible to
@ -119,15 +119,16 @@ pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec<AnalyzedDocument> {
abilities_store, abilities_store,
}); });
debug!("exposed_imports: {:#?}", &exposed_imports); 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 let exposed_imports: HashMap<_, _> = exposed_imports
.into_iter() .into_iter()
.map(|(id, symbols)| { .map(|(module_id, symbols)| {
( (
id, module_id,
symbols symbols
.into_iter() .into_iter()
.filter_map(|(symbol, _)| { .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 //TODO this seems to not be comparing proprely so we aren't getting any exposed imports
symb == &symbol symb == &symbol
}) })
@ -137,14 +138,16 @@ pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec<AnalyzedDocument> {
) )
}) })
.collect(); .collect();
//Create a list
let exposed: HashMap<_, _> = exposes let exposed: HashMap<_, _> = exposes
.into_iter() .into_iter()
.map(|(id, symbols)| (id, Arc::new(symbols))) .map(|(id, symbols)| (id, Arc::new(symbols)))
.collect(); .collect();
//Combine the subs from all modules
let all_subs = Arc::new(Mutex::new( let all_subs = Arc::new(Mutex::new(
typechecked typechecked
.iter() .iter()
.map(|(k, v)| (k.clone(), v.solved_subs.0.clone())) .map(|(k, v)| (*k, v.solved_subs.0.clone()))
.collect::<HashMap<_, _>>(), .collect::<HashMap<_, _>>(),
)); ));
let mut builder = AnalyzedDocumentBuilder { let mut builder = AnalyzedDocumentBuilder {
@ -253,6 +256,8 @@ impl<'a> AnalyzedDocumentBuilder<'a> {
let abilities; let abilities;
let declarations; let declarations;
let aliases; let aliases;
//lookup the type info for each import from the module where it was exposed
let imports = self let imports = self
.imports .imports
.remove(&module_id) .remove(&module_id)
@ -288,7 +293,7 @@ impl<'a> AnalyzedDocumentBuilder<'a> {
abilities, abilities,
declarations, declarations,
module_id, module_id,
other_subs: self.all_subs.clone(), other_modules_subs: self.all_subs.clone(),
interns: self.interns.clone(), interns: self.interns.clone(),
module_id_to_url: self.module_id_to_url.clone(), module_id_to_url: self.module_id_to_url.clone(),
}; };

View file

@ -228,7 +228,7 @@ impl AnalyzedDocument {
exposed_imports, exposed_imports,
aliases, aliases,
imports, imports,
other_subs, other_modules_subs,
.. ..
} = self.module()?; } = self.module()?;
@ -245,14 +245,11 @@ impl AnalyzedDocument {
info!("Getting module dot completion"); info!("Getting module dot completion");
//TODO: this doesn't work with builtins for some reason //TODO: this doesn't work with builtins for some reason
Some(get_upper_case_completion_items( Some(get_upper_case_completion_items(
position,
symbol_prefix, symbol_prefix,
module_id, module_id,
interns, interns,
&mut subs.clone(),
imports, imports,
aliases, other_modules_subs,
other_subs,
true, true,
)) ))
} else { } else {
@ -260,10 +257,10 @@ impl AnalyzedDocument {
field_completion( field_completion(
position, position,
symbol_prefix, symbol_prefix,
&declarations, declarations,
&interns, interns,
&mut subs.clone(), &mut subs.clone(),
&module_id, module_id,
) )
} }
} else { } else {
@ -274,14 +271,11 @@ impl AnalyzedDocument {
if is_module_or_type_completion { if is_module_or_type_completion {
info!("Getting module completion"); info!("Getting module completion");
let completions = get_upper_case_completion_items( let completions = get_upper_case_completion_items(
position,
symbol_prefix, symbol_prefix,
module_id, module_id,
interns, interns,
&mut subs.clone(),
imports, imports,
aliases, other_modules_subs,
other_subs,
true, true,
); );
Some(completions) Some(completions)

View file

@ -400,8 +400,8 @@ mod tests {
info!("doc is:\n{0}", change); info!("doc is:\n{0}", change);
inner.change(&url, change, 1).await.unwrap(); 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 ///Test that completion works properly when we apply an "as" pattern to an identifier
@ -491,9 +491,8 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_completion_fun_params() { async fn test_completion_fun_params() {
let actual = completion_test( let actual = completion_test(
indoc! {r#" indoc! {r"main =\param1,param2->
main =\param1,param2-> "},
"#},
"par", "par",
Position::new(4, 3), Position::new(4, 3),
) )
@ -512,9 +511,8 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn test_completion_closure() { async fn test_completion_closure() {
let actual = completion_test( let actual = completion_test(
indoc! {r#" indoc! {r"main =[]|>List.map\param1,param2->
main =[]|>List.map\param1,param2-> "},
"#},
"par", "par",
Position::new(4, 3), Position::new(4, 3),
) )