aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands
diff options
context:
space:
mode:
authorRoland Kovacs2022-04-05 00:56:14 +0000
committerGitHub2022-04-05 00:56:14 +0000
commitd962e06e91b997813092cc5e49a800cc9d4f0ee1 (patch)
tree9ccbee392cbee6d0dc5e9c30bd73e44d5c47a444 /helix-term/src/commands
parent6fc6f87260a2f11a892f09678fc6c10b01e88e3f (diff)
Add runtime language configuration (#1794) (#1866)
* Add runtime language configuration (#1794) * Add set-language typable command to change the language of current buffer. * Add completer for available language options. * Update set-language to refresh language server as well * Add language id based config lookup on `syntax::Loader`. * Add `Document::set_language3` to set programming language based on language id. * Update `Editor::refresh_language_server` to try language detection only if language is not already set. * Remove language detection from Editor::refresh_language_server * Move document language detection to where the scratch buffer is saved. * Rename Document::set_language3 to Document::set_language_by_language_id. * Remove unnecessary clone in completers::language
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r--helix-term/src/commands/typed.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 4c044793..8f74adb6 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -217,6 +217,7 @@ fn write_impl(cx: &mut compositor::Context, path: Option<&Cow<str>>) -> anyhow::
if path.is_some() {
let id = doc.id();
+ doc.detect_language(cx.editor.syn_loader.clone());
let _ = cx.editor.refresh_language_server(id);
}
Ok(())
@@ -931,6 +932,24 @@ fn setting(
Ok(())
}
+/// Change the language of the current buffer at runtime.
+fn language(
+ cx: &mut compositor::Context,
+ args: &[Cow<str>],
+ _event: PromptEvent,
+) -> anyhow::Result<()> {
+ if args.len() != 1 {
+ anyhow::bail!("Bad arguments. Usage: `:set-language language`");
+ }
+
+ let doc = doc_mut!(cx.editor);
+ doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone());
+
+ let id = doc.id();
+ cx.editor.refresh_language_server(id);
+ Ok(())
+}
+
fn sort(
cx: &mut compositor::Context,
args: &[Cow<str>],
@@ -1409,6 +1428,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
completer: None,
},
TypableCommand {
+ name: "set-language",
+ aliases: &["lang"],
+ doc: "Set the language of current buffer.",
+ fun: language,
+ completer: Some(completers::language),
+ },
+ TypableCommand {
name: "set-option",
aliases: &["set"],
doc: "Set a config option at runtime",