Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .fantomasignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ src/Compiler/TypedTree/TypedTreeOps.fs
src/Compiler/TypedTree/TypedTreePickle.fs
src/Compiler/TypedTree/TypeProviders.fs

# https://github.com/fsprojects/fantomas/issues/2779
vsintegration/tests/FSharp.Editor.Tests/QuickInfoProviderTests.fs

# Explicitly unformatted file that needs more care to get it to format well

src/Compiler/SyntaxTree/LexFilter.fs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Process fantomas command
if: steps.command-extractor.outputs.result == 'fantomas'
id: fantomas
run: dotnet fantomas src -r
run: dotnet fantomas . -r
- name: Process fantomas command
if: steps.command-extractor.outputs.result == 'xlf'
id: xlf
Expand Down
4 changes: 2 additions & 2 deletions DEVGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,13 @@ or
Some of the code in this repository is formatted automatically by [Fantomas](https://github.com/fsprojects/fantomas). To format all files use:

```cmd
dotnet fantomas src -r
dotnet fantomas . -r
```

The formatting is checked automatically by CI:

```cmd
dotnet fantomas src -r --check
dotnet fantomas . -r --check
```

At the time of writing only a subset of signature files (`*.fsi`) are formatted. See the settings in `.fantomasignore` and `.editorconfig`.
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ stages:
env:
DOTNET_ROLL_FORWARD_TO_PRERELEASE: 1
displayName: Install tools
- script: dotnet fantomas src -r --check
- script: dotnet fantomas . -r --check
env:
DOTNET_ROLL_FORWARD_TO_PRERELEASE: 1
displayName: Check code formatting (run 'dotnet fantomas src -r' to fix)
displayName: Check code formatting (run 'dotnet fantomas . -r' to fix)

# Check whether package with current version has been published to nuget.org
# We will try to restore both FSharp.Core and FCS and if restore is _successful_, package version needs to be bumped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ type BraceMatchingServiceTests() =
let position = fileContents.IndexOf(marker)
Assert.True(position >= 0, $"Cannot find marker '{marker}' in file contents")

let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions
let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

match
FSharpBraceMatchingService.GetBraceMatchingResult(checker, sourceText, fileName, parsingOptions, position, "UnitTest")
|> Async.RunImmediateExceptOnUI
with
| None -> ()
| Some (left, right) -> failwith $"Found match for brace '{marker}'"
| Some (left, right) -> failwith $"Found match for brace '{marker}'"

member private this.VerifyBraceMatch(fileContents: string, startMarker: string, endMarker: string) =
let sourceText = SourceText.From(fileContents)
Expand All @@ -36,7 +37,8 @@ type BraceMatchingServiceTests() =
Assert.True(startMarkerPosition >= 0, $"Cannot find start marker '{startMarkerPosition}' in file contents")
Assert.True(endMarkerPosition >= 0, $"Cannot find end marker '{endMarkerPosition}' in file contents")

let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions
let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

match
FSharpBraceMatchingService.GetBraceMatchingResult(
Expand Down Expand Up @@ -202,7 +204,9 @@ let main argv =
[<InlineData("let a8 = seq { yield() }", 13, 23)>]
member this.DoNotMatchOnInnerSide(fileContents: string, [<ParamArray>] matchingPositions: int[]) =
let sourceText = SourceText.From(fileContents)
let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

for position in matchingPositions do
match
Expand All @@ -215,4 +219,4 @@ let main argv =
| 0 -> ""
| _ -> fileContents.[position - 1] |> sprintf " (previous character '%c')"
|> sprintf "Didn't find a matching brace at position '%d' %s" position
|> raise (exn())
|> raise (exn ())
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ let main argv =
|]

[<Theory>]
[<MemberData(nameof(BreakpointResolutionServiceTests.testCases))>]
[<MemberData(nameof (BreakpointResolutionServiceTests.testCases))>]
member this.TestBreakpointResolution(searchToken: string, expectedResolution: string option) =
let searchPosition = code.IndexOf(searchToken)
Assert.True(searchPosition >= 0, $"SearchToken '{searchToken}' is not found in code")

let sourceText = SourceText.From(code)

let document =
RoslynTestHelpers.CreateSolution(code)
|> RoslynTestHelpers.GetSingleDocument
RoslynTestHelpers.CreateSolution(code) |> RoslynTestHelpers.GetSingleDocument

let searchSpan =
TextSpan.FromBounds(searchPosition, searchPosition + searchToken.Length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ System.Console.WriteLine(x + y)
IntelliSenseOptions.Default
)

triggered |> Assert.shouldBeEqualWith shouldBeTriggered
triggered
|> Assert.shouldBeEqualWith
shouldBeTriggered
"FSharpCompletionProvider.ShouldTriggerCompletionAux() should compute the correct result"

[<Fact>]
Expand Down Expand Up @@ -242,7 +244,9 @@ let z = $"abc {System.Console.WriteLine(x + y)} def"
IntelliSenseOptions.Default
)

triggered |> Assert.shouldBeEqualWith shouldBeTriggered
triggered
|> Assert.shouldBeEqualWith
shouldBeTriggered
$"FSharpCompletionProvider.ShouldTriggerCompletionAux() should compute the correct result for marker '{marker}"

[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,25 @@ type DocumentDiagnosticAnalyzerTests() =
|> Seq.filter (fun e -> e.Severity = DiagnosticSeverity.Error)
|> Seq.toArray

errors.Length |> Assert.shouldBeEqualWith 1 "There should be exactly one error generated"
errors.Length
|> Assert.shouldBeEqualWith 1 "There should be exactly one error generated"

let actualError = errors.[0]

if expectedMessage.IsSome then
actualError.GetMessage() |> Assert.shouldBeEqualWith expectedMessage.Value "Error messages should match"
actualError.GetMessage()
|> Assert.shouldBeEqualWith expectedMessage.Value "Error messages should match"

Assert.Equal(DiagnosticSeverity.Error, actualError.Severity)
let expectedStart = fileContents.IndexOf(expectedMarker)
actualError.Location.SourceSpan.Start |> Assert.shouldBeEqualWith expectedStart "Error start positions should match"

actualError.Location.SourceSpan.Start
|> Assert.shouldBeEqualWith expectedStart "Error start positions should match"

let expectedEnd = expectedStart + expectedMarker.Length
actualError.Location.SourceSpan.End |> Assert.shouldBeEqualWith expectedEnd "Error end positions should match"

actualError.Location.SourceSpan.End
|> Assert.shouldBeEqualWith expectedEnd "Error end positions should match"

member private this.VerifyDiagnosticBetweenMarkers
(
Expand All @@ -59,14 +67,24 @@ type DocumentDiagnosticAnalyzerTests() =
|> Seq.filter (fun e -> e.Severity = expectedSeverity)
|> Seq.toArray

errors.Length |> Assert.shouldBeEqualWith 1 "There should be exactly one error generated"
errors.Length
|> Assert.shouldBeEqualWith 1 "There should be exactly one error generated"

let actualError = errors.[0]
Assert.Equal(expectedSeverity, actualError.Severity)
actualError.GetMessage() |> Assert.shouldBeEqualWith expectedMessage "Error messages should match"

actualError.GetMessage()
|> Assert.shouldBeEqualWith expectedMessage "Error messages should match"

let expectedStart = fileContents.IndexOf(startMarker) + startMarker.Length
actualError.Location.SourceSpan.Start |> Assert.shouldBeEqualWith expectedStart "Error start positions should match"

actualError.Location.SourceSpan.Start
|> Assert.shouldBeEqualWith expectedStart "Error start positions should match"

let expectedEnd = fileContents.IndexOf(endMarker)
actualError.Location.SourceSpan.End |> Assert.shouldBeEqualWith expectedEnd "Error end positions should match"

actualError.Location.SourceSpan.End
|> Assert.shouldBeEqualWith expectedEnd "Error end positions should match"

member private this.VerifyErrorBetweenMarkers(fileContents: string, expectedMessage: string) =
this.VerifyDiagnosticBetweenMarkers(fileContents, expectedMessage, DiagnosticSeverity.Error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module DocumentHighlightsServiceTests =
let filePath = "C:\\test.fs"

let private getSpans (fileContents: string) (caretPosition: int) =
let document =
let document =
RoslynTestHelpers.CreateSolution(fileContents)
|> RoslynTestHelpers.GetSingleDocument

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ marker4"""
let lineNumber =
sourceText.Lines |> Seq.findIndex (fun line -> line.Span.Contains position)

let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions
let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let changesOpt =
FSharpEditorFormattingService.GetFormattingChanges(
Expand All @@ -93,7 +94,9 @@ marker4"""
[<InlineData(false, "")>]
member this.TestPasteChanges_PastingOntoIndentedLine(enabled: bool, prefix: string) =
let checker = FSharpChecker.Create()
let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let clipboard =
prefix
Expand Down Expand Up @@ -149,14 +152,17 @@ somethingElseHere
Assert.Equal(expected, changedText)
| _ -> failwithf "Expected text changes, but got %+A" changesOpt
else
changesOpt |> Assert.shouldBeEqualWith None "Expected no changes as FormatOnPaste is disabled"
changesOpt
|> Assert.shouldBeEqualWith None "Expected no changes as FormatOnPaste is disabled"

[<Theory>]
[<InlineData "">]
[<InlineData " ">]
member this.TestPasteChanges_PastingOntoEmptyLine(prefix: string) =
let checker = FSharpChecker.Create()
let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let clipboard =
prefix
Expand Down Expand Up @@ -214,7 +220,9 @@ somethingElseHere
[<Fact>]
member this.TestPasteChanges_PastingWithAutoIndentationInPasteSpan() =
let checker = FSharpChecker.Create()
let parsingOptions, _ = checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let parsingOptions, _ =
checker.GetParsingOptionsFromProjectOptions RoslynTestHelpers.DefaultProjectOptions

let clipboard =
"""[<Class>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ type Worker() =
member _.VerifyCompletionListExactly(fileContents: string, marker: string, expected: List<string>) =
let caretPosition = fileContents.IndexOf(marker) + marker.Length

let options = { RoslynTestHelpers.DefaultProjectOptions with SourceFiles = [|filePath|] }
let options =
{ RoslynTestHelpers.DefaultProjectOptions with
SourceFiles = [| filePath |]
}

let document =
RoslynTestHelpers.CreateSolution(fileContents, options = options)
|> RoslynTestHelpers.GetSingleDocument
Expand Down Expand Up @@ -49,7 +53,7 @@ module FsxCompletionProviderTests =
let getWorker () = Worker()

#if RELEASE
[<Fact(Skip="Fails in some CI, reproduces locally in Release mode, needs investigation")>]
[<Fact(Skip = "Fails in some CI, reproduces locally in Release mode, needs investigation")>]
#else
[<Fact>]
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module GoToDefinitionServiceTests =
let caretPosition = fileContents.IndexOf(caretMarker) + caretMarker.Length - 1 // inside the marker

let sourceText = SourceText.From(fileContents)

let document =
RoslynTestHelpers.CreateSolution(fileContents)
|> RoslynTestHelpers.GetSingleDocument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type HelpContextServiceTests() =
let fileContents = fileContentsWithMarkers.Replace("$", "")

let sourceText = SourceText.From(fileContents)

let document =
RoslynTestHelpers.CreateSolution(fileContents)
|> RoslynTestHelpers.GetSingleDocument
Expand Down Expand Up @@ -57,7 +58,7 @@ type HelpContextServiceTests() =
TestF1KeywordsWithOptions(expectedKeywords, lines)

#if RELEASE
[<Fact(Skip="Fails in some CI, reproduces locally in Release mode, needs investigation")>]
[<Fact(Skip = "Fails in some CI, reproduces locally in Release mode, needs investigation")>]
#else
[<Fact>]
#endif
Expand Down Expand Up @@ -209,7 +210,7 @@ type HelpContextServiceTests() =
TestF1Keywords(keywords, file)

#if RELEASE
[<Fact(Skip="Fails in some CI, reproduces locally in Release mode, needs investigation")>]
[<Fact(Skip = "Fails in some CI, reproduces locally in Release mode, needs investigation")>]
#else
[<Fact>]
#endif
Expand All @@ -218,13 +219,10 @@ type HelpContextServiceTests() =
let file = [ "open N$1" ]
let keywords = [ Some "N1" ]

TestF1KeywordsWithOptions(
keywords,
file
)
TestF1KeywordsWithOptions(keywords, file)

#if RELEASE
[<Fact(Skip="Fails in some CI, reproduces locally in Release mode, needs investigation")>]
[<Fact(Skip = "Fails in some CI, reproduces locally in Release mode, needs investigation")>]
#else
[<Fact>]
#endif
Expand All @@ -239,10 +237,7 @@ type HelpContextServiceTests() =

let keywords = [ Some "N1.T" ]

TestF1KeywordsWithOptions(
keywords,
file
)
TestF1KeywordsWithOptions(keywords, file)

[<Fact>]
member _.``F1 help keyword EndOfLine``() =
Expand Down
Loading