-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Add FormatASTRangeAsync to API. #454
Comments
Ok, should we not also capture the original source for trivia parsing? |
This contains also original source code. Idea of this method is "format this selection of this code and here you have its AST so you don't have to create it". |
My bad, didn't see the |
Also, |
Hmm, good question. When So, I guess |
My thoughts exactly, perhaps we should add the defines explicit as a parameter. |
In order for both Rider and FSAutoComplete to format the code I believe two key questions are relevant:
If the file does not have any dead code, we should be able to re-use the untyped AST and collect the trivia from the source text. At this point, I assume the editor knows that there is dead code or not and calls Fantomas one way or the other based on this information. In the scenario where there is no dead code and we currently don't have any option to format a range based on AST. So the title of this topic still seems relevant. Any thoughts or concerns at this point? @jindraivanek @auduchinok @Krzysztof-Cieslak |
@nojaf No objections from me as everything is how we've discussed it. :) |
@nojaf Thanks for great summary. I think question is if there is some notable perf win in re-use AST vs. re-use of Checker. Is this worth the effort? |
As I recall from our conversation with @Krzysztof-Cieslak , having the re-use of the Checker would be beneficial. In the current (2.X) api when you are using the overload where no checker is passed on to Fantomas, it will use its own checker so I believe we want to avoid that. Unfortunately I can't say anything more relevant than "believe" here. As for the re-use of AST, are we certain that the AST is always in sync the latest keystrokes of the user? |
Yes. My question is if re-use of AST would be significantly more beneficial than re-use of Checker.
Well, this has advantage when Fantomas is used as library, its checker is reused, so consecutive calls are faster.
That would be responsibility of user of this API. |
In case of FSAC, yes, for the (untyped) AST in current file we are always in sync with latest keystroke.
I think the value of reusing Checker is the fact that you can handle the logic regarding multiple-parsing yourself. As far as I remember you've mentioned you may need multiple AST from single file (in case of #if etc) - in FSAC we only track single AST (for current defines) for the file. It would be nice if we don't have to re implement this logic in every client ;-) |
I could be wrong but if we re-use the checker it might be ok to parse the AST again anyway as it looks like it is cached internally. |
This is exactly where my question was aiming :) But maybe we want to do some benchmark to be sure. |
I think this can be closed now, we can always discuss if anything new should be added to the public API. |
https://twitter.com/k_cieslak/status/1156219821387931650
Suggested type:
ast:ParsedInput * fileName:string * selection:range * source:SourceOrigin * config:FormatConfig * projectOptions:FSharpParsingOptions * checker:FSharpChecker -> Async<string>
Why? Parsing source code to AST is expensive, we can avoid it by sharing AST.
I think we can do it by use
formatWith
here https://github.com/fsprojects/fantomas/blob/trivia/src/Fantomas/CodeFormatterImpl.fs#L594 with AST node covering selection range.The text was updated successfully, but these errors were encountered: