mirror of
https://github.com/helix-editor/helix.git
synced 2025-01-19 13:37:06 +04:00
Switch to Result for invalid language
This commit is contained in:
parent
e8add6f46d
commit
75e6a64327
@ -1254,14 +1254,10 @@ fn language(
|
|||||||
|
|
||||||
let doc = doc_mut!(cx.editor);
|
let doc = doc_mut!(cx.editor);
|
||||||
|
|
||||||
let loader = cx.editor.syn_loader.clone();
|
|
||||||
if args[0] == "text" {
|
if args[0] == "text" {
|
||||||
doc.set_language(None, Some(loader))
|
doc.set_language(None, None)
|
||||||
} else {
|
} else {
|
||||||
let ok = doc.set_language_by_language_id(&args[0], loader);
|
doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone())?;
|
||||||
if !ok {
|
|
||||||
anyhow::bail!("invalid language: {}", args[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
doc.detect_indent_and_line_ending();
|
doc.detect_indent_and_line_ending();
|
||||||
|
|
||||||
|
@ -683,13 +683,12 @@ pub fn set_language_by_language_id(
|
|||||||
&mut self,
|
&mut self,
|
||||||
language_id: &str,
|
language_id: &str,
|
||||||
config_loader: Arc<syntax::Loader>,
|
config_loader: Arc<syntax::Loader>,
|
||||||
) -> bool {
|
) -> anyhow::Result<()> {
|
||||||
let language_config = config_loader.language_config_for_language_id(language_id);
|
let language_config = config_loader
|
||||||
if language_config.is_none() {
|
.language_config_for_language_id(language_id)
|
||||||
return false;
|
.ok_or_else(|| anyhow!("invalid language id: {}", language_id))?;
|
||||||
}
|
self.set_language(Some(language_config), Some(config_loader));
|
||||||
self.set_language(language_config, Some(config_loader));
|
Ok(())
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the LSP.
|
/// Set the LSP.
|
||||||
|
Loading…
Reference in New Issue
Block a user