Add PrettyPrinter That Returns Both Errors & Text#351
Open
prikhi wants to merge 1 commit into
Open
Conversation
Add a new `pPrintText` function to the Brittany.Main module that behaves similarly to the `coreIO` function, but instead only take a config & input string & always returns a list of errors & either the unaltered or the pretty printed text. This new function will always check the generated text & ignores all tracing and printing to stdout. This a useful function for utility programs, like haskell-language-server, that want to feed text to brittany & manipulate the output.
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.
Hi! Currently
haskell-language-serverusesparsePrintModulein it's brittany plugin to format source code.This works well unless the source code causes brittany to throw warnings. See haskell/haskell-language-server#2005
I added a new
pPrintTextfunction theBrittany.Mainmodule, that emulates thecoreIOfunction but only relies on aConfigand the inputText, & returns the list of warnings/errors & either the original or formatted text.This is pretty hacky, lots of code is copy-pasted & trimmed down from the stuff in
coreIO. Not sure ifMainis the correct place for this, ifpPrintTextis a decent name for this, or if I should refactor a bit to reduce duplication. Feedback welcome & feel free to just toss this away and do it correctly 😉.It would be great if we could get a new release pushed after this sort of functionality is added - it'd mean we can bring back HLS auto-brittany-formatting to projects that heavily use constructs that cause brittany to raise warnings(like
TypeOperators).Commit message follows.
Add a new
pPrintTextfunction to the Brittany.Main module that behavessimilarly to the
coreIOfunction, but instead only take a config &input string & always returns a list of errors & either the unaltered or
the pretty printed text.
This new function will always check the generated text & ignores all
tracing and printing to stdout.
This a useful function for utility programs, like haskell-language-server,
that want to feed text to brittany & manipulate the output.