Repository navigation
Add support for formatting from stdin - #4681
Merged
Merged
Conversation
| stdinFilePathFlagName, | ||
| ) | ||
| } | ||
| data, err := io.ReadAll(container.Stdin()) |
Contributor
There was a problem hiding this comment.
Should there be some sort of limit on this? https://pkg.go.dev/io#LimitReader
Contributor
There was a problem hiding this comment.
io.ReadAll matches the current file behavior. Don't think theres a reasonable limit to apply.
| if err != nil { | ||
| return err | ||
| } | ||
| diffBuffer := bytes.NewBuffer(nil) |
Contributor
There was a problem hiding this comment.
When creating an initially empty buffer, usually var diffBuffer bytes.Buffer is used, and then you use &diffBuffer.
Contributor
There was a problem hiding this comment.
diffBuffer := bytes.NewBuffer(nil) matches the current file.
emcfarlane
approved these changes
Sep 15, 2026
| stdinFilePathFlagName, | ||
| ) | ||
| } | ||
| data, err := io.ReadAll(container.Stdin()) |
Contributor
There was a problem hiding this comment.
io.ReadAll matches the current file behavior. Don't think theres a reasonable limit to apply.
| if err != nil { | ||
| return err | ||
| } | ||
| diffBuffer := bytes.NewBuffer(nil) |
Contributor
There was a problem hiding this comment.
diffBuffer := bytes.NewBuffer(nil) matches the current file.
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the
--stdin-filepathflag which when set, indicates a filepath to use to identify input passed via stdin instead. One use case is simple editor integration, though I suspect since the issue was filed LSP integration on both sides may have improved enough that this is less of an issue. Another still important one is integration with meta formatters, the Gradle spotless plugin in the linked issue invokes other formatters and unfortunately needs to prepare a temp file only for protos, and rumdl also rejected the tempfile approach for formatting protos within markdown files. With this change, we can eventually have formatting of proto in markdown files which is pretty great for docs pages.There are various names for a similar flag in many formatters,
--filenameetc. I went with this one only because it matches Zed's docs which feels like a neutral third party.Fixes #1035
/cc @stefanvanburen