Skip to content

Commit

Permalink
feat: rebase Vladimir's pr
Browse files Browse the repository at this point in the history
  • Loading branch information
kamadorueda committed Nov 24, 2024
1 parent e2c843c commit 9828d43
Show file tree
Hide file tree
Showing 47 changed files with 35 additions and 6,416 deletions.
11 changes: 8 additions & 3 deletions src/alejandra/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::config::Config;
use crate::config::Indentation;

#[derive(PartialEq)]
pub(crate) enum Step {
Expand All @@ -15,14 +16,13 @@ pub(crate) enum Step {

#[derive(Clone)]
pub(crate) struct BuildCtx {
pub _config: Config,
pub config: Config,
pub force_wide: bool,
pub force_wide_success: bool,
pub indentation: usize,
pub pos_old: crate::position::Position,
pub path: String,
pub vertical: bool,
pub indent: String,
}

pub(crate) fn build(
Expand Down Expand Up @@ -100,7 +100,12 @@ fn build_step(
add_token(
builder,
rnix::SyntaxKind::TOKEN_WHITESPACE,
&build_ctx.indent.repeat(build_ctx.indentation),
&match build_ctx.config.indentation {
Indentation::FourSpaces => " ",
Indentation::Tabs => "\t",
Indentation::TwoSpaces => " ",
}
.repeat(build_ctx.indentation),
);
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/alejandra/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@ use serde::Deserialize;

/// Configuration used by the formatter
#[derive(Clone, Copy, Default, Deserialize)]
pub struct Config {}
pub struct Config {
/// Indentation to use
pub indentation: Indentation,
}

#[derive(Clone, Copy, Default, Deserialize)]
/// Indentation options
pub enum Indentation {
/// Four spaces
FourSpaces,
/// Tabs
Tabs,
#[default]
/// Two spaces
TwoSpaces,
}
3 changes: 1 addition & 2 deletions src/alejandra/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ pub fn in_memory(
}

let mut build_ctx = crate::builder::BuildCtx {
_config: config,
config,
force_wide: false,
force_wide_success: true,
indentation: 0,
path,
pos_old: crate::position::Position::default(),
vertical: true,
indent,
};

let after = crate::builder::build(&mut build_ctx, ast.node().into())
Expand Down
112 changes: 0 additions & 112 deletions src/alejandra/tests/cases/apply/out.nix

This file was deleted.

44 changes: 0 additions & 44 deletions src/alejandra/tests/cases/assert/out.nix

This file was deleted.

138 changes: 0 additions & 138 deletions src/alejandra/tests/cases/attr_set/out.nix

This file was deleted.

Loading

0 comments on commit 9828d43

Please sign in to comment.