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

additional new lines added after each call to format #1137

Closed
3 tasks
jmagaram opened this issue Sep 14, 2020 · 0 comments · Fixed by #1138
Closed
3 tasks

additional new lines added after each call to format #1137

jmagaram opened this issue Sep 14, 2020 · 0 comments · Fixed by #1138

Comments

@jmagaram
Copy link

Issue created from fantomas-online

Code

let create: Highlighter =
    fun searchTerm ->
        let regex = searchTerm |> SearchTerm.toRegex

        fun s ->
            match s |> String.length with
            | 0 -> [] |> FormattedText
            | _ ->
                seq {
                    let ms = regex.Matches(s)

                    if ms.Count = 0 then yield (TextSpan.normal s)
                    elif ms.[0].Index > 0 then yield TextSpan.normal (s.Substring(0, ms.[0].Index))

                    for i in 0 .. ms.Count - 1 do
                        yield TextSpan.highlight ms.[i].Value
                        let regStart = ms.[i].Index + ms.[i].Length

                        if i < ms.Count - 1
                        then yield TextSpan.normal (s.Substring(regStart, ms.[i + 1].Index - regStart))
                        elif regStart < s.Length
                        then yield TextSpan.normal (s.Substring(regStart))



                }
                |> List.ofSeq
                |> FormattedText.fromList

Result

let create: Highlighter =
    fun searchTerm ->
        let regex = searchTerm |> SearchTerm.toRegex

        fun s ->
            match s |> String.length with
            | 0 -> [] |> FormattedText
            | _ ->
                seq {
                    let ms = regex.Matches(s)

                    if ms.Count = 0 then yield (TextSpan.normal s)
                    elif ms.[0].Index > 0 then yield TextSpan.normal (s.Substring(0, ms.[0].Index))

                    for i in 0 .. ms.Count - 1 do
                        yield TextSpan.highlight ms.[i].Value
                        let regStart = ms.[i].Index + ms.[i].Length

                        if i < ms.Count - 1
                        then yield TextSpan.normal (s.Substring(regStart, ms.[i + 1].Index - regStart))
                        elif regStart < s.Length
                        then yield TextSpan.normal (s.Substring(regStart))




                }
                |> List.ofSeq
                |> FormattedText.fromList

Problem description

See the extra new lines in the input? If that is the source file and you press Ctrl K D another new line gets added each time. To simulate this in the online formatter, I kept copying the output into the input box and pressing Format and another line gets added. But if you just press Format a few times nothing changes.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas Master at 09/13/2020 16:11:22 - c6faad7

Default Fantomas configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant