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

Adds duplicated placeholder code for second iteration of Cypher formatter #353

Open
wants to merge 56 commits into
base: main
Choose a base branch
from

Conversation

tomasnyberg
Copy link
Contributor

Description

This introduces the first draft of the second iteration of the cypher formatter, intended to be able to handle line breaks in a reasonably good way. The PR does not change any of the existing files, and instead creates new files with a "v2" extension that are copies of the old files, with new changes introduced. This is done because of the following reasons:

  1. It's hard to consolidate the v2 version with the existing code without changing existing functionality
  2. The new version gives very different outputs in cases where line breaks are needed, and that output is not necessarily production ready yet
  3. We want to be able to iteratively release updates for this new iteration instead of introducing everything at once

Given that the files are fully copied, the easiest way to review is probably to check this out locally and open a diff view in your editor of choice, e.g.

nvim -d formatting.ts formattingv2.ts

since otherwise everything will look like a change.

Changes (v2 compared to v1)

This PR introduces significant architectural changes to the formatter, since that is necessary for the line break logic. Much of it is inspired by this blog post

  • Instead of visiting and adding tokens directly to our output, we now consolidate (possibly multiple) tokens into Chunks
    • This comes with quite a few changes in formatting.ts since spaces between tokens is now encoded differently. For instance, we now avoid spaces where needed instead of explicitly adding them when needed
  • formattingHelpers introduces ~10 new constructs to help with the best first graph search and constructing the output
  • formattingHelpers introduces ~6 new methods for turning the lists of chunks into the formatted output through the graph search
    A simplified overview of the flow from source code to formatted source code would be something like this:

image

Testing

  • All the old formatting tests pass (except for one, commented out with a TODO since it will require some architectural changes to get right)
    • The tests are copied over to a v2 test file as well to ensure it's formatted by the new version
  • Ten new queries that have lines that go beyond the max width of 80, and a test that verifies that linebreaks keep them within the max width

Copy link

changeset-bot bot commented Feb 10, 2025

⚠️ No Changeset found

Latest commit: 24f5761

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ncordon ncordon self-assigned this Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants