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

Formatter #371

Merged
merged 132 commits into from Mar 29, 2023
Merged

Formatter #371

merged 132 commits into from Mar 29, 2023

Conversation

JonasWanke
Copy link
Member

Changes in this PR:

  • performance improvements
  • show hints with multiline content as a single line
  • code cleanup
  • parser fixes
  • oh, and we now have a formatter

This is only a draft PR since I still have to add support for trailing sandwich-likes. But I wanted to give you a chance to catch up since this PR is leaning slightly towards the larger end.

After that, we only have to add support for formatting text (once we update the parser to the new text formatting) and integrate it in our language server and CLI.

I switched from producing a new CST and diffing that against the old one to computing and collecting text edits directly (in TextEdits) since it seemed simpler. (I don't have the full comparison since I didn't implement diffing, but at least the formatting code in ExistingWhitespace got simpler.) I also added a bit of documentation and there are many tests for the formatter (src/format.rs) as well as some for ExistingWhitespace.

Checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

hyperfine --warmup 1 "cargo run --release --manifest-path=compiler/cli/Cargo.toml -- run packages/examples/fibonacci.candy"

Before:
  Time (mean ± σ):      1.180 s ±  0.045 s    [User: 1.115 s, System: 0.067 s]
  Range (min … max):    1.092 s …  1.241 s    10 runs

After:
  Time (mean ± σ):      1.096 s ±  0.059 s    [User: 1.037 s, System: 0.061 s]
  Range (min … max):    0.981 s …  1.201 s    10 runs
compiler/formatter/src/width.rs Outdated Show resolved Hide resolved
compiler/formatter/src/format.rs Outdated Show resolved Hide resolved
compiler/formatter/src/text_edits.rs Show resolved Hide resolved
compiler/formatter/src/existing_whitespace.rs Outdated Show resolved Hide resolved
compiler/formatter/src/existing_whitespace.rs Outdated Show resolved Hide resolved
compiler/formatter/src/format.rs Outdated Show resolved Hide resolved
compiler/formatter/src/format.rs Outdated Show resolved Hide resolved
compiler/formatter/src/format.rs Outdated Show resolved Hide resolved
@jwbot jwbot added the P: Core Package: Candy's standard library label Mar 27, 2023
JonasWanke and others added 3 commits March 27, 2023 17:30
Co-authored-by: Marcel Garus <marcel.garus@gmail.com>
Co-authored-by: Marcel Garus <marcel.garus@gmail.com>
@JonasWanke JonasWanke marked this pull request as ready for review March 27, 2023 15:32
@JonasWanke JonasWanke merged commit 053d767 into main Mar 29, 2023
4 checks passed
@JonasWanke JonasWanke deleted the formatter branch March 29, 2023 15:03
@JonasWanke JonasWanke mentioned this pull request Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P: Compiler: CLI Package: Candy's command-line interface P: Compiler: Frontend Package: The compiler frontend P: Compiler: Fuzzer Package: Candy's built-in fuzzer fuzzing Candy code P: Compiler: Language Server Package: The Candy Language Server P: Compiler: VM Package: The VM executing Candy byte code (LIR) P: Compiler: VS Code Extension Package: The Candy VS Code Extension P: Core Package: Candy's standard library T: Feature Type: New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants