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

Format out of process #1845

Merged
merged 28 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9ea1b4c
Style guide lambda (#1858)
nojaf Sep 7, 2021
e28a40f
WIP Daemon service contract.
nojaf Jul 20, 2021
b879731
Early working daemon prototype.
nojaf Jul 24, 2021
2ca2ae2
Take .editorconfig settings into account.
nojaf Jul 24, 2021
97dbe5c
Fix current build.
nojaf Jul 25, 2021
a479538
Add Fantomas locator.
nojaf Jul 25, 2021
47d91c8
Found globally installed Fantomas version.
nojaf Jul 26, 2021
881246a
Remove unused function.
nojaf Jul 26, 2021
e557269
Add formatSelection.
nojaf Jul 27, 2021
2e47356
Refactor FormatDocumentResponse to DU.
nojaf Jul 31, 2021
0da1708
Remove unused LspTypes dependency.
nojaf Aug 2, 2021
25afe3f
Update FCS in Daemon
nojaf Sep 10, 2021
d9c7c57
Refactored public api of FantomasService.
nojaf Oct 8, 2021
1144779
Don't pass full exception in FormatDocumentResponse.
nojaf Oct 13, 2021
aba545d
Use separate versioning for Fantomas.Client.
nojaf Oct 13, 2021
37cf203
FantomasService manages multiple daemon versions.
nojaf Oct 14, 2021
ed7f5fe
Fully implement FantomasService.
nojaf Oct 15, 2021
fb56efe
Return configuration as json.
nojaf Oct 15, 2021
d93725d
Validate if filePath in request is absolute.
nojaf Oct 15, 2021
81a5956
Ignore first three 4.6 alphas as compatible tools.
nojaf Oct 17, 2021
3dda8a3
Find ignore file from current file path.
nojaf Oct 18, 2021
ccdd585
Remove safeFileName from CodeFormatterImpl.fs.
nojaf Oct 18, 2021
2a7837f
Add daemon unit tests.
nojaf Oct 19, 2021
ed04614
Update help text for daemon mode.
nojaf Oct 20, 2021
85cd808
Add documentation for Fantomas daemon mode.
nojaf Oct 20, 2021
cf31b36
Initial attempt at adding source links.
nojaf Oct 20, 2021
ba2fef9
Set DebugType to embedded.
nojaf Oct 20, 2021
298847e
Bump Fantomas.Client to 0.3.0
nojaf Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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