Skip to content

Commit 8d98b13

Browse files
committed
Render spell diagnostics when command is executed
1 parent f332ba5 commit 8d98b13

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

helix-spell/src/client.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ pub struct Client {
88

99
impl Client {
1010
pub fn new() -> Self {
11+
// TODO: accept lang as an argument, configurable by the user
1112
let lang = "en_US";
1213
let checker = SpellLauncher::new()
1314
.aspell()
1415
.dictionary(lang)
1516
.launch()
17+
// TODO: instead of unwrap (which panics), figure out proper error handling
1618
.unwrap();
17-
// TODO: instead of unwrap (which panics), figure out proper error handling
1819
Self { checker, lang }
1920
}
2021
pub fn check(&mut self, string: &str) -> Vec<IspellError> {
2122
self.checker.check(string).unwrap_or(Vec::new())
2223
}
2324
}
2425

25-
// TODO: use helix_core::Diagnostic to represent a mispelling
26-
// note: Range start is the location of total characters, regardless of "lines"
27-
// thus, we can probably send the entire string to aspell and things should work alright
26+
// TODO: expose the ability to add words to a user's dictionary, which the ispell crate supports

helix-spell/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ mod tests {
1818
let word = "This sentence contains a misssspelled word";
1919
let errors = client.check(word);
2020
let error = errors.first().unwrap();
21-
assert_eq!(error.word, "misssspelled");
22-
assert_eq!(error.pos, 25);
21+
assert_eq!(error.misspelled, "misssspelled");
22+
assert_eq!(error.position, 25);
2323
}
2424

2525
#[test]

helix-term/src/application.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ impl Application {
326326
// idle timeout
327327
self.editor.clear_idle_timer();
328328
self.handle_idle_timeout();
329+
// HACK: force rendering until I can figure out how
330+
// async jobs work
331+
self.render();
329332

330333
#[cfg(feature = "integration")]
331334
{

helix-term/src/commands/typed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ fn spell_check(
341341
return Ok(());
342342
}
343343
let doc = doc_mut!(cx.editor);
344-
// TODO: make this async via a Job?
345-
doc.spell_check();
344+
let mut diagnostics = doc.spell_check();
345+
doc.add_diagnostics(diagnostics.as_mut());
346346
Ok(())
347347
}
348348

helix-view/src/document.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub struct Document {
119119
version: i32, // should be usize?
120120
pub(crate) modified_since_accessed: bool,
121121

122+
// TODO: add a seperate spell diagnostics list decoupled from the language server?
122123
diagnostics: Vec<Diagnostic>,
123124
language_server: Option<Arc<helix_lsp::Client>>,
124125
}
@@ -393,7 +394,7 @@ impl Document {
393394
Ok(doc)
394395
}
395396

396-
pub fn spell_check(&mut self) {
397+
pub fn spell_check(&mut self) -> Vec<Diagnostic> {
397398
let mut diagnostics = Vec::new();
398399
if let Some(node) = self.syntax() {
399400
let mut spell_checker = helix_spell::Client::new();
@@ -418,17 +419,19 @@ impl Document {
418419
end: position + error.position + word_count,
419420
},
420421
message: error.suggestions.join("\n"),
421-
severity: Some(diagnostic::Severity::Hint),
422+
severity: Some(diagnostic::Severity::Warning),
422423
code: None,
423424
};
424425
diagnostics.push(diagnostic);
426+
// TODO: don't set doc diagnostics here, simply return the Vec<Diagnostic> instead
427+
// and have the caller decide how to handle it
425428
}
426429
position += line.len_chars();
427430
}
428431
}
429432
};
430433
};
431-
self.add_diagnostics(diagnostics.as_mut());
434+
diagnostics
432435
}
433436

434437
pub fn auto_format(&self) -> Option<BoxFuture<'static, Result<Transaction, FormatterError>>> {

0 commit comments

Comments
 (0)