GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing fsprojects.github.io — Code formatting Code formattingThis page demonstrates how to use First, we need to load the assembly and open the necessary namespaces: If you want to process multiple snippets, it is a good idea to keep the formatting agent around if possible. The agent needs to load the F# compiler (which needs to load various files itself) and so this takes a long time. Processing F# sourceThe formatting agent provides a CodeFormatAgent.ParseAndCheckSource method (together with an asynchronous
version for use from F# and also a version that returns a .NET When calling the method, you need to specify a file name and the actual content
of the script file. The file does not have to physically exist. It is used by the
F# compiler to resolve relative references (e.g. You can also specify additional parameters, such as This operation might take some time, so it is a good idea to use an asynchronous variant of the method. It returns two arrays - the first contains F# snippets in the source code and the second contains any errors reported by the compiler. A single source file can include multiple snippets using the same formatting tags as those used on fssnip.net as documented in the about page. Working with returned tokensEach returned snippet is essentially just a collection of lines, and each line consists of a sequence of tokens. The following snippet prints basic information about the tokens of our sample snippet: The The Generating HTML outputFinally, the If the input contains multiple snippets separated using the 1 2 3 4 5 6 7 // [snippet: First sample] printf "The answer is: %A" 42 // [/snippet] // [snippet: Second sample] printf "Hello world!" // [/snippet] then the formatter returns multiple HTML blocks. However, the generated tooltips are shared by all snippets (to save space) and so they are returned separately. Multiple items
namespace FSharp -------------------- namespace Microsoft.FSharp namespace FSharp.Formatting
namespace FSharp.Formatting.CodeFormat
namespace System
namespace System.Reflection
val source: string
val snippets: Snippet array
val diagnostics: SourceError array
Formats F# source code snippets into annotated token sequences by invoking the
F# Compiler Service for tokenisation, type-checking, and semantic classification. module CodeFormatter from FSharp.Formatting.CodeFormat Parse, check and annotate the source code specified by 'source', assuming that it
is located in a specified 'file'. Optional arguments can be used to give compiler command line options and preprocessor definitions val ParseAndCheckSource: file: string * source: string * options: string option * defines: string option * onError: (string -> unit) -> Snippet array * SourceError array union case Option.None: Option<'T>
val ignore: value: 'T -> unit
Multiple items
union case Snippet.Snippet: title: string * lines: Line list -> Snippet -------------------- An F# snippet consists of a snippet title and a list of lines type Snippet = | Snippet of title: string * lines: Line list val title: string
val lines: Line list
module Seq
from Microsoft.FSharp.Collections val head: source: 'T seq -> 'T
Multiple items
union case Line.Line: originalLine: string * tokenSpans: TokenSpans -> Line -------------------- Represents a line of source code as a list of TokenSpan values. This is a single case discriminated union with Line constructor. type Line = | Line of originalLine: string * tokenSpans: TokenSpans val tokens: TokenSpans
val token: TokenSpan
A token in a parsed F# code snippet. Aside from standard tokens reported from
the compiler (Token), this also includes Error (wrapping the underlined tokens), Omitted for the special [omit:...] tags and Output for the special [output:...] tag type TokenSpan = | Token of kind: TokenKind * body: string * tip: ToolTipSpans option | Error of kind: ErrorKind * message: string * body: TokenSpans | Omitted of body: string * hidden: string | Output of string union case TokenSpan.Token:
kind: TokenKind * body: string * tip: ToolTipSpans option -> TokenSpan val kind: TokenKind
val code: string
val tip: ToolTipSpans option
val printf: format: Printf.TextWriterFormat<'T> -> 'T
module Option
from Microsoft.FSharp.Core val iter: action: ('T -> unit) -> option: 'T option -> unit
val spans: ToolTipSpans
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
union case TokenSpan.Omitted: body: string * hidden: string -> TokenSpan
union case TokenSpan.Output: string -> TokenSpan
union case TokenSpan.Error:
kind: ErrorKind * message: string * body: TokenSpans -> TokenSpan Multiple items
type LiteralAttribute = inherit Attribute new: unit -> LiteralAttribute -------------------- new: unit -> LiteralAttribute val prefix: string
val html: FormattedContent
Exposes functionality of the F# code formatter with a nice interface
type CodeFormat = static member FormatFsx: snippets: Snippet seq -> FormattedContent static member FormatHtml: snippets: Snippet array * prefix: string * ?openTag: string * ?closeTag: string * ?lineNumbers: bool * ?openLinesTag: string * ?closeLinesTag: string * ?addErrors: bool * ?tokenKindToCss: (TokenKind -> string) -> FormattedContent static member FormatLatex: snippets: Snippet array * ?openTag: string * ?closeTag: string * ?lineNumbers: bool -> FormattedContent static member CodeFormat.FormatHtml:
snippets: Snippet array * prefix: string * ?openTag: string * ?closeTag: string * ?lineNumbers: bool * ?openLinesTag: string * ?closeLinesTag: string * ?addErrors: bool * ?tokenKindToCss: (TokenKind -> string) -> FormattedContent val snip: FormattedSnippet
Returns the processed snippets as an array
property FormattedContent.Snippets: FormattedSnippet array with get Returns the formatted content code for the snipet
property FormattedSnippet.Content: string with get Returns string with ToolTip elements for all the snippets
property FormattedContent.ToolTip: string with get |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |