Skip to content
Open
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
16 changes: 9 additions & 7 deletions src/FSharpLint.Core/Framework/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ module ExpressionUtilities =

/// Tries to find the source code within a given range.
let tryFindTextOfRange (range:Range) (text:string) =
let maybeStartIndex = findPos range.Start text
let maybeEndIndex = findPos range.End text

match (maybeStartIndex, maybeEndIndex) with
| Some(startIndex), Some(endIndex) ->
text.Substring(startIndex, endIndex - startIndex) |> Some
| _ -> None
findLineStart text range.Start.Line 1 0
|> Option.bind (fun startLineOffset ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer pattern matching to Option.bind and Option.map, but that's just stylistic choice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change it to something like

        match findLineStart text range.Start.Line 1 0 with
        | Some startLineOffset ->
            match findLineStart text range.End.Line range.Start.Line startLineOffset with
            | Some endLineOffset ->
                let startIndex = startLineOffset + range.Start.Column
                let endIndex = endLineOffset + range.End.Column
                text.Substring(startIndex, endIndex - startIndex) |> Some
            | None -> None
        | None -> None

if you'd prefer that.

findLineStart text range.End.Line range.Start.Line startLineOffset
|> Option.map (fun endLineOffset ->
let startIndex = startLineOffset + range.Start.Column
let endIndex = endLineOffset + range.End.Column
text.Substring(startIndex, endIndex - startIndex)
)
)

let getLeadingSpaces (range:Range) (text:string) =
let range = Range.mkRange String.Empty (Position.mkPos range.StartLine 0) range.End
Expand Down
Loading