Switch to Result for invalid language

pull/3780/head
A-Walrus 2 years ago committed by Blaž Hrastnik
parent e8add6f46d
commit 75e6a64327

@ -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();

@ -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.

Loading…
Cancel
Save