Skip to content

Commit

Permalink
Format out of process (#1845)
Browse files Browse the repository at this point in the history
* Style guide lambda (#1858)

* WIP lambda as last argument

* Update remaining test according to style proposal.

* Add test for multiline non lambda argument.

* Print trivia for function keyword from ast range.

* multiline non lambda argument, match lambda

* WIP Daemon service contract.

* Early working daemon prototype.

* Take .editorconfig settings into account.

* Fix current build.

* Add Fantomas locator.

* Found globally installed Fantomas version.

* Remove unused function.

* Add formatSelection.

* Refactor FormatDocumentResponse to DU.

* Remove unused LspTypes dependency.

* Update FCS in Daemon

* Refactored public api of FantomasService.

* Don't pass full exception in FormatDocumentResponse.

* Use separate versioning for Fantomas.Client.

* FantomasService manages multiple daemon versions.

* Fully implement FantomasService.

* Return configuration as json.

* Validate if filePath in request is absolute.

* Ignore first three 4.6 alphas as compatible tools.

* Find ignore file from current file path.

* Remove safeFileName from CodeFormatterImpl.fs.
Disable daemon tests.

* Add daemon unit tests.

* Update help text for daemon mode.

* Add documentation for Fantomas daemon mode.

* Initial attempt at adding source links.

* Set DebugType to embedded.

* Bump Fantomas.Client to 0.3.0
  • Loading branch information
nojaf committed Dec 29, 2021
1 parent 9215038 commit 4545c9d
Show file tree
Hide file tree
Showing 34 changed files with 2,635 additions and 488 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### 4.6.0-alpha-004

* Initial Fantomas.Client release.

#### 4.6.0-alpha-003

* Fix Update record should indent from the curly brace instead of the identifier. [#1876](https://github.com/fsprojects/fantomas/issues/1876)
Expand Down
26 changes: 21 additions & 5 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ let owner = "Anh-Dung Phan"
let tags =
"F# fsharp formatting beautifier indentation indenter"

let fantomasClientVersion = "0.3.0"

// (<solutionFile>.sln is built during the building process)
let solutionFile = "fantomas"
//// Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
Expand Down Expand Up @@ -168,7 +170,9 @@ Target.create
"src/Fantomas/bin"
"src/Fantomas/obj"
"src/Fantomas.CoreGlobalTool/bin"
"src/Fantomas.CoreGlobalTool/obj" ]
"src/Fantomas.CoreGlobalTool/obj"
"src/Fantomas.Client/bin"
"src/Fantomas.Client/obj" ]
|> List.iter Shell.cleanDir)

Target.create
Expand All @@ -180,13 +184,20 @@ Target.create
let file =
sprintf "src/%s/%s.fsproj" project project

Xml.poke file "Project/PropertyGroup/Version/text()" version
Xml.poke
file
"Project/PropertyGroup/Version/text()"
(if project = "Fantomas.Client" then
fantomasClientVersion
else
version)

setProjectVersion "Fantomas"
setProjectVersion "Fantomas.CoreGlobalTool"
setProjectVersion "Fantomas.CoreGlobalTool.Tests"
setProjectVersion "Fantomas.Tests"
setProjectVersion "Fantomas.Extras")
setProjectVersion "Fantomas.Extras"
setProjectVersion "Fantomas.Client")

// --------------------------------------------------------------------------------------
// Build library & test project
Expand Down Expand Up @@ -241,7 +252,11 @@ Target.create
{ defaultArgs with
Properties =
[ "Title", project
"PackageVersion", nugetVersion
"PackageVersion",
(if project = "Fantomas.Client" then
fantomasClientVersion
else
nugetVersion)
"Authors", (String.Join(" ", authors))
"Owners", owner
"PackageRequireLicenseAcceptance", "false"
Expand All @@ -263,7 +278,8 @@ Target.create

pack "Fantomas"
pack "Fantomas.Extras"
pack "Fantomas.CoreGlobalTool")
pack "Fantomas.CoreGlobalTool"
pack "Fantomas.Client")

// This takes the list of external projects defined above, does a git checkout of the specified repo and tag,
// tries to build the project, then reformats with fantomas and tries to build the project again. If this fails
Expand Down
24 changes: 24 additions & 0 deletions docs/Daemon mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Fantomas Daemon mode

## Introduction

As part of the `4.6` release, we've introduced a new feature where end-user can control the version of Fantomas that is being used inside an IDE.
In previous iterations, the editor tooling would typically reference the [Fantomas](https://www.nuget.org/packages/Fantomas) or [Fantomas.Extras](https://www.nuget.org/packages/Fantomas.Extras) nuget package and use the [CodeFormatter](../src/Fantomas/CodeFormatter.fsi) api to handle formatting.
The major drawback of this approach is that shared [FCS](https://www.nuget.org/packages/FSharp.Compiler.Service/) dependency needed to be exactly the same.
So the editor is in control of which version of Fantomas is being used.
Each version of Fantomas theoretically can have a different outcome as the style guides may have changed over time.

## Solution

To tackle this problem, we introduce two new concepts: `--daemon` mode for the [fantomas-tool](https://www.nuget.org/packages/fantomas-tool) and [Fantomas.Client](https://www.nuget.org/packages/Fantomas.Client).
`--daemon` would launch the commandline application as a sort of [LSP server](https://microsoft.github.io/language-server-protocol/) and `Fantomas.Client` could connect to this and proxy format requests.
Editor tooling would be able to launch your pinned version of `fantomas-tool` as a daemon service and interact with it outside-of-process.

## End-user impact

End-users don't have to worry about `Fantomas.Client` or the `--daemon` flag. They only need to install a compatible version of `fantomas-tool`.
Be it locally or globally. The first compatible version is `4.6.0-alpha-004`, all higher version should work as well.
Local versions have precedence over the global version.

The nice thing about this approach is that you can upgrade Fantomas at your own pace.
When new versions drop, you can dedicate a separate commit in source control and it won't interfere with your other commits.
9 changes: 7 additions & 2 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For the overview how to use the tool, you can type the command
dotnet fantomas --help

```
USAGE: dotnet fantomas [--help] [--recurse] [--force] [--profile] [--fsi <string>] [--stdin] [--stdout] [--out <string>] [--check] [--version] [<string>...]
USAGE: dotnet fantomas [--help] [--recurse] [--force] [--profile] [--fsi <string>] [--stdin] [--stdout] [--out <string>] [--check] [--daemon] [--version] [<string>...]
INPUT:
Expand All @@ -31,9 +31,10 @@ OPTIONS:
--profile Print performance profiling information.
--fsi <string> Read F# source from stdin as F# signatures.
--stdin Read F# source from standard input.
--stdout Write the formatted source code to standard output.
--stdout Write the formatted source code to standard output.
--out <string> Give a valid path for files/folders. Files should have .fs, .fsx, .fsi, .ml or .mli extension only.
--check Don't format files, just check if they have changed. Exits with 0 if it's formatted correctly, with 1 if some files need formatting and 99 if there was an internal error
--daemon Daemon mode, launches an LSP-like server to can be used by editor tooling.
--version, -v Displays the version of Fantomas
--help display this list of options.
Expand Down Expand Up @@ -80,6 +81,10 @@ Or usage with `find` on unix:

`find my-project/ -type f -name "*.fs" -not -path "*obj*" | xargs dotnet fantomas --check`

### Daemon mode

`--daemon` should not be used directly by end-users. Learn more about this feature in the [Daemon mode documentation](./Daemon%20mode.md)

## Configuration

Fantomas ships with a series of format options.
Expand Down
14 changes: 14 additions & 0 deletions fantomas.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Benchmarks", "src\
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Extras", "src\Fantomas.Extras\Fantomas.Extras.fsproj", "{4088FF76-1DB7-4E68-80FE-E851CE6701AC}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Client", "src\Fantomas.Client\Fantomas.Client.fsproj", "{AA895F94-CCF2-4FCF-A9BB-E16987B57535}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -105,6 +107,18 @@ Global
{4088FF76-1DB7-4E68-80FE-E851CE6701AC}.Release|x64.Build.0 = Release|Any CPU
{4088FF76-1DB7-4E68-80FE-E851CE6701AC}.Release|x86.ActiveCfg = Release|Any CPU
{4088FF76-1DB7-4E68-80FE-E851CE6701AC}.Release|x86.Build.0 = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Debug|x64.ActiveCfg = Debug|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Debug|x64.Build.0 = Debug|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Debug|x86.ActiveCfg = Debug|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Debug|x86.Build.0 = Debug|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|Any CPU.Build.0 = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|x64.ActiveCfg = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|x64.Build.0 = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|x86.ActiveCfg = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
Expand Down
22 changes: 21 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ nuget Argu
nuget BenchmarkDotNet
nuget editorconfig
nuget MAB.DotIgnore 3.0.2
nuget Microsoft.SourceLink.GitHub copy_local: true

github: fsprojects/fantomas:829faa6ba834f99afed9b4434b3a1680536474b2 src/Fantomas/CodePrinter.fs

Expand All @@ -23,11 +24,30 @@ group build
source https://api.nuget.org/v3/index.json

nuget Microsoft.Azure.Cosmos.Table
nuget FSharp.Core ~> 5
nuget Fake.Core.ReleaseNotes
nuget Fake.Core.Xml
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Paket
nuget Fake.Tools.Git
nuget Fake.Core.Process
nuget Fake.Core.Target
nuget MSBuild.StructuredLogger 2.1.500
nuget MSBuild.StructuredLogger 2.1.500

group tool
storage: none
source https://api.nuget.org/v3/index.json

nuget FSharp.Core 5.0.3-beta.21352.5
nuget Argu
nuget StreamJsonRpc
nuget Thoth.Json.Net
nuget SerilogTraceListener

group client
storage: none
source https://api.nuget.org/v3/index.json

nuget FSharp.Core 5
nuget StreamJsonRpc
nuget Microsoft.SourceLink.GitHub copy_local: true
Loading

0 comments on commit 4545c9d

Please sign in to comment.