Skip to content

Commit

Permalink
Update index before spawning initial diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed May 30, 2024
1 parent 8231963 commit b125d2b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions crates/ark/src/lsp/state_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub(crate) fn did_open(
parsers.insert(uri.clone(), parser);
state.documents.insert(uri.clone(), document.clone());

update_index(&uri, &document);
lsp::spawn_diagnostics_refresh(uri, document, state.clone());

Ok(())
Expand All @@ -158,18 +159,9 @@ pub(crate) fn did_change(
let doc = state.get_document_mut(uri)?;
let mut parser = parsers.get_mut(uri)?;

// Respond to document updates
doc.on_did_change(&mut parser, &params);

// Update index
if let Ok(path) = uri.to_file_path() {
let path = Path::new(&path);
if let Err(err) = indexer::update(&doc, &path) {
lsp::log_error!("{err:?}");
}
}

// Refresh diagnostics
update_index(uri, doc);
lsp::spawn_diagnostics_refresh(uri.clone(), doc.clone(), state.clone());

Ok(())
Expand Down Expand Up @@ -214,3 +206,16 @@ pub(crate) fn did_change_console_inputs(

Ok(())
}

// FIXME: The initial indexer is currently racing against our state notification
// handlers. The indexer is synchronised through a mutex but we might end up in
// a weird state. Eventually the index should be moved to WorldState and created
// on demand with Salsa instrumenting and cancellation.
fn update_index(uri: &url::Url, doc: &Document) {
if let Ok(path) = uri.to_file_path() {
let path = Path::new(&path);
if let Err(err) = indexer::update(&doc, &path) {
lsp::log_error!("{err:?}");
}
}
}

0 comments on commit b125d2b

Please sign in to comment.