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

#if blocks result in code being moved around incorrectly #282

Closed
7sharp9 opened this issue Jul 20, 2018 · 2 comments
Closed

#if blocks result in code being moved around incorrectly #282

7sharp9 opened this issue Jul 20, 2018 · 2 comments

Comments

@7sharp9
Copy link
Member

7sharp9 commented Jul 20, 2018

As an example from this code base TokenMatcher.fs:

module internal Fantomas.TokenMatcher

open System
open System.Collections.Generic
open System.Diagnostics
open Fantomas
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.PrettyNaming
open Microsoft.FSharp.Compiler.SourceCodeServices
open System.Text.RegularExpressions

#if INTERACTIVE
type Debug = Console
#endif

type Token = 
   | EOL
   | Tok of FSharpTokenInfo * int
   override x.ToString() =
        match x with
        | EOL -> "<EOL>"
        | Tok(tokInfo, l) ->
            sprintf "Tok(%O, %O)" tokInfo.TokenName l

This will get formatted to:

module internal Fantomas.TokenMatcher

open System
open System.Collections.Generic
open System.Diagnostics
open Fantomas
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.PrettyNaming
open Microsoft.FSharp.Compiler.SourceCodeServices
open System.Text.RegularExpressions
#if INTERACTIVE

type Token =
    
#endif
| EOL
    | Tok of FSharpTokenInfo * int
    override x.ToString() =
        match x with
        | EOL -> "<EOL>"
        | Tok(tokInfo, l) -> sprintf "Tok(%O, %O)" tokInfo.TokenName l

type Debug = Console is erased, type Token = is moved into the #if block.

@jindraivanek
Copy link
Contributor

This is now formatted to:

module internal Fantomas.TokenMatcher

open System
open System.Collections.Generic
open System.Diagnostics
open Fantomas
open Microsoft.FSharp.Compiler.Range
open Microsoft.FSharp.Compiler.PrettyNaming
open Microsoft.FSharp.Compiler.SourceCodeServices
open System.Text.RegularExpressions
#if INTERACTIVE

type Debug = Console
#endif


type Token =
    | EOL
    | Tok of FSharpTokenInfo * int
    override x.ToString() =
        match x with
        | EOL -> "<EOL>"
        | Tok(tokInfo, l) -> sprintf "Tok(%O, %O)" tokInfo.TokenName l

so only remaining problem is added/removed newlines. Probably bug in TokenMatcher.

@nojaf
Copy link
Contributor

nojaf commented Jul 17, 2019

This issue is now solved by trivia.

@nojaf nojaf closed this as completed Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants