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

More multiline, and some comment support #7695

Merged
merged 3 commits into from
Mar 28, 2025

Conversation

gamebox
Copy link
Collaborator

@gamebox gamebox commented Mar 12, 2025

This is ready to merge!

Copy link
Collaborator

@lukewilliamboswell lukewilliamboswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looking good. I don't have any significant comments.

};
if (comment) |c| {
token.offset = c.begin;
token.extra = .{ .length = if (c.end > c.begin) c.end - c.begin else 0 };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would end ever be less than begin?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@@ -435,9 +449,15 @@ pub const Cursor = struct {
}
} else if (b == '#') {
self.pos += 1;
const comment_start = self.pos;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather make this part of the return value (eg in a struct) than stuff this in a field on self

Copy link
Collaborator Author

@gamebox gamebox Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of removing the u16 for the indent completely - since it's no longer used (or needed).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me!

if (self.cursor.chompTrivia()) |indent| {
self.output.pushNewline(indent);
if (self.cursor.chompTrivia()) |_| {
self.output.pushNewline(self.cursor.popComment());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify this, newlines instead of store the indent now store the index to any comments that appear between lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They store the start and endposition

src/fmt.zig Outdated
fmt.push(braces.end());
}

fn formatExpr(fmt: *Formatter, ei: ExprIdx) IR.Region {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the returned region is almost always ignored. What is it actually needed/used for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used by formatCollection to flush comments and newlines (normalized) between the items

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See fmt.zig:212 above

joshuawarner32
joshuawarner32 previously approved these changes Mar 27, 2025
Copy link
Collaborator

@joshuawarner32 joshuawarner32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I think there are some merge conflicts that need to be resolved first tho.

@joshuawarner32 joshuawarner32 merged commit 837e021 into roc-lang:main Mar 28, 2025
18 checks passed
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.

4 participants