Skip to content

Commit

Permalink
New Index syntax on raw list. Fixes #1929. (#1964)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 9, 2021
1 parent a40a7e9 commit fd34034
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Fantomas.Tests/IndexSyntaxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,18 @@ for x in 1..2 do
let s = seq { 0..10..100 }
"""

[<Test>]
let ``index syntax on raw list, 1929`` () =
formatSourceString
false
"""
let y = [ 0; 2; 4 ][ 1 ]
"""
config
|> prepend newline
|> should
equal
"""
let y = [ 0; 2; 4 ][1]
"""
5 changes: 5 additions & 0 deletions src/Fantomas/RangeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ module RangeHelpers =
&& r1.EndColumn = r2.EndColumn

let rangeEq = Range.equals

let isAdjacentTo (r1: Range) (r2: Range) : bool =
r1.FileName = r2.FileName
&& r1.End.Line = r2.Start.Line
&& r1.EndColumn = r2.StartColumn
6 changes: 6 additions & 0 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,12 @@ let (|IndexWithoutDotExpr|_|) =
function
| SynExpr.App (ExprAtomicFlag.Atomic, false, identifierExpr, SynExpr.ArrayOrListComputed (false, indexExpr, _), _) ->
Some(identifierExpr, indexExpr)
| SynExpr.App (ExprAtomicFlag.NonAtomic,
false,
identifierExpr,
(SynExpr.ArrayOrListComputed (isArray = false; expr = indexExpr) as argExpr),
_) when (RangeHelpers.isAdjacentTo identifierExpr.Range argExpr.Range) ->
Some(identifierExpr, indexExpr)
| _ -> None

let (|MatchLambda|_|) =
Expand Down

0 comments on commit fd34034

Please sign in to comment.