Skip to content

Commit

Permalink
Add error handling to set language command
Browse files Browse the repository at this point in the history
If you type a nonexistant language an appropriate message will show,
and the language won't be changed.
  • Loading branch information
A-Walrus authored and archseer committed Sep 10, 2022
1 parent cc47d3f commit e8add6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 10 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,16 @@ fn language(
}

let doc = doc_mut!(cx.editor);
doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone());

let loader = cx.editor.syn_loader.clone();
if args[0] == "text" {
doc.set_language(None, Some(loader))
} else {
let ok = doc.set_language_by_language_id(&args[0], loader);
if !ok {
anyhow::bail!("invalid language: {}", args[0]);
}
}
doc.detect_indent_and_line_ending();

let id = doc.id();
Expand Down
6 changes: 5 additions & 1 deletion helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,13 @@ impl Document {
&mut self,
language_id: &str,
config_loader: Arc<syntax::Loader>,
) {
) -> bool {
let language_config = config_loader.language_config_for_language_id(language_id);
if language_config.is_none() {
return false;
}
self.set_language(language_config, Some(config_loader));
true
}

/// Set the LSP.
Expand Down

0 comments on commit e8add6f

Please sign in to comment.