Skip to content

Commit

Permalink
fix: temp fix for performance issues through parallelizing diagnostic
Browse files Browse the repository at this point in the history
calculation

Related to #29
  • Loading branch information
Feel-ix-343 committed Mar 11, 2024
1 parent 247e684 commit ec133d8
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ impl Backend {

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

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)));
};
{
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;
drop(r);
Ok(())
})
.await;
}

let elapsed = timer.elapsed();

Expand Down Expand Up @@ -141,7 +142,7 @@ impl Backend {
let diagnostics = self
.bind_vault(|vault| {
Ok(uris
.iter()
.par_iter()
.filter_map(|uri| {
let path = uri.to_file_path().ok()?;

Expand All @@ -155,8 +156,6 @@ impl Backend {
self.client.publish_diagnostics(uri, diags, None).await;
}

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

Ok(())
}

Expand Down Expand Up @@ -326,24 +325,26 @@ impl LanguageServer for Backend {
}

async fn did_open(&self, params: DidOpenTextDocumentParams) {
let _new_files = self
.bind_opened_files_mut(|files| {
// diagnostics will only be published for the files that are opened; We must track which files are opened
let path = params_path!(params)?;
{
let _new_files = self
.bind_opened_files_mut(|files| {
// diagnostics will only be published for the files that are opened; We must track which files are opened
let path = params_path!(params)?;

files.insert(path);
files.insert(path);

Ok(files.clone())
})
Ok(files.clone())
})
.await;

self.client.log_message(MessageType::LOG, "Added file").await;
self.client.log_message(MessageType::LOG, "Added file").await;

self.update_vault(TextDocumentItem {
uri: params.text_document.uri,
text: params.text_document.text,
})
.await; // usually, this is not necesary; however some may start the LS without saving a changed file, so it is necessary
self.update_vault(TextDocumentItem {
uri: params.text_document.uri,
text: params.text_document.text,
})
.await; // usually, this is not necesary; however some may start the LS without saving a changed file, so it is necessary
} // drop the lock

match self.publish_diagnostics().await {
Ok(_) => (),
Expand Down

0 comments on commit ec133d8

Please sign in to comment.