Skip to content

Commit

Permalink
removing some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Feel-ix-343 committed Mar 11, 2024
1 parent d961018 commit 247e684
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
use completion::get_completions;
use diagnostics::diagnostics;
use itertools::Itertools;
use rayon::prelude::*;
use references::references;
use serde_json::Value;
use symbol::{document_symbol, workspace_symbol};
Expand Down Expand Up @@ -62,7 +63,7 @@ impl Backend {
};
let text = &params.text;
Vault::update_vault(vault, (&path, text));
} // must close the write lock before publishing diagnostics; I don't really like how imperative this is; TODO: Fix this shit
} // must close the write lock before publishing diagnostics; I don't really like how imperative this is

match self.publish_diagnostics().await {
Ok(_) => (),
Expand All @@ -86,19 +87,18 @@ impl Backend {

let timer = std::time::Instant::now();

{
let _ = self
.bind_vault_mut(|vault| {
let Ok(new_vault) = Vault::construct_vault(vault.root_dir()) else {
return Err(Error::new(ErrorCode::ServerError(0)));
};
let r = self
.bind_vault_mut(|vault| {
let Ok(new_vault) = Vault::construct_vault(vault.root_dir()) else {
return Err(Error::new(ErrorCode::ServerError(0)));
};

*vault = new_vault;
*vault = new_vault;

Ok(())
})
.await;
} // same issue as in the above function; TODO: Fix this
Ok(())
})
.await;
drop(r);

let elapsed = timer.elapsed();

Expand Down Expand Up @@ -147,24 +147,16 @@ impl Backend {

diagnostics(vault, (&path, &uri)).map(|diags| (uri.clone(), diags))
})
.collect_vec())
.collect::<Vec<_>>())
})
.await?;

self.client
.log_message(
MessageType::LOG,
format!(
"Calcualted Diagnostics for files: {:?}",
diagnostics.iter().map(|(uri, _)| uri).collect_vec()
),
)
.await;

for (uri, diags) in diagnostics {
self.client.publish_diagnostics(uri, diags, None).await;
}

self.client.log_message(MessageType::WARNING, "Published diagnostics").await;

Ok(())
}

Expand All @@ -178,16 +170,17 @@ impl Backend {
/// in the call back functions. (though to get aroudn this, the callback could return a Result of a writer style monad, which could be logged async outside of
/// the callback)
async fn bind_vault<T>(&self, callback: impl FnOnce(&Vault) -> Result<T>) -> Result<T> {
let vault_option = self.vault.read().await;
let Some(vault) = vault_option.deref() else {
let guard = self.vault.read().await;
let Some(vault) = guard.deref() else {
return Err(Error::new(ErrorCode::ServerError(0)));
};

callback(vault)
}

async fn bind_vault_mut<T>(&self, callback: impl Fn(&mut Vault) -> Result<T>) -> Result<T> {
let Some(ref mut vault) = *self.vault.write().await else {
let mut guard = self.vault.write().await;
let Some(ref mut vault) = *guard else {
return Err(Error::new(ErrorCode::ServerError(0)));
};

Expand Down Expand Up @@ -516,10 +509,6 @@ impl LanguageServer for Backend {
.bind_vault(|vault| Ok(tokens::semantic_tokens_full(vault, &path, params)))
.await;

self.client
.log_message(MessageType::LOG, format!("{:?}", res))
.await;

return res;
}
}
Expand Down

0 comments on commit 247e684

Please sign in to comment.