Skip to content

Commit

Permalink
For ClauseInCalse, except for insertAtBeginning, make precise computa…
Browse files Browse the repository at this point in the history
…tion of horizontal offset for the insertion
  • Loading branch information
jxxcarlson committed Jun 2, 2024
1 parent dccf829 commit bc6c577
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
31 changes: 12 additions & 19 deletions src/Install/ClauseInCase.elm
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ rangeToInsertClause insertAt cases expression =
|> List.head
|> Maybe.map Tuple.second
|> Maybe.withDefault expression

_ =
Debug.log "LAST CLAUSE RANGE" (Node.range lastClauseExpression)

_ =
Debug.log "FIRST CLAUSE RANGE" (Node.range firstClauseExpression)
in
case insertAt of
After previousClause ->
Expand All @@ -241,44 +235,43 @@ rangeToInsertClause insertAt cases expression =
pattern
|> Tuple.second
|> Node.range
|> Debug.log "NODE RANGE (1)"
|> (\range -> ( range, 2, range.start.column |> Debug.log "H OFFSET" ))
|> (\range -> ( range, 2, range.start.column |> Debug.log "rangeStartColumn (1)" ))

Nothing ->
( Node.range lastClauseExpression |> Debug.log "NODE RANGE (2)", 2, 0 )
( Node.range lastClauseExpression |> Debug.log "rangeLastClauseExpression", 2, 0 )

AtBeginning ->
-- TODO: Review, is it correct?
( Node.range expression |> Debug.log "NODE RANGE (3)", 1, 0 )
( Node.range expression |> Debug.log "NODE RANGE (3)", 1, (Node.range expression).start.column |> Debug.log "expressionStartColumn (2)" )

AtEnd ->
let
range =
Node.range lastClauseExpression |> Debug.log "NODE RANGE (4)"
Node.range lastClauseExpression
in
( range, 2, range.start.column |> Debug.log "H OFFSET" )
( range, 2, range.start.column )


errorWithFix : CustomError -> String -> String -> Node a -> Maybe ( Range, Int, Int ) -> Error {}
errorWithFix (CustomError customError) clause functionCall node errorRange =
let
deltaH =
Node.range node |> .start |> .row |> Debug.log "@@NODE RANGE, start, row"
nodeStartRow =
(Node.range node).start.row |> Debug.log "nodeStartRow"
in
Rule.errorWithFix
customError
(Node.range node |> Debug.log "RANGE")
(Node.range node)
(case errorRange of
Just ( range, verticalOffset, horizontalOffset ) ->
let
horizontalOffset2 =
Debug.log "@@@ horizontalOffset2" horizontalOffset - deltaH + 1
horizontalPadding =
Debug.log "horizontalPadding" (horizontalOffset - nodeStartRow + 1)

insertionPoint =
{ row = range.end.row + verticalOffset, column = 0 }

prefix =
"\n" ++ String.repeat horizontalOffset2 " "
"\n" ++ String.repeat horizontalPadding " "
in
[ addMissingCase insertionPoint prefix clause functionCall |> Debug.log "insertion" ]

Expand All @@ -293,7 +286,7 @@ addMissingCase { row, column } prefix clause functionCall =
insertion =
prefix ++ clause ++ " -> " ++ functionCall ++ "\n\n"
in
Fix.insertAt ({ row = row, column = column } |> Debug.log "INSERTING AT") insertion
Fix.insertAt { row = row, column = column } insertion



Expand Down
6 changes: 3 additions & 3 deletions tests/Install/ClauseInCaseTest2.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import Test exposing (Test, describe, test)
all : Test
all =
describe "Install.ClauseInCase"
[ -- Run.testFix test1a
Run.testFix test1b
[ Run.testFix test1a

--, Run.testFix test1c
-- Run.testFix test1b
-- Run.testFix test1c
-- Run.testFix test2
]

Expand Down

0 comments on commit bc6c577

Please sign in to comment.