@@ -888,10 +888,34 @@ mod cmd {
889 tokio::spawn(doc.save());
889 tokio::spawn(doc.save());
891 fn new_file(editor: &mut Editor, args: &[&str], event: PromptEvent) {
892 fn new_file(editor: &mut Editor, args: &[&str], event: PromptEvent) {
892 editor.new_file(Action::Replace);
893 editor.new_file(Action::Replace);
896+ fn format(editor: &mut Editor, args: &[&str], event: PromptEvent) {
897+ let (view, doc) = editor.current();
899+ if let Some(language_server) = doc.language_server() {
900+ // TODO: await, no blocking
901+ let transaction = helix_lsp::block_on(
903+ .text_document_formatting(doc.identifier(), lsp::FormattingOptions::default()),
906+ helix_lsp::util::generate_transaction_from_edits(
909+ language_server.offset_encoding(),
913+ if let Ok(transaction) = transaction {
914+ doc.apply(&transaction, view.id);
895 pub const COMMAND_LIST: &[Command] = &[
919 pub const COMMAND_LIST: &[Command] = &[
896 Command {
920 Command {
897 name: "quit",
921 name: "quit",
@@ -928,6 +952,13 @@ mod cmd {
928 fun: new_file,
952 fun: new_file,
929 completer: Some(completers::filename),
953 completer: Some(completers::filename),
958+ doc: "Format the file using a formatter.",
933 pub static COMMANDS: Lazy<HashMap<&'static str, &'static Command>> = Lazy::new(|| {
964 pub static COMMANDS: Lazy<HashMap<&'static str, &'static Command>> = Lazy::new(|| {