mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
reworked global analysis to remove unnecissary tuple
Signed-off-by: faldor20 <eli.jambu@yahoo.com>
This commit is contained in:
parent
a6549f3fd3
commit
dd8e76e0e3
3 changed files with 80 additions and 86 deletions
|
@ -59,29 +59,16 @@ fn is_roc_identifier_char(char: &char) -> bool {
|
||||||
}
|
}
|
||||||
///Returns a closure that will run the global analysis and the docinfo for the provided source
|
///Returns a closure that will run the global analysis and the docinfo for the provided source
|
||||||
///This means that you can get positions within the source code before the analysis completes
|
///This means that you can get positions within the source code before the analysis completes
|
||||||
pub(crate) fn global_analysis(
|
pub(crate) fn global_analysis(doc_info: DocInfo) -> Vec<AnalyzedDocument> {
|
||||||
source_url: Url,
|
let fi = doc_info.url.to_file_path().unwrap();
|
||||||
source: String,
|
|
||||||
version: i32,
|
|
||||||
) -> (impl FnOnce() -> Vec<AnalyzedDocument>, DocInfo) {
|
|
||||||
let fi = source_url.to_file_path().unwrap();
|
|
||||||
let src_dir = find_src_dir(&fi).to_path_buf();
|
let src_dir = find_src_dir(&fi).to_path_buf();
|
||||||
let line_info = LineInfo::new(&source);
|
|
||||||
|
|
||||||
let doc_info = DocInfo {
|
|
||||||
url: source_url.clone(),
|
|
||||||
line_info: line_info.clone(),
|
|
||||||
source: source.clone(),
|
|
||||||
version,
|
|
||||||
};
|
|
||||||
//We will return this before the analysis has completed to enable completion
|
//We will return this before the analysis has completed to enable completion
|
||||||
let doc_info_return = doc_info.clone();
|
|
||||||
let perform_analysis = move || {
|
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let loaded = roc_load::load_and_typecheck_str(
|
let loaded = roc_load::load_and_typecheck_str(
|
||||||
&arena,
|
&arena,
|
||||||
fi,
|
fi,
|
||||||
&source,
|
&doc_info.source,
|
||||||
src_dir,
|
src_dir,
|
||||||
roc_target::TargetInfo::default_x86_64(),
|
roc_target::TargetInfo::default_x86_64(),
|
||||||
roc_load::FunctionKind::LambdaSet,
|
roc_load::FunctionKind::LambdaSet,
|
||||||
|
@ -140,12 +127,10 @@ pub(crate) fn global_analysis(
|
||||||
};
|
};
|
||||||
|
|
||||||
for (module_id, (path, source)) in sources {
|
for (module_id, (path, source)) in sources {
|
||||||
documents.push(builder.build_document(path, source, module_id, version));
|
documents.push(builder.build_document(path, source, module_id, doc_info.version));
|
||||||
}
|
}
|
||||||
|
|
||||||
documents
|
documents
|
||||||
};
|
|
||||||
(perform_analysis, doc_info_return)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_src_dir(path: &Path) -> &Path {
|
fn find_src_dir(path: &Path) -> &Path {
|
||||||
|
@ -313,17 +298,26 @@ pub struct DocInfo {
|
||||||
pub version: i32,
|
pub version: i32,
|
||||||
}
|
}
|
||||||
impl DocInfo {
|
impl DocInfo {
|
||||||
|
pub fn new(url: Url, source: String, version: i32) -> Self {
|
||||||
|
Self {
|
||||||
|
url,
|
||||||
|
line_info: LineInfo::new(&source),
|
||||||
|
source,
|
||||||
|
version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
fn debug_log_prefix(&self, offset: usize) {
|
fn debug_log_prefix(&self, offset: usize) {
|
||||||
debug!("prefix source{:?}", self.source);
|
debug!("prefix source: {:?}", self.source);
|
||||||
|
|
||||||
let last_few = self.source.get(offset - 5..offset + 5).unwrap();
|
let last_few = self.source.get(offset - 5..offset + 5).unwrap();
|
||||||
|
|
||||||
let (before, after) = last_few.split_at(5);
|
let (before, after) = last_few.split_at(5);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"starting to get completion items at offset:{:?} content:: '{:?}|{:?}'",
|
"starting to get completion items at offset: {:?} content: '{:?}|{:?}'",
|
||||||
offset, before, after
|
offset, before, after
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -342,7 +342,7 @@ fn find_record_fields(var: Variable, subs: &mut Subs) -> Vec<(String, Variable)>
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Trying to get field completion for a type that is not a record ",);
|
warn!("Trying to get field completion for a type that is not a record : {:?}", subs.dbg(typ));
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,7 @@ use tower_lsp::jsonrpc::Result;
|
||||||
use tower_lsp::lsp_types::*;
|
use tower_lsp::lsp_types::*;
|
||||||
use tower_lsp::{Client, LanguageServer, LspService, Server};
|
use tower_lsp::{Client, LanguageServer, LspService, Server};
|
||||||
|
|
||||||
use crate::analysis::global_analysis;
|
use crate::analysis::{global_analysis, DocInfo};
|
||||||
|
|
||||||
mod analysis;
|
mod analysis;
|
||||||
mod convert;
|
mod convert;
|
||||||
|
@ -132,10 +132,10 @@ impl Inner {
|
||||||
//was write lock
|
//was write lock
|
||||||
|
|
||||||
debug!("V{:?}:change acquired registry lock", version);
|
debug!("V{:?}:change acquired registry lock", version);
|
||||||
let (results, partial) = global_analysis(fi.clone(), text, version);
|
let doc_info = DocInfo::new(fi.clone(), text, version);
|
||||||
|
|
||||||
self.registry
|
self.registry
|
||||||
.apply_doc_info_changes(fi.clone(), partial.clone())
|
.apply_doc_info_changes(fi.clone(), doc_info.clone())
|
||||||
.await;
|
.await;
|
||||||
//Now that we've got our new partial document written and we hold the exclusive write_handle to its analysis we can allow other tasks to access the registry and the doc_info inside this partial document
|
//Now that we've got our new partial document written and we hold the exclusive write_handle to its analysis we can allow other tasks to access the registry and the doc_info inside this partial document
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ impl Inner {
|
||||||
return Err("Not latest version skipping analysis".to_string());
|
return Err("Not latest version skipping analysis".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = match tokio::task::spawn_blocking(results).await {
|
let results = match tokio::task::spawn_blocking(|| global_analysis(doc_info)).await {
|
||||||
Err(e) => return Err(format!("Document analysis failed. reason:{:?}", e)),
|
Err(e) => return Err(format!("Document analysis failed. reason:{:?}", e)),
|
||||||
Ok(a) => a,
|
Ok(a) => a,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue