This commit is contained in:
faldor20 2024-02-01 18:17:10 +10:00
parent 93b6ca7bb5
commit ff0514aafc
No known key found for this signature in database
GPG Key ID: F2216079B890CD57
4 changed files with 20 additions and 22 deletions

View File

@ -52,14 +52,14 @@ impl DocInfo {
#[cfg(debug_assertions)]
#[allow(unused)]
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 (before, after) = last_few.split_at(5);
debug!(
"starting to get completion items at offset: {:?} content: '{:?}|{:?}'",
"Starting to get completion items at offset: {:?} content: '{:?}|{:?}'",
offset, before, after
);
}
@ -207,7 +207,7 @@ impl AnalyzedDocument {
) -> Option<Vec<CompletionItem>> {
let symbol_prefix = latest_doc.get_prefix_at_position(position);
debug!(
"starting to get completion items for prefix: {:?} docVersion:{:?}",
"Starting to get completion items for prefix: {:?} docVersion:{:?}",
symbol_prefix, latest_doc.version
);
let len_diff = latest_doc.source.len() as i32 - self.doc_info.source.len() as i32;
@ -216,7 +216,7 @@ impl AnalyzedDocument {
//TODO: this is kind of a hack and should be removed once we can do some minimal parsing without full type checking
let mut position = position.to_roc_position(&latest_doc.line_info);
position.offset = (position.offset as i32 - len_diff - 1) as u32;
debug!("completion offset: {:?}", position.offset);
debug!("Completion offset: {:?}", position.offset);
let AnalyzedModule {
module_id,

View File

@ -60,7 +60,7 @@ impl Visitor for CompletionVisitor<'_> {
}
impl CompletionVisitor<'_> {
fn extract_defs(&mut self, def: &Def) -> Vec<(Symbol, Variable)> {
trace!("completion begin");
trace!("Completion begin");
def.pattern_vars
.iter()
.map(|(symbol, var)| (*symbol, *var))
@ -228,7 +228,7 @@ impl CompletionVisitor<'_> {
.flat_map(|(var, _, pat)| self.patterns(&pat.value, var));
//We add in the pattern for the function declaration
out.extend(args);
trace!("added function args to completion output =:{:#?}", out);
trace!("Added function args to completion output =:{:#?}", out);
}
out
}
@ -413,10 +413,10 @@ pub fn field_completion(
} = get_field_completion_parts(&symbol_prefix)?;
debug!(
"getting record field completions: variable: {:?} field: {:?} middle: {:?} ",
"Getting record field completions: variable: {:?} field: {:?} middle: {:?} ",
var, field, middle_fields
);
//TODO: this is kind of just a hack. We are getting all the completions and seeing if any match the part before the dot as a way to get the Variable type of the variable before the dot. I imagine there are much faster ways to do this
let completion = get_completions(position, declarations, var.to_string(), interns)
.into_iter()
.map(|a| (a.0.as_str(interns).to_string(), a.1))

View File

@ -86,7 +86,7 @@ impl Registry {
pub async fn apply_changes<'a>(&self, analysed_docs: Vec<AnalyzedDocument>, updating_url: Url) {
let mut documents = self.documents.lock().await;
debug!(
"finised doc analysis for doc: {:?}",
"Finished doc analysis for doc: {}",
updating_url.to_string()
);
@ -103,7 +103,7 @@ impl Registry {
match doc {
Some(a) => {
debug!(
"set the docInfo for {:?} to version:{:?}",
"Set the docInfo for {:?} to version:{:?}",
url.as_str(),
info.version
);
@ -113,16 +113,15 @@ impl Registry {
latest_document: OnceLock::new(),
};
}
None => debug!("no existing docinfo for {:?} ", url.as_str()),
None => debug!("So existing docinfo for {:?} ", url.as_str()),
}
}
async fn document_info_by_url(&self, url: &Url) -> Option<DocInfo> {
self.documents.lock().await.get(url).map(|a| a.info.clone())
}
}U
///Tries to get the latest document from analysis.
///Gives up and returns none after 5 seconds.
///Gives up and returns none aft 5 seconds.
async fn latest_document_by_url(&self, url: &Url) -> Option<Arc<AnalyzedDocument>> {
let duration = std::time::Duration::from_secs(5);
tokio::time::timeout(duration, async {
@ -179,13 +178,13 @@ impl Registry {
url: &Url,
position: Position,
) -> Option<CompletionResponse> {
trace!("starting completion ");
trace!("Starting completion ");
let lock = self.documents.lock().await;
let pair = lock.get(url)?;
let latest_doc_info = &pair.info;
info!(
"using document version:{:?} for completion ",
"Using document version:{:?} for completion ",
latest_doc_info.version
);

View File

@ -94,10 +94,10 @@ impl RocServer {
//The analysis task can be cancelled by another change coming in which will update the watched variable
if let Err(e) = updating_result {
debug!("cancelled change. Reason:{:?}", e);
debug!("Cancelled change. Reason:{:?}", e);
return;
}
debug!("applied_change getting and returning diagnostics");
debug!("Applied_change getting and returning diagnostics");
let diagnostics = self.state.registry.diagnostics(&fi).await;
@ -165,7 +165,7 @@ impl RocServerState {
if let Some(latest_version) = latest_version {
if latest_version != version {
return Err(format!(
"version {0} doesn't match latest: {1} discarding analysis ",
"Version {0} doesn't match latest: {1} discarding analysis",
version, latest_version
));
}
@ -214,7 +214,6 @@ impl LanguageServer for RocServer {
let TextDocumentContentChangeEvent { text, .. } =
params.content_changes.into_iter().next().unwrap();
trace!("got did_change");
self.change(uri, text, version).await;
}
@ -309,7 +308,7 @@ impl LanguageServer for RocServer {
async fn completion(&self, params: CompletionParams) -> Result<Option<CompletionResponse>> {
let doc = params.text_document_position;
trace!("got completion request");
trace!("Got completion request");
panic_wrapper_async(|| async {
self.state
@ -386,7 +385,7 @@ mod tests {
.filter_level(log::LevelFilter::Trace)
.init();
});
info!("doc is:\n{0}", doc);
info!("Doc is:\n{0}", doc);
let url = Url::parse("file:/Test.roc").unwrap();
let inner = RocServerState::new();