Skip to content

Commit 5112b9d

Browse files
committed
Execute spell check as a Job::Callback, removing hack
1 parent 8d98b13 commit 5112b9d

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

helix-term/src/application.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl Application {
328328
self.handle_idle_timeout();
329329
// HACK: force rendering until I can figure out how
330330
// async jobs work
331-
self.render();
331+
// self.render();
332332

333333
#[cfg(feature = "integration")]
334334
{

helix-term/src/commands/typed.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,23 @@ fn spell_check(
340340
if event != PromptEvent::Validate {
341341
return Ok(());
342342
}
343-
let doc = doc_mut!(cx.editor);
344-
let mut diagnostics = doc.spell_check();
345-
doc.add_diagnostics(diagnostics.as_mut());
343+
let doc = doc!(cx.editor);
344+
// TODO: could probably just be a job?
345+
let callback = make_spell_check_callback(doc.id());
346+
cx.jobs.callback(callback);
346347
Ok(())
347348
}
348349

350+
async fn make_spell_check_callback(doc_id: DocumentId) -> anyhow::Result<job::Callback> {
351+
let call: job::Callback = Box::new(move |editor, _compositor| {
352+
if let Some(doc) = editor.document_mut(doc_id) {
353+
let mut diagnostics = doc.spell_check();
354+
doc.add_diagnostics(diagnostics.as_mut());
355+
};
356+
});
357+
Ok(call)
358+
}
359+
349360
fn set_indent_style(
350361
cx: &mut compositor::Context,
351362
args: &[Cow<str>],

helix-view/src/document.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,8 @@ impl Document {
11151115

11161116
pub fn add_diagnostics(&mut self, diagnostics: &mut Vec<Diagnostic>) {
11171117
self.diagnostics.append(diagnostics);
1118+
self.diagnostics
1119+
.sort_unstable_by_key(|diagnostic| diagnostic.range);
11181120
}
11191121

11201122
/// Get the document's auto pairs. If the document has a recognized

0 commit comments

Comments
 (0)