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

Allow setting input file when reading from STDIN #82

Closed
wants to merge 1 commit into from

Conversation

tfausak
Copy link

@tfausak tfausak commented Jul 27, 2023

Fixes #51. Alternative to #65.

This adds a new --stdin-input-file FILE command-line option. It is intended to be used when reading a Cabal file from STDIN. The given FILE will be used to resolve relative references, which allows pragmas like -- cabal-fmt: expand some-directory to work even when reading from STDIN.

I borrowed the flag name from Ormolu. I'm not set on it — if there's a better name, let's change it.

Like #65, this does not let you set both --stdin-input-file and an actual input file. In other words, cabal-fmt --stdin-input-file x y is an error, even if x and y happen to be the same.

I think this is preferable to #65 because it should be easier to integrate with tools. It's very common to have the file path of the file you want to format, along with the file's contents in memory. Requiring a directory name would require calling something like dirname, which is just an extra unnecessary step.

@michaelpj
Copy link

Just to note that this is a problem for the HLS cabal-fmt plugin, which needs to call cabal-fmt with the contents of the file as they appear in the user's editor, not on disk. So we rely on the option to read from stdin.

@tfausak
Copy link
Author

tfausak commented Aug 28, 2023

@phadej can you review this when you get a chance? Thanks!

@tfausak
Copy link
Author

tfausak commented Jan 22, 2024

Is there anything that I can do to help move this along? This feature would allow me to replace hpack with cabal-fmt. It would also fix a problem with HLS.

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.

supply path to expand src when using stdin
2 participants