Skip to content

Commit e671f3d

Browse files
authored
V6.1 (#2913)
* Expose TransformAST api. (#2868) * Expose TransformAST api. * Add additional unit test. * Revert changelog entry * Add Changelog for 6.1 alpha 1 * Enrich transformed Oak. (#2869) * Add Changelog for 6.1 alpha 2 * Rename FSharp.Compiler to Fantomas.FCS (#2894) * Rename FSharp.Compiler to Fantomas.FCS * Add release notes for 6.1.0-alpha-003. * Update editorconfig package (#2895) * Use EditorConfigCache. * Clean up EditorConfig.fs(i) * Add 6.1.0-alpha-004 to changelog. * Add 6.1.0-alpha-005 to changelog. * Add 6.1.0-alpha-006 to changelog. * Add stable release
1 parent d1295a0 commit e671f3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+232
-119
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Changelog
22

3+
## 6.1.0 - 2023-06-27
4+
5+
Stable release
6+
7+
## 6.1.0-alpha-006 - 2023-06-20
8+
9+
Contains fixes of 6.0.8
10+
11+
## 6.1.0-alpha-005 - 2023-06-20
12+
13+
Contains fixes of 6.0.7
14+
15+
## 6.1.0-alpha-004 - 2023-06-19
16+
17+
Contains fixes of 6.0.6
18+
19+
## 6.1.0-alpha-003 - 2023-06-02
20+
21+
### Changed
22+
* Rename `namespace FSharp.Compiler` to `namespace Fantomas.FCS` for `Fantomas.FCS`. [#2894](https://github.com/fsprojects/fantomas/pull/2894)
23+
24+
## 6.1.0-alpha-002 - 2023-05-02
25+
26+
### Changed
27+
* Enrich transformed Oak. [#2869](https://github.com/fsprojects/fantomas/pull/2869)
28+
29+
## 6.1.0-alpha-001 - 2023-05-02
30+
31+
### Added
32+
* TransformAST in CodeFormatter. [#2868](https://github.com/fsprojects/fantomas/pull/2868)
33+
334
## [6.0.8] - 2023-06-20
435

536
### Fixed

build.fsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ let fsharpCompilerHash =
193193
let xDoc = XElement.Load(__SOURCE_DIRECTORY__ </> "Directory.Build.props")
194194
xDoc.XPathSelectElements("//FCSCommitHash") |> Seq.head |> (fun xe -> xe.Value)
195195

196+
let updateFileRaw (file: FileInfo) =
197+
let lines = File.ReadAllLines file.FullName
198+
let updatedLines =
199+
lines
200+
|> Array.map (fun line ->
201+
if line.Contains("FSharp.Compiler") then
202+
line.Replace("FSharp.Compiler", "Fantomas.FCS")
203+
else
204+
line)
205+
File.WriteAllLines(file.FullName, updatedLines)
206+
196207
let downloadCompilerFile commitHash relativePath =
197208
async {
198209
let file = FileInfo(deps </> commitHash </> relativePath)
@@ -213,6 +224,8 @@ let downloadCompilerFile commitHash relativePath =
213224
printfn $"Could not download %s{relativePath}"
214225
do! Async.AwaitTask(response.ResponseStream.CopyToAsync(fs))
215226
fs.Close()
227+
228+
updateFileRaw file
216229
}
217230

218231
pipeline "Init" {

docs/docs/end-users/GeneratingCode.fsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ To illustrate the API, lets generate a simple value binding: `let a = 0`.
3333
*)
3434

3535
#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.FCS.dll"
36-
#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.Core.dll" // In production use #r "nuget: Fantomas.Core, 6.0-alpha-*"
36+
#r "../../../src/Fantomas/bin/Release/net6.0/Fantomas.Core.dll" // In production use #r "nuget: Fantomas.Core, 6.*"
3737

38-
open FSharp.Compiler.Text
38+
open Fantomas.FCS.Text
3939
open Fantomas.Core.SyntaxOak
4040

4141
let implementationSyntaxTree =
@@ -88,11 +88,8 @@ The more you interact with AST/Oak, the easier you pick up which node represents
8888
8989
### Fantomas.FCS
9090
91-
When looking at the example, we notice that we've opened `FSharp.Compiler.Text`.
92-
Don't be fooled by this, `Fantomas.Core` and `Fantomas.FCS` **do not reference [FSharp.Compiler.Service](https://www.nuget.org/packages/FSharp.Compiler.Service)**!
93-
Instead, `Fantomas.FCS` is a custom version of the F# compiler (built from source) that only exposes the F# parser and the syntax tree.
94-
95-
`Fantomas.FCS` exposes the exact same namespaces because it builds from the exact same F# compiler source code.
91+
When looking at the example, we notice that we've opened `Fantomas.FCS.Text`.
92+
`Fantomas.FCS` is a custom version of the F# compiler (built from source) that only exposes the F# parser and the syntax tree.
9693
The key difference is that `Fantomas.FCS` will most likely contain a more recent version of the F# parser.
9794
You can read the [CHANGELOG](https://github.com/fsprojects/fantomas/blob/main/CHANGELOG.md) to see what git commit was used to build `Fantomas.FCS`.
9895

src/Fantomas.Core.Tests/ASTTransformerTests.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module Fantomas.Core.Tests.ASTTransformerTests
22

33
open NUnit.Framework
4-
open FSharp.Compiler.Text
5-
open FSharp.Compiler.Xml
6-
open FSharp.Compiler.Syntax
7-
open FSharp.Compiler.SyntaxTrivia
4+
open Fantomas.FCS.Text
5+
open Fantomas.FCS.Xml
6+
open Fantomas.FCS.Syntax
7+
open Fantomas.FCS.SyntaxTrivia
88
open Fantomas.Core
99

1010
[<Test>]

src/Fantomas.Core.Tests/CodeFormatterTests.fs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
module Fantomas.Core.Tests.CodeFormatterTests
22

33
open NUnit.Framework
4+
open Fantomas.FCS.Text
45
open Fantomas.Core
6+
open Fantomas.Core.SyntaxOak
57
open Fantomas.Core.Tests.TestHelpers
68

79
[<Test>]
@@ -39,7 +41,7 @@ let main _ =
3941
|> ignore
4042

4143
[<Test>]
42-
let ``trivia is parsed for Oak`` () =
44+
let ``trivia is transformed to Oak`` () =
4345
let oak =
4446
CodeFormatter.ParseOakAsync(false, "let a = 0\n // foo")
4547
|> Async.RunSynchronously
@@ -67,3 +69,61 @@ let ``parsed oak can be formatted back to source`` () =
6769
|> Async.RunSynchronously
6870

6971
Assert.AreEqual(source, formatted)
72+
73+
[<Test>]
74+
let ``transform parsedInput to Oak`` () =
75+
let source =
76+
"""
77+
module A
78+
79+
#if DEBUG
80+
let b = 0
81+
#endif
82+
"""
83+
84+
let ast, _ =
85+
Fantomas.FCS.Parse.parseFile false (SourceText.ofString source) [ "DEBUG" ]
86+
87+
let oak = CodeFormatter.TransformAST(ast, source)
88+
89+
match oak.ModulesOrNamespaces.[0].Declarations.[0] with
90+
| ModuleDecl.TopLevelBinding _ -> Assert.Pass()
91+
| _ -> Assert.Fail()
92+
93+
[<Test>]
94+
let ``transform parsedInput created with additional defines to Oak`` () =
95+
let source =
96+
"""
97+
module A
98+
99+
#if DEBUG
100+
let b = 0
101+
#endif
102+
"""
103+
104+
let ast, _ =
105+
Fantomas.FCS.Parse.parseFile false (SourceText.ofString source) [ "DEBUG"; "FOO"; "BAR" ]
106+
107+
let oak = CodeFormatter.TransformAST ast
108+
109+
match oak.ModulesOrNamespaces.[0].Declarations.[0] with
110+
| ModuleDecl.TopLevelBinding _ -> Assert.Pass()
111+
| _ -> Assert.Fail()
112+
113+
[<Test>]
114+
let ``transform parsedInput contains trivia in Oak`` () =
115+
let source =
116+
"""
117+
module A
118+
119+
// foo
120+
let b = 0
121+
"""
122+
123+
let ast, _ = Fantomas.FCS.Parse.parseFile false (SourceText.ofString source) []
124+
125+
let oak = CodeFormatter.TransformAST(ast, source)
126+
127+
match oak.ModulesOrNamespaces.[0].Declarations.[0] with
128+
| ModuleDecl.TopLevelBinding node -> Assert.True node.HasContentBefore
129+
| _ -> Assert.Fail()

src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ let a =
209209

210210
// Let's create a dummy Oak
211211
// In practise, a FCS Syntax tree will be transformed to an Oak
212-
let zeroRange = FSharp.Compiler.Text.Range.Zero
212+
let zeroRange = Fantomas.FCS.Text.Range.Zero
213213
let stn text = SingleTextNode(text, zeroRange)
214214

215215
let tree =
@@ -321,7 +321,7 @@ let b = 2
321321
"""
322322

323323
// Imagine that we always want to print a new line between let bindings.
324-
let zeroRange = FSharp.Compiler.Text.Range.Zero
324+
let zeroRange = Fantomas.FCS.Text.Range.Zero
325325
let stn text = SingleTextNode(text, zeroRange)
326326

327327
let mkBinding name body =

src/Fantomas.Core.Tests/CursorTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Fantomas.Core.Tests.CursorTests
22

3-
open FSharp.Compiler.Text
3+
open Fantomas.FCS.Text
44
open NUnit.Framework
55
open FsUnit
66
open Fantomas.Core

src/Fantomas.Core.Tests/DefinesTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Fantomas.Core.Tests.TokenParserTests
22

33
open NUnit.Framework
44
open FsUnit
5-
open FSharp.Compiler.Syntax
5+
open Fantomas.FCS.Syntax
66
open Fantomas.Core
77
open Fantomas.Core.Defines
88
open Fantomas.Core.Tests.TestHelpers

src/Fantomas.Core.Tests/FormattingSelectionOnlyTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Fantomas.Core.Tests.FormattingSelectionOnlyTests
22

3-
open FSharp.Compiler.Text
3+
open Fantomas.FCS.Text
44
open Fantomas.Core
55
open NUnit.Framework
66
open FsUnit

src/Fantomas.Core.Tests/SynLongIdentTests.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module Fantomas.Core.Tests.SynLongIdentTests
22

3-
open FSharp.Compiler.Text
4-
open FSharp.Compiler.Syntax
5-
open FSharp.Compiler.SyntaxTrivia
6-
open FSharp.Compiler.Xml
3+
open Fantomas.FCS.Text
4+
open Fantomas.FCS.Syntax
5+
open Fantomas.FCS.SyntaxTrivia
6+
open Fantomas.FCS.Xml
77
open NUnit.Framework
88
open FsUnit
99
open Fantomas.Core

0 commit comments

Comments
 (0)