Skip to content

Commit b125d2b

Browse files
committed
Update index before spawning initial diagnostics
1 parent 8231963 commit b125d2b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

crates/ark/src/lsp/state_handlers.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ pub(crate) fn did_open(
144144
parsers.insert(uri.clone(), parser);
145145
state.documents.insert(uri.clone(), document.clone());
146146

147+
update_index(&uri, &document);
147148
lsp::spawn_diagnostics_refresh(uri, document, state.clone());
148149

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

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

164-
// Update index
165-
if let Ok(path) = uri.to_file_path() {
166-
let path = Path::new(&path);
167-
if let Err(err) = indexer::update(&doc, &path) {
168-
lsp::log_error!("{err:?}");
169-
}
170-
}
171-
172-
// Refresh diagnostics
164+
update_index(uri, doc);
173165
lsp::spawn_diagnostics_refresh(uri.clone(), doc.clone(), state.clone());
174166

175167
Ok(())
@@ -214,3 +206,16 @@ pub(crate) fn did_change_console_inputs(
214206

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

0 commit comments

Comments
 (0)