Skip to content

Commit

Permalink
Execute spell check as a Job::Callback, removing hack
Browse files Browse the repository at this point in the history
  • Loading branch information
connorlay committed Sep 13, 2022
1 parent 8d98b13 commit 5112b9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl Application {
self.handle_idle_timeout();
// HACK: force rendering until I can figure out how
// async jobs work
self.render();
// self.render();

#[cfg(feature = "integration")]
{
Expand Down
17 changes: 14 additions & 3 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,23 @@ fn spell_check(
if event != PromptEvent::Validate {
return Ok(());
}
let doc = doc_mut!(cx.editor);
let mut diagnostics = doc.spell_check();
doc.add_diagnostics(diagnostics.as_mut());
let doc = doc!(cx.editor);
// TODO: could probably just be a job?
let callback = make_spell_check_callback(doc.id());
cx.jobs.callback(callback);
Ok(())
}

async fn make_spell_check_callback(doc_id: DocumentId) -> anyhow::Result<job::Callback> {
let call: job::Callback = Box::new(move |editor, _compositor| {
if let Some(doc) = editor.document_mut(doc_id) {
let mut diagnostics = doc.spell_check();
doc.add_diagnostics(diagnostics.as_mut());
};
});
Ok(call)
}

fn set_indent_style(
cx: &mut compositor::Context,
args: &[Cow<str>],
Expand Down
2 changes: 2 additions & 0 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,8 @@ impl Document {

pub fn add_diagnostics(&mut self, diagnostics: &mut Vec<Diagnostic>) {
self.diagnostics.append(diagnostics);
self.diagnostics
.sort_unstable_by_key(|diagnostic| diagnostic.range);
}

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

0 comments on commit 5112b9d

Please sign in to comment.