Skip to content

Commit

Permalink
Extracted Context types and functions from FormatConfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 26, 2018
1 parent 32dccea commit 289a318
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 373 deletions.
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/TestHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let printAST isFsiFile sourceCode =

let printContext sourceCode =
let normalizedSourceCode = Fantomas.String.normalizeNewLine sourceCode
let context = Fantomas.FormatConfig.Context.create config normalizedSourceCode
let context = Fantomas.Context.Context.create config normalizedSourceCode
printfn "directives:"
context.Directives
|> Seq.iter (fun kv -> printfn "%A %s" kv.Key kv.Value)
Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas/CodeFormatter.fsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#r "../../packages/FSharp.Compiler.Service/lib/net45/FSharp.Compiler.Service.dll"

#load "Utils.fs"
#load "TokenMatcher.fs"
#load "FormatConfig.fs"
#load "TokenMatcher.fs"
#load "Context.fs"
#load "SourceParser.fs"
#load "SourceTransformer.fs"
#load "CodePrinter.fs"
Expand Down
16 changes: 8 additions & 8 deletions src/Fantomas/CodeFormatterImpl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ let formatWith ast formatContext config =
let sourceCode = defaultArg input String.Empty
let normalizedSourceCode = String.normalizeNewLine sourceCode
let formattedSourceCode =
Context.create config normalizedSourceCode
Fantomas.Context.Context.create config normalizedSourceCode
|> genParsedInput { ASTContext.Default with TopLevelModuleName = moduleName } ast
|> dump
|> Context.dump
|> if config.StrictMode then id
else integrateComments config.PreserveEndOfLine config.SpaceAroundDelimiter formatContext.ProjectOptions.ConditionalCompilationDefines normalizedSourceCode
else integrateComments config formatContext.ProjectOptions.ConditionalCompilationDefines normalizedSourceCode

// Sometimes F# parser gives a partial AST for incorrect input
if input.IsSome && String.IsNullOrWhiteSpace normalizedSourceCode <> String.IsNullOrWhiteSpace formattedSourceCode then
Expand Down Expand Up @@ -536,13 +536,13 @@ let formatRange returnFormattedContentOnly (range : range) (lines : _ []) config
let reconstructSourceCode startCol formatteds pre post =
Debug.WriteLine("Formatted parts: '{0}' at column {1}", sprintf "%A" formatteds, startCol)
// Realign results on the correct column
Context.create config String.Empty
Context.Context.create config String.Empty
// Mono version of indent text writer behaves differently from .NET one,
// So we add an empty string first to regularize it
|> if returnFormattedContentOnly then str String.Empty else str pre
|> atIndentLevel startCol (col sepNln formatteds str)
|> if returnFormattedContentOnly then str String.Empty else str post
|> dump
|> if returnFormattedContentOnly then Context.str String.Empty else Context.str pre
|> Context.atIndentLevel startCol (Context.col Context.sepNln formatteds Context.str)
|> if returnFormattedContentOnly then Context.str String.Empty else Context.str post
|> Context.dump

async {
match patch with
Expand Down
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open Fantomas
open Fantomas.FormatConfig
open Fantomas.SourceParser
open Fantomas.SourceTransformer
open Fantomas.Context

/// This type consists of contextual information which is important for formatting
type ASTContext =
Expand Down
Loading

0 comments on commit 289a318

Please sign in to comment.