Skip to content

Commit

Permalink
Fixing off by 1 error for Negation To Substraction CodeFix (#882)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Zalewski <[email protected]>
  • Loading branch information
jasiozet and jpingus authored Jan 22, 2022
1 parent d693d98 commit a7af704
Show file tree
Hide file tree
Showing 3 changed files with 558 additions and 351 deletions.
40 changes: 19 additions & 21 deletions src/FsAutoComplete/CodeFixes/NegationToSubtraction.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ open FsAutoComplete
open FsAutoComplete.LspHelpers

/// a codefix that corrects -<something> to - <something> when negation is not intended
let fix (getFileLines: GetFileLines): CodeFix =
Run.ifDiagnosticByCode
(Set.ofList [ "3" ])
(fun diagnostic codeActionParams ->
asyncResult {
let fileName =
codeActionParams.TextDocument.GetFilePath() |> Utils.normalizePath
let fix (getFileLines: GetFileLines) : CodeFix =
Run.ifDiagnosticByCode (Set.ofList [ "3" ]) (fun diagnostic codeActionParams ->
asyncResult {
let fileName =
codeActionParams.TextDocument.GetFilePath()
|> Utils.normalizePath

let! lines = getFileLines fileName
let! lines = getFileLines fileName

match walkForwardUntilCondition lines (inc lines diagnostic.Range.End) (fun ch -> ch = '-') with
| Some dash ->
return
[ { SourceDiagnostic = Some diagnostic
Title = "Use subtraction instead of negation"
File = codeActionParams.TextDocument
Edits =
[| { Range = { Start = dash; End = inc lines dash }
NewText = "- " } |]
Kind = FixKind.Fix } ]
| None -> return []
}
)
match walkForwardUntilCondition lines (inc lines diagnostic.Range.End) (fun ch -> ch = '-') with
| Some dash ->
return
[ { SourceDiagnostic = Some diagnostic
Title = "Use subtraction instead of negation"
File = codeActionParams.TextDocument
Edits =
[| { Range = { Start = dash; End = dec lines dash }
NewText = "- " } |]
Kind = FixKind.Fix } ]
| None -> return []
})
Loading

0 comments on commit a7af704

Please sign in to comment.