Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: format #133

Merged
merged 61 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
7f3a812
feat: introduces WDL format
a-frantz Jul 17, 2024
53b883e
tests: format framework (everything panics)
a-frantz Oct 4, 2024
030a3e2
fix(wdl-ast/element): typos in macro call
a-frantz Oct 4, 2024
067e89f
[WIP]
a-frantz Oct 4, 2024
03a0a6e
revise: `s/preceeding/preceding/g`
claymcleod Oct 4, 2024
0064569
revise: updates default indent size
claymcleod Oct 4, 2024
bd0591f
[WIP]revise: rework trivia
a-frantz Oct 5, 2024
fd4da2e
[WIP]revise: trivia rework
a-frantz Oct 5, 2024
e128913
chore: cargo fmt
a-frantz Oct 6, 2024
cb86d0b
[WIP]
a-frantz Oct 6, 2024
c8ac499
[WIP]
a-frantz Oct 7, 2024
63a4eb2
[WIP]
a-frantz Oct 7, 2024
acf0f15
[WIP]
a-frantz Oct 7, 2024
d97580f
[WIP]
a-frantz Oct 8, 2024
343353a
[WIP] tests: seaseq case formats
a-frantz Oct 9, 2024
2cef6f8
[WIP]tests: format each current test
a-frantz Oct 10, 2024
23331da
fix: escape quotes when writing strings
a-frantz Oct 10, 2024
94aa668
feat: all elements in the tree are formatted
a-frantz Oct 10, 2024
fd4b145
fix: don't line split empty arrays
a-frantz Oct 10, 2024
1e66dd0
revise: reorganize format functions
a-frantz Oct 10, 2024
1aee371
feat: line split if/then/else exprs
a-frantz Oct 11, 2024
6f35e56
revise: rename BlankLinesContext
a-frantz Oct 11, 2024
58eeff3
feat: implement LineSpacingPolicy
a-frantz Oct 11, 2024
d2d699f
revise: simplify blank line logic
a-frantz Oct 11, 2024
ea53d1b
Merge branch 'main' into feat/format
a-frantz Oct 11, 2024
502fca0
chore: cleanup after merge
a-frantz Oct 11, 2024
5696b29
revise(LineSpacingPolicy): BetweenComments->BeforeComments
a-frantz Oct 11, 2024
c5581ea
Update Gauntlet.toml
a-frantz Oct 11, 2024
7e1bfa4
chore: rm backup/
a-frantz Oct 11, 2024
72d9238
revise: change how if elses are handled
a-frantz Oct 11, 2024
f2b5453
Update expr.rs
a-frantz Oct 12, 2024
3aed4cf
revise: don't line split empty meta items
a-frantz Oct 12, 2024
9911f52
feat: AssertConsumedIter
a-frantz Oct 12, 2024
83b4757
tests: test for unconsumed children
a-frantz Oct 12, 2024
9f46bd4
chore: cleanup
a-frantz Oct 14, 2024
2cf5814
docs: add docstrings
a-frantz Oct 14, 2024
ba3d0fe
chore: rm wdl-config
a-frantz Oct 14, 2024
9f80c4a
chore: clean up tree.rs
a-frantz Oct 14, 2024
7b5faf8
Update stdlib.rs
a-frantz Oct 14, 2024
fe317be
Update Gauntlet.toml
a-frantz Oct 14, 2024
a89b3ee
fix: don't reference TaskHints in workflow sections
a-frantz Oct 14, 2024
34ddab3
docs: CHANGELOG updates
a-frantz Oct 14, 2024
68a6b1c
Delete engine.rs
a-frantz Oct 14, 2024
de61347
Apply suggestions from code review
a-frantz Oct 14, 2024
a758c8a
chore: cargo fmt
a-frantz Oct 14, 2024
f7cfedc
chore: revert placeholder changes
a-frantz Oct 14, 2024
bf631d8
chore: revert bad hints changes
a-frantz Oct 14, 2024
df4f263
Update v1.rs
a-frantz Oct 14, 2024
7ddb8a7
chore: cleanup
a-frantz Oct 14, 2024
35aed7e
Update main.rs
a-frantz Oct 14, 2024
31bd09a
Update Gauntlet.toml
a-frantz Oct 14, 2024
c8f3770
tests: move registry.rs to tests/
a-frantz Oct 14, 2024
a6ef511
Update registry.rs
a-frantz Oct 14, 2024
e77afde
tests: reconfigure
a-frantz Oct 14, 2024
160dc8b
feat: use config for indents
a-frantz Oct 14, 2024
af1462a
revise: code review feedback
a-frantz Oct 15, 2024
d6aff8b
Apply suggestions from code review
a-frantz Oct 15, 2024
84090d9
chore: code review feedback
a-frantz Oct 15, 2024
68b70b8
chore: cargo fmt
a-frantz Oct 15, 2024
3cbf60b
fix: display for Token
a-frantz Oct 15, 2024
286602d
Update post.rs
a-frantz Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update nightly && rustup default nightly
- name: Install rustfmt
Expand All @@ -20,7 +20,7 @@ jobs:
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- name: Install clippy
Expand All @@ -30,53 +30,62 @@ jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo test --all-features

test-examples:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo test --all-features --examples

docs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo doc

gauntlet:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo run --release --bin gauntlet

arena:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo run --release --bin gauntlet -- --arena

workspace-lints-enabled:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo install cargo-workspace-lints --locked
- run: cargo workspace-lints

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- name: Install cargo-binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Install cargo-msrv
run: cargo binstall -y --version 0.16.0-beta.23 cargo-msrv
- name: Verify the MSRV
working-directory: ./wdl
run: cargo msrv verify --output-format minimal --all-features
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- name: Install cargo-binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Install cargo-msrv
run: cargo binstall -y --version 0.16.0-beta.23 cargo-msrv
- name: Verify the MSRV
working-directory: ./wdl
run: cargo msrv verify --output-format minimal --all-features
70 changes: 44 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[workspace]
members = [ "ci",
members = [
"ci",
"gauntlet",
"wdl",
"wdl-analysis",
"wdl-ast",
"gauntlet",
"wdl-format",
"wdl-grammar",
"wdl-lint",
"wdl-lsp",
Expand All @@ -19,40 +21,56 @@ repository = "https://github.com/stjude-rust-labs/wdl"
rust-version = "1.80.0"

[workspace.dependencies]
anyhow = "1.0.86"
approx = "0.5.1"
clap = { version = "4.5.7", features = ["derive"] }
clap-verbosity-flag = "2.2.1"
codespan-reporting = "0.11.1"
colored = "2.1.0"
convert_case = "0.6.0"
dirs = "5.0.1"
faster-hex = "0.9.0"
futures = "0.3.30"
git2 = "0.18.3"
id-arena = "2.2.1"
indexmap = { version = "2.2.6", features = ["serde"] }
indicatif = "0.17.8"
itertools = "0.13.0"
line-index = "0.1.1"
logos = "0.14.0"
nonempty = "0.10.0"
parking_lot = "0.12.3"
path-clean = "1.0.1"
petgraph = "0.6.5"
pretty_assertions = "1.4.0"
rayon = "1.10.0"
reqwest = "0.12.5"
rowan = "0.15.15"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.120"
serde_with = "3.8.1"
tempfile = "3.10.1"
tokio = { version = "1.38.0", features = ["full"] }
toml = "0.8.14"
tower-lsp = "0.20.0"
tracing = "0.1.40"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
logos = "0.14.0"
rowan = "0.15.15"
pretty_assertions = "1.4.0"
rayon = "1.10.0"
approx = "0.5.1"
codespan-reporting = "0.11.1"
anyhow = "1.0.86"
dirs = "5.0.1"
faster-hex = "0.9.0"
git2 = "0.18.3"
tempfile = "3.10.1"
url = "2.5.2"
urlencoding = "2.1.3"
parking_lot = "0.12.3"
reqwest = "0.12.5"
petgraph = "0.6.5"
futures = "0.3.30"
walkdir = "2.5.0"
path-clean = "1.0.1"
indicatif = "0.17.8"
tower-lsp = "0.20.0"
line-index = "0.1.1"
serde_json = "1.0.120"
uuid = "1.10.0"
id-arena = "2.2.1"
clap-verbosity-flag = "2.2.1"
tracing-log = "0.2.0"
walkdir = "2.5.0"

[workspace.lints.rust]
missing_docs = "warn"
nonstandard-style = "warn"
rust-2018-idioms = "warn"
rust-2021-compatibility = "warn"
rust-2024-compatibility = "warn"
edition_2024_expr_fragment_specifier = "allow"

[workspace.lints.rustdoc]
broken_intra_doc_links = "warn"

[workspace.lints.clippy]
missing_docs_in_private_items = "warn"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ cargo run --bin wdl --features cli -- $ARGS

Where `$ARGS` are the command line arguments to the `wdl` CLI tool.

The `wdl` CLI tool currently supports three subcommands:
The `wdl` CLI tool currently supports the following subcommands:

* `parse` - Parses a WDL document and prints both the parse diagnostics and the
resulting Concrete Syntax Tree (CST).
Expand All @@ -140,6 +140,8 @@ The `wdl` CLI tool currently supports three subcommands:
document scopes and exits with a status code of `0` if the documents are
valid; otherwise, prints the validation diagnostics and exits with a status
code of `1`.
* `format` - Parses, validates, and then formats a single WDL document, printing
the result to STDOUT.
adthrasher marked this conversation as resolved.
Show resolved Hide resolved

Each of the subcommands supports passing `-` as the file path to denote reading
from STDIN instead of a file on disk.
Expand Down
12 changes: 12 additions & 0 deletions backup/wdl-format-old-2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

* Added the `wdl-format` crate for formatting WDL documents ([#133](https://github.com/stjude-rust-labs/wdl/pull/133)).
28 changes: 28 additions & 0 deletions backup/wdl-format-old-2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "wdl-format"
version = "0.1.0"
license.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
anyhow.workspace = true
wdl-ast = { path = "../wdl-ast", version = "0.5.0" }
wdl-grammar = { version = "0.6.0", path = "../wdl-grammar" }

[dev-dependencies]
pretty_assertions = { workspace = true }
approx = { workspace = true }
rayon = { workspace = true }
colored = { workspace = true }
codespan-reporting = { workspace = true }

[features]
codespan = ["wdl-ast/codespan"]

[[test]]
name = "format"
required-features = ["codespan"]
harness = false
Empty file.
131 changes: 131 additions & 0 deletions backup/wdl-format-old-2/src/formatter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//! Contains the `Formatter` struct, which is used to keep track of the
//! current formatting state. This includes the current indentation level and
//! whether the current line has been interrupted by comments.
//! The state becomes "interrupted" by comments when a comment forces a newline
//! where it would otherwise not be expected. In this case, the next line(s)
//! will be indented by one level.

use crate::Formattable;
use crate::NEWLINE;

/// Space constant used for formatting.
pub const SPACE: &str = " ";
/// Indentation constant used for formatting. Indentation is four spaces
/// per-level.
pub const INDENT: &str = " ";
/// Inline comment space constant used for formatting.
///
/// Inline comments should start two spaces after the end of the element they
/// are commenting on.
pub const INLINE_COMMENT_SPACE: &str = " ";

/// The `Formatter` struct is used to keep track of the current formatting
/// state. This includes the current indentation level and whether the current
/// line has been interrupted by comments.
#[derive(Debug, Clone, Copy, Default)]
pub struct Formatter {
/// The current indentation level.
indent_level: usize,
/// Whether the current line has been interrupted by comments.
interrupted_by_comments: bool,
}

impl Formatter {
/// Format an element.
pub fn format<F: std::fmt::Write, T: Formattable>(
mut self,
element: &T,
writer: &mut F,
) -> std::fmt::Result {
element.format(writer, &mut self)
}

/// Add the current indentation to the writer.
/// The indentation level will be temporarily increased by one if the
/// current line has been interrupted by comments.
pub fn indent<T: std::fmt::Write>(&self, writer: &mut T) -> std::fmt::Result {
write!(
writer,
"{}",
INDENT.repeat(self.indent_level + (if self.interrupted_by_comments { 1 } else { 0 }))
)
}

/// Add a space or an indentation to the writer. If the current line has
/// been interrupted by comments, an indentation is added. Otherwise, a
/// space is added.
pub fn space_or_indent<T: std::fmt::Write>(&mut self, writer: &mut T) -> std::fmt::Result {
if !self.interrupted_by_comments {
write!(writer, "{}", SPACE)?;
} else {
self.indent(writer)?;
}
self.reset_interrupted();
Ok(())
}

/// Add a level of indentation.
pub fn increment_indent(&mut self) {
self.indent_level += 1;
self.reset_interrupted();
}

/// Remove a level of indentation.
pub fn decrement_indent(&mut self) {
self.indent_level = self.indent_level.saturating_sub(1);
self.reset_interrupted();
}

/// Check if the current line has been interrupted by comments.
pub fn interrupted(&self) -> bool {
self.interrupted_by_comments
}

/// Interrupt the current line with comments.
pub fn interrupt(&mut self) {
self.interrupted_by_comments = true;
}

/// Reset the interrupted state.
pub fn reset_interrupted(&mut self) {
self.interrupted_by_comments = false;
}

pub fn format_preceding_trivia<F: std::fmt::Write>(
&mut self,
writer: &mut F,
comments: Box<[String]>,
would_be_interrupting: bool,
respect_blank_lines: bool,
) -> std::fmt::Result {
if would_be_interrupting && !comments.is_empty() && !self.interrupted_by_comments {
write!(writer, "{}", NEWLINE)?;
self.interrupt();
}
for comment in comments {
if !respect_blank_lines && !comment.starts_with('#') {
continue;
}
self.indent(writer)?;
write!(writer, "{}{}", comment, NEWLINE)?;
}
Ok(())
}

pub fn format_inline_comment<F: std::fmt::Write>(
&mut self,
writer: &mut F,
comment: Option<String>,
would_be_interrupting: bool,
) -> std::fmt::Result {
if let Some(ref comment) = comment {
write!(writer, "{}{}{}", INLINE_COMMENT_SPACE, comment, NEWLINE)?;
}
if would_be_interrupting && comment.is_some() {
self.interrupt();
} else if !would_be_interrupting && comment.is_none() {
write!(writer, "{}", NEWLINE)?;
}
Ok(())
}
}
Loading