aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA-Walrus2022-08-09 07:43:27 +0000
committerBlaž Hrastnik2022-09-10 13:23:38 +0000
commit75e6a6432747eae6d2255afc52f20ced6902519b (patch)
tree14b99168cb50c65c9adbbd6181ee226dda7c4c70
parente8add6f46d0f208c96407151276a985dd34fc93f (diff)
Switch to Result for invalid language
-rw-r--r--helix-term/src/commands/typed.rs8
-rw-r--r--helix-view/src/document.rs13
2 files changed, 8 insertions, 13 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 127eea0d..674ce7a6 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -1254,14 +1254,10 @@ fn language(
let doc = doc_mut!(cx.editor);
- let loader = cx.editor.syn_loader.clone();
if args[0] == "text" {
- doc.set_language(None, Some(loader))
+ doc.set_language(None, None)
} else {
- let ok = doc.set_language_by_language_id(&args[0], loader);
- if !ok {
- anyhow::bail!("invalid language: {}", args[0]);
- }
+ doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone())?;
}
doc.detect_indent_and_line_ending();
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 84c92320..8ebc9002 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -683,13 +683,12 @@ 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
+ ) -> anyhow::Result<()> {
+ let language_config = config_loader
+ .language_config_for_language_id(language_id)
+ .ok_or_else(|| anyhow!("invalid language id: {}", language_id))?;
+ self.set_language(Some(language_config), Some(config_loader));
+ Ok(())
}
/// Set the LSP.