-
Notifications
You must be signed in to change notification settings - Fork 156
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
Use Fantomas client instead of direct embedding #836
Conversation
src/FsAutoComplete.Core/Commands.fs
Outdated
let! fantomasResponse = service.FormatDocumentAsync { SourceCode = currentCode; FilePath = (UMX.untag file); IsLastFile = false; Config = None } | ||
match fantomasResponse with | ||
| { Code = 1; Content = Some code } -> | ||
fantomasLogger.info (Log.setMessage (sprintf "Fantomas daemon was able to format \"%A\"" file)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are those logs written to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these logs are written to serilog eventually, which is configured in the Program.fs. the default outputs are to write all logs to stderror, because LSP communication is done over the main stdin/stdout channels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea how to view these in Rider when attaching to an existing project? Or is it easy to have them written to a rolling file thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, you should be able to add a rolling file appender to the logger configuration here, though you will need to add the Serilog.Sinks.File package in order to do so. It would be excellent if you also hooked the configuration of this file up to a CLI option (perhaps --log-file <filepath>
?)
Alright, this is getting in a workable state I think. Let me know what you think. |
Oh and we probably want to have some basic tests for this I imagine. |
re: tests I think the current project-based test case model could work here, because you can do local-tool installs to those folders to test specific scenarios. so you'd make a folder representing a project, install fantomas as a local tool, then verify that formatting worked. separately another folder could test the case where we install fantomas for the user, etc, etc. |
re:re:tests ah good to hear, then we can indeed have a real test in place. |
@baronfel again, some good stuff today. Man this is a tricky thing to nail down 😋 |
Hey again @baronfel, getting pretty happy where this sits right now. |
paket.dependencies
Outdated
@@ -6,12 +6,13 @@ source https://api.nuget.org/v3/index.json | |||
# this is the FCS nightly feed, re-enable at your own risk! | |||
#source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json | |||
#source: ./libs | |||
source C:\Users\fverdonck\Projects\fantomas\bin\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just making a note, we'd want to remove this before final merge
@@ -176,15 +176,13 @@ type FSharpLspServer(backgroundServiceEnabled: bool, state: State, lspClient: FS | |||
let logger = LogProvider.getLoggerByName "LSP" | |||
let fantomasLogger = LogProvider.getLoggerByName "Fantomas" | |||
let backgroundService: BackgroundServices.BackgroundService = if backgroundServiceEnabled then BackgroundServices.ActualBackgroundService() :> _ else BackgroundServices.MockBackgroundService() :> _ | |||
let mutable commands = new Commands(FSharpCompilerServiceChecker(backgroundServiceEnabled, false), state, backgroundService, false) | |||
let mutable rootPath : string option = None | |||
let mutable commands = new Commands(FSharpCompilerServiceChecker(backgroundServiceEnabled, false), state, backgroundService, false, rootPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is beginning to smell to me. not your code, but just how large Commands is getting.
I'm really happy with this overall, and really excited for the UX of this change, as well as how it insulates the core of FSAC from changes in Fantomas while enabling users to manage fantomas versions independently! |
let dotConfigContent = File.ReadAllText dotConfig | ||
if dotConfigContent.Contains("fantomas-tool") then | ||
// uninstall a older, non-compatible version of fantomas-tool | ||
Process.Start("dotnet", @"tool uninstall fantomas-tool").WaitForExit(5000) |> ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any objection to bringing in https://github.com/Tyrrrz/CliWrap?
As Process.Start
can now fail silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, go on ahead!
@baronfel I think the only thing missing here is some sort of unit/integration test. |
The test passed on Windows as well. |
Merged! Thank you for this wonderful contribution, I'm very excited to get it out to our users! |
You and me both buddy! Many thanks for all the mentoring along the way. |
🥳 Awesome work @nojaf, thanks a lot!. |
| Ok FormatDocumentResponse.UnChanged -> | ||
return LspResult.success None | ||
| Ok FormatDocumentResponse.ToolNotPresent -> | ||
let actions = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could all this logic be added to Fantomas.Client? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all LSP-specific responses/API usage here, it's not really something that I would expect to drop seamlessly into, say, the VS API. The bit below about prompting especially would be editor-specific, I have zero idea what those interfaces look like.
Following up on fsprojects/fantomas#1845, I want to try out the new approach in FSAC/Ionide.
@baronfel I have some specific questions that I will ask in the code, but overall I'd like to hear your thoughts.
Are we on to something here you think?
PS: This worked on my local machine, that alpha-004 is not published yet.