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::{
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<Mutex<HashMap<ModuleId, Subs>>>,
other_modules_subs: Arc<Mutex<HashMap<ModuleId, Subs>>>,
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<AnalyzedDocument> {
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<AnalyzedDocument> {
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<AnalyzedDocument> {
)
})
.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::<HashMap<_, _>>(),
));
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(),
};

View File

@ -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)

View File

@ -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),
)