mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 10:56:19 +04:00
Add error handling to set language command
If you type a nonexistant language an appropriate message will show, and the language won't be changed.
This commit is contained in:
parent
cc47d3fb9d
commit
e8add6f46d
@ -1253,7 +1253,16 @@ fn language(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let doc = doc_mut!(cx.editor);
|
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();
|
doc.detect_indent_and_line_ending();
|
||||||
|
|
||||||
let id = doc.id();
|
let id = doc.id();
|
||||||
|
@ -683,9 +683,13 @@ 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 {
|
||||||
let language_config = config_loader.language_config_for_language_id(language_id);
|
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));
|
self.set_language(language_config, Some(config_loader));
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the LSP.
|
/// Set the LSP.
|
||||||
|
Loading…
Reference in New Issue
Block a user