Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing off by 1 error for Negation To Substraction CodeFix #882

Merged
merged 3 commits into from
Jan 22, 2022
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
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