diff --git a/.editorconfig b/.editorconfig index c4eaa90..2fbb641 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,4 +14,10 @@ fsharp_array_or_list_multiline_formatter=character_width fsharp_max_value_binding_width=70 fsharp_max_function_binding_width=70 fsharp_max_dot_get_expression_width=70 -fsharp_max_elmish_width=70 \ No newline at end of file +fsharp_max_elmish_width=70 + +[Marksman/*.{fs,fsi}] +fsharp_multiline_bracket_style = stroustrup + +[Tests/*.{fs,fsi}] +fsharp_multiline_bracket_style = stroustrup diff --git a/Marksman/Ast.fs b/Marksman/Ast.fs index 8388146..963e5ea 100644 --- a/Marksman/Ast.fs +++ b/Marksman/Ast.fs @@ -4,18 +4,20 @@ open Marksman.Misc open Marksman.Names open Marksman.Syms -type Heading = - { level: int - text: string - id: Slug } +type Heading = { + level: int + text: string + id: Slug +} with member this.CompactFormat() = let prefix = String.replicate this.level "#" $"{prefix} {this.text} {{{this.id.Raw}}}" -type WikiLink = - { doc: option - heading: option } +type WikiLink = { + doc: option + heading: option +} with member this.CompactFormat() = let doc = this.doc |> Option.defaultValue "" @@ -29,10 +31,11 @@ type WikiLink = // [text](url "title") -type MdLink = - { text: string - url: option - anchor: option } +type MdLink = { + text: string + url: option + anchor: option +} with member this.CompactFormat() = let url = @@ -65,9 +68,10 @@ type MdRef = member this.DestLabel = LinkLabel.ofString this.Dest -type MdLinkDef = - { label: string - url: UrlEncoded } +type MdLinkDef = { + label: string + url: UrlEncoded +} with member this.Label = LinkLabel.ofString this.label member this.CompactFormat() = $"[{this.label}]: {UrlEncoded.raw this.url}" diff --git a/Marksman/Compl.fs b/Marksman/Compl.fs index 488d9fc..f71021e 100644 --- a/Marksman/Compl.fs +++ b/Marksman/Compl.fs @@ -384,23 +384,27 @@ module Completions = let range = if Completable.isPartial compl then range else inputRange let textEdit = { Range = range; NewText = newText } - Some - { CompletionItem.Create(targetName) with + Some { + CompletionItem.Create(targetName) with Detail = Some(Doc.pathFromRoot doc |> RelPath.toSystem) TextEdit = Some(First textEdit) - FilterText = Some filterText } + FilterText = Some filterText + } | Some _ -> let newText = targetLink let range = inputRange - let textEdit = - { Range = range; NewText = WikiEncoded.raw (WikiDest.encode newText) } + let textEdit = { + Range = range + NewText = WikiEncoded.raw (WikiDest.encode newText) + } - Some - { CompletionItem.Create(targetName) with + Some { + CompletionItem.Create(targetName) with Detail = Some(Doc.pathFromRoot doc |> RelPath.toSystem) TextEdit = Some(First textEdit) - FilterText = Some targetName } + FilterText = Some targetName + } | _ -> None let wikiHeadingInSrcDoc @@ -427,10 +431,11 @@ module Completions = let textEdit = { Range = range; NewText = newText } - Some - { CompletionItem.Create(completionHeading) with + Some { + CompletionItem.Create(completionHeading) with TextEdit = Some(First textEdit) - FilterText = Some newText } + FilterText = Some newText + } | _ -> None let wikiHeadingInOtherDoc @@ -442,8 +447,10 @@ module Completions = let label = $"{Doc.name doc} / {heading}" match compl with - | E(WL { data = { doc = Some destPart; heading = Some headingPart } - range = range }) + | E(WL { + data = { doc = Some destPart; heading = Some headingPart } + range = range + }) | PE(PartialElement.WikiLink(Some destPart, Some headingPart, range)) -> let targetLink = CompletionHelpers.wikiTargetLink config doc @@ -468,11 +475,12 @@ module Completions = let textEdit = { Range = range; NewText = newText } - Some - { CompletionItem.Create(label) with + Some { + CompletionItem.Create(label) with Detail = Some(Doc.pathFromRoot doc |> RelPath.toSystem) TextEdit = Some(First textEdit) - FilterText = Some filterText } + FilterText = Some filterText + } | _ -> None let reference (pos: Position) (compl: Completable) (def: MdLinkDef) : option = @@ -503,12 +511,13 @@ module Completions = let textEdit = { Range = range; NewText = newText } - Some - { CompletionItem.Create(linkDefLabel) with + Some { + CompletionItem.Create(linkDefLabel) with Detail = MdLinkDef.titleContent def Documentation = MdLinkDef.urlContent def |> Documentation.String |> Some TextEdit = Some(First textEdit) - FilterText = Some newText } + FilterText = Some newText + } let inlineDoc (pos: Position) (compl: Completable) (doc: Doc) : option = let targetPath = (Doc.pathFromRoot doc) |> RelPath.toSystem @@ -519,18 +528,20 @@ module Completions = match compl with | E(ML { data = MdLink.IL(_, None, _) }) -> - Some - { CompletionItem.Create(targetPath) with + Some { + CompletionItem.Create(targetPath) with Detail = detail TextEdit = - Some(First { Range = Range.Mk(pos, pos); NewText = targetPathEncoded }) } + Some(First { Range = Range.Mk(pos, pos); NewText = targetPathEncoded }) + } | E(ML { data = MdLink.IL(_, Some url, _) }) -> match Url.ofUrlNode url with | { url = Some url } -> - Some - { CompletionItem.Create(targetPath) with + Some { + CompletionItem.Create(targetPath) with Detail = detail - TextEdit = Some(First { Range = url.range; NewText = targetPathEncoded }) } + TextEdit = Some(First { Range = url.range; NewText = targetPathEncoded }) + } | _ -> None | PE(PartialElement.InlineLink(Some _text, path, Some _anchor, _range)) -> let range = @@ -538,19 +549,21 @@ module Completions = |> Option.map Node.range |> Option.defaultValue (Range.Mk(pos, pos)) - Some - { CompletionItem.Create(targetPath) with + Some { + CompletionItem.Create(targetPath) with Detail = detail - TextEdit = Some(First { Range = range; NewText = targetPathEncoded }) } + TextEdit = Some(First { Range = range; NewText = targetPathEncoded }) + } | PE(PartialElement.InlineLink(Some text, _path, None, range)) -> let newText = MdLink.renderInline (Node.text text |> Some) (Some targetPathEncoded) None - Some - { CompletionItem.Create(targetPath) with + Some { + CompletionItem.Create(targetPath) with Detail = detail TextEdit = Some(First { Range = range; NewText = newText }) - FilterText = Some newText } + FilterText = Some newText + } | _ -> None let inlineAnchorInSrcDoc @@ -568,18 +581,20 @@ module Completions = | { url = None; anchor = Some anchor } -> let newText = headingSlug - Some - { CompletionItem.Create(completionHeading) with + Some { + CompletionItem.Create(completionHeading) with TextEdit = Some(First { Range = anchor.range; NewText = newText }) - FilterText = Some newText } + FilterText = Some newText + } | _ -> None | PE(PartialElement.InlineLink(Some text, None, Some _anchor, range)) -> let newText = $"[{text.text}](#{headingSlug})" - Some - { CompletionItem.Create(completionHeading) with + Some { + CompletionItem.Create(completionHeading) with TextEdit = Some(First { Range = range; NewText = newText }) - FilterText = Some newText } + FilterText = Some newText + } | _ -> None let inlineAnchorInOtherDoc @@ -604,11 +619,12 @@ module Completions = let newRange = Range.Mk(url.range.Start, anchor.range.End) let filterText = $"{targetPathEncoded}#{targetHeading}" - Some - { CompletionItem.Create(label) with + Some { + CompletionItem.Create(label) with Detail = detail TextEdit = Some(First { Range = newRange; NewText = newText }) - FilterText = Some filterText } + FilterText = Some filterText + } | _, _ -> None | PE(PartialElement.InlineLink(Some text, Some _path, Some _anchor, range)) -> let newText = @@ -616,11 +632,12 @@ module Completions = let filterText = $"[{text.text}]({targetPathEncoded}#{targetHeading})" - Some - { CompletionItem.Create(label) with + Some { + CompletionItem.Create(label) with Detail = detail TextEdit = Some(First { Range = range; NewText = newText }) - FilterText = Some filterText } + FilterText = Some filterText + } | _ -> None let tag @@ -642,10 +659,11 @@ module Completions = let detail = $"{numUsages} usages" // IDEA: since we have numUsages we could provide sort text that would sort based on usages. - Some - { CompletionItem.Create(label) with + Some { + CompletionItem.Create(label) with Detail = Some detail - TextEdit = Some(First { Range = range; NewText = label }) } + TextEdit = Some(First { Range = range; NewText = label }) + } module Candidates = let findDocCandidates (folder: Folder) (srcDoc: Doc) (destPart: option) : seq = diff --git a/Marksman/Config.fs b/Marksman/Config.fs index 90ea249..1482a6b 100644 --- a/Marksman/Config.fs +++ b/Marksman/Config.fs @@ -123,35 +123,38 @@ module TextSync = /// /// Note: all config options are laid out flat to make working with the config /// without lenses manageable. -type Config = - { caTocEnable: option - caCreateMissingFileEnable: option - coreMarkdownFileExtensions: option> - coreTextSync: option - coreIncrementalReferences: option - coreParanoid: option - complWikiStyle: option - complCandidates: option } - - static member Default = - { caTocEnable = Some true - caCreateMissingFileEnable = Some true - coreMarkdownFileExtensions = Some [| "md"; "markdown" |] - coreTextSync = Some Full - coreIncrementalReferences = Some false - coreParanoid = Some false - complWikiStyle = Some TitleSlug - complCandidates = Some 50 } - - static member Empty = - { caTocEnable = None - caCreateMissingFileEnable = None - coreMarkdownFileExtensions = None - coreTextSync = None - coreIncrementalReferences = None - coreParanoid = None - complWikiStyle = None - complCandidates = None } +type Config = { + caTocEnable: option + caCreateMissingFileEnable: option + coreMarkdownFileExtensions: option> + coreTextSync: option + coreIncrementalReferences: option + coreParanoid: option + complWikiStyle: option + complCandidates: option +} with + + static member Default = { + caTocEnable = Some true + caCreateMissingFileEnable = Some true + coreMarkdownFileExtensions = Some [| "md"; "markdown" |] + coreTextSync = Some Full + coreIncrementalReferences = Some false + coreParanoid = Some false + complWikiStyle = Some TitleSlug + complCandidates = Some 50 + } + + static member Empty = { + caTocEnable = None + caCreateMissingFileEnable = None + coreMarkdownFileExtensions = None + coreTextSync = None + coreIncrementalReferences = None + coreParanoid = None + complWikiStyle = None + complCandidates = None + } member this.CaTocEnable() = this.caTocEnable @@ -231,34 +234,37 @@ let private configOfTable (table: TomlTable) : LookupResult = Error(WrongValue(complCandidatesPath, v, "expected a non-negative number")) - { caTocEnable = caTocEnable - caCreateMissingFileEnable = caCreateMissingFileEnable - coreMarkdownFileExtensions = coreMarkdownFileExtensions - coreTextSync = coreTextSync - coreIncrementalReferences = coreIncrementalReferences - coreParanoid = coreParanoid - complWikiStyle = complWikiStyle - complCandidates = complCandidates } + { + caTocEnable = caTocEnable + caCreateMissingFileEnable = caCreateMissingFileEnable + coreMarkdownFileExtensions = coreMarkdownFileExtensions + coreTextSync = coreTextSync + coreIncrementalReferences = coreIncrementalReferences + coreParanoid = coreParanoid + complWikiStyle = complWikiStyle + complCandidates = complCandidates + } } module Config = let logger = LogProvider.getLoggerByName "Config" - let merge hi low = - { caTocEnable = hi.caTocEnable |> Option.orElse low.caTocEnable - caCreateMissingFileEnable = + let merge hi low = { + caTocEnable = hi.caTocEnable |> Option.orElse low.caTocEnable + caCreateMissingFileEnable = hi.caCreateMissingFileEnable |> Option.orElse low.caCreateMissingFileEnable - coreMarkdownFileExtensions = + coreMarkdownFileExtensions = hi.coreMarkdownFileExtensions |> Option.orElse low.coreMarkdownFileExtensions - coreTextSync = hi.coreTextSync |> Option.orElse low.coreTextSync - coreIncrementalReferences = + coreTextSync = hi.coreTextSync |> Option.orElse low.coreTextSync + coreIncrementalReferences = hi.coreIncrementalReferences |> Option.orElse low.coreIncrementalReferences - coreParanoid = hi.coreParanoid |> Option.orElse low.coreParanoid - complWikiStyle = hi.complWikiStyle |> Option.orElse low.complWikiStyle - complCandidates = hi.complCandidates |> Option.orElse low.complCandidates } + coreParanoid = hi.coreParanoid |> Option.orElse low.coreParanoid + complWikiStyle = hi.complWikiStyle |> Option.orElse low.complWikiStyle + complCandidates = hi.complCandidates |> Option.orElse low.complCandidates + } let mergeOpt hi low = match low with diff --git a/Marksman/Conn.fs b/Marksman/Conn.fs index 3f40130..348a51b 100644 --- a/Marksman/Conn.fs +++ b/Marksman/Conn.fs @@ -9,9 +9,10 @@ open Marksman.Graph open Marksman.Syms -type Oracle = - { resolveToScope: Scope -> Ref -> Scope[] - resolveInScope: Ref -> Scope -> Def[] } +type Oracle = { + resolveToScope: Scope -> Ref -> Scope[] + resolveInScope: Ref -> Scope -> Def[] +} module ScopedSym = let asRef (scope, sym) = Sym.asRef sym |> Option.map (fun link -> scope, link) @@ -33,13 +34,14 @@ type Unresolved = | Scope FullyUnknown -> "FullyUnknown" | Scope(InScope scope) -> $"{scope}" -type ConnDifference = - { refsDifference: MMapDifference - defsDifference: MMapDifference - tagsDifference: MMapDifference - resolvedDifference: GraphDifference - unresolvedDifference: GraphDifference - refDepsDifference: GraphDifference } +type ConnDifference = { + refsDifference: MMapDifference + defsDifference: MMapDifference + tagsDifference: MMapDifference + resolvedDifference: GraphDifference + unresolvedDifference: GraphDifference + refDepsDifference: GraphDifference +} with member this.IsEmpty() = this.refsDifference.IsEmpty() @@ -79,9 +81,10 @@ type ConnDifference = concatLines lines -type Defs = - { byScope: MMap - bySlug: MMap } +type Defs = { + byScope: MMap + bySlug: MMap +} with static member Empty = { byScope = MMap.empty; bySlug = MMap.empty } @@ -116,14 +119,15 @@ type Defs = { byScope = byScope; bySlug = bySlug } -type Conn = - { refs: MMap - defs: Defs - tags: MMap - resolved: Graph - unresolved: Graph - refDeps: Graph - lastTouched: Set } +type Conn = { + refs: MMap + defs: Defs + tags: MMap + resolved: Graph + unresolved: Graph + refDeps: Graph + lastTouched: Set +} with member private this.ResolvedCompactFormat() = let byScope = @@ -217,14 +221,15 @@ type Conn = module Conn = let private logger = LogProvider.getLoggerByName "Conn" - let empty = - { refs = MMap.empty - defs = Defs.Empty - tags = MMap.empty - resolved = Graph.empty - unresolved = Graph.empty - refDeps = Graph.empty - lastTouched = Set.empty } + let empty = { + refs = MMap.empty + defs = Defs.Empty + tags = MMap.empty + resolved = Graph.empty + unresolved = Graph.empty + refDeps = Graph.empty + lastTouched = Set.empty + } let isSameStructure c1 c2 = c1.refs = c2.refs @@ -253,12 +258,14 @@ module Conn = let stopwatch = System.Diagnostics.Stopwatch.StartNew() - let mutable { refs = refs - defs = defs - tags = tags - resolved = resolved - unresolved = unresolved - refDeps = refDeps } = + let mutable { + refs = refs + defs = defs + tags = tags + resolved = resolved + unresolved = unresolved + refDeps = refDeps + } = conn let mutable lastTouched = Set.empty @@ -470,13 +477,15 @@ module Conn = >> Log.addContext "elapsed_ms" stopwatch.ElapsedMilliseconds ) - { refs = refs - defs = defs - tags = tags - resolved = resolved - unresolved = unresolved - refDeps = refDeps - lastTouched = lastTouched } + { + refs = refs + defs = defs + tags = tags + resolved = resolved + unresolved = unresolved + refDeps = refDeps + lastTouched = lastTouched + } let update oracle diff conn = if Difference.isEmpty diff then @@ -498,13 +507,14 @@ module Conn = update oracle { added = added; removed = Set.empty } empty - let difference c1 c2 : ConnDifference = - { refsDifference = MMap.difference c1.refs c2.refs - defsDifference = MMap.difference c1.defs.byScope c2.defs.byScope - tagsDifference = MMap.difference c1.tags c2.tags - resolvedDifference = Graph.difference c1.resolved c2.resolved - unresolvedDifference = Graph.difference c1.unresolved c2.unresolved - refDepsDifference = Graph.difference c1.refDeps c2.refDeps } + let difference c1 c2 : ConnDifference = { + refsDifference = MMap.difference c1.refs c2.refs + defsDifference = MMap.difference c1.defs.byScope c2.defs.byScope + tagsDifference = MMap.difference c1.tags c2.tags + resolvedDifference = Graph.difference c1.resolved c2.resolved + unresolvedDifference = Graph.difference c1.unresolved c2.unresolved + refDepsDifference = Graph.difference c1.refDeps c2.refDeps + } module Query = let resolve (scopedSym: ScopedSym) (conn: Conn) : Set = diff --git a/Marksman/Cst.fs b/Marksman/Cst.fs index d59f1f8..305ff9f 100644 --- a/Marksman/Cst.fs +++ b/Marksman/Cst.fs @@ -99,20 +99,23 @@ type MdLink = // reference shortcut | RS of label: TextNode -type Url<'T> = - { url: Option> - anchor: Option> } +type Url<'T> = { + url: Option> + anchor: Option> +} with override this.ToString() : string = let parts = - [ this.url - |> Option.map (fun x -> x.text, x.range) - |> Option.map (fun (text, range) -> $"docUrl={text} @ {range}") - |> Option.toList - this.anchor - |> Option.map (fun x -> x.text, x.range) - |> Option.map (fun (text, range) -> $"anchor={text} @ {range}") - |> Option.toList ] + [ + this.url + |> Option.map (fun x -> x.text, x.range) + |> Option.map (fun (text, range) -> $"docUrl={text} @ {range}") + |> Option.toList + this.anchor + |> Option.map (fun x -> x.text, x.range) + |> Option.map (fun (text, range) -> $"anchor={text} @ {range}") + |> Option.toList + ] |> List.concat String.Join(';', parts) @@ -134,21 +137,23 @@ module Url = else let docText = url.text.Substring(0, offsetHash) - let docRange = - { url.range with - End = Position.Mk(url.range.Start.Line, url.range.Start.Character + offsetHash) } + let docRange = { + url.range with + End = Position.Mk(url.range.Start.Line, url.range.Start.Character + offsetHash) + } let docUrl = Node.mk docText docRange (coder docText) let anchorText = url.text.Substring(offsetHash + 1) - let anchorRange = - { url.range with + let anchorRange = { + url.range with Start = Position.Mk( url.range.Start.Line, url.range.Start.Character + offsetHash + 1 - ) } + ) + } let anchor = Node.mk anchorText anchorRange (coder anchorText) @@ -219,8 +224,10 @@ module MdLinkDef = let name (mld: MdLinkDef) = mld.label |> Node.text - let toAbstract (mdDef: MdLinkDef) : Ast.MdLinkDef = - { label = mdDef.label.text; url = mdDef.url.data } + let toAbstract (mdDef: MdLinkDef) : Ast.MdLinkDef = { + label = mdDef.label.text + url = mdDef.url.data + } type Tag = { name: TextNode } @@ -297,8 +304,11 @@ module Heading = let scope (heading: Heading) : Range = heading.scope - let toAbstract (cHead: Heading) : Ast.Heading = - { level = cHead.level; text = cHead.title.text; id = slug cHead } + let toAbstract (cHead: Heading) : Ast.Heading = { + level = cHead.level + text = cHead.title.text + id = slug cHead + } module Element = diff --git a/Marksman/Diag.fs b/Marksman/Diag.fs index 5729d3f..3b17c42 100644 --- a/Marksman/Diag.fs +++ b/Marksman/Diag.fs @@ -40,9 +40,10 @@ let checkNonBreakingWhitespace (doc: Doc) = match headingLike with | None -> [] | Some heading -> - let whitespaceRange: Lsp.Range = - { Start = { Line = x; Character = heading.Length } - End = { Line = x; Character = heading.Length + 1 } } + let whitespaceRange: Lsp.Range = { + Start = { Line = x; Character = heading.Length } + End = { Line = x; Character = heading.Length + 1 } + } [ NonBreakableWhitespace(whitespaceRange) ]) @@ -136,15 +137,17 @@ let diagToLsp (diag: Entry) : Lsp.Diagnostic = let related = dests |> Array.map mkRelated - { Range = Element.range el - Severity = Some severity - Code = Some(code diag) - CodeDescription = None - Source = Some "Marksman" - Message = $"Ambiguous link to {refToHuman ref}" - RelatedInformation = Some related - Tags = None - Data = None } + { + Range = Element.range el + Severity = Some severity + Code = Some(code diag) + CodeDescription = None + Source = Some "Marksman" + Message = $"Ambiguous link to {refToHuman ref}" + RelatedInformation = Some related + Tags = None + Data = None + } | BrokenLink(el, ref) -> let severity = match el with @@ -157,27 +160,30 @@ let diagToLsp (diag: Entry) : Lsp.Diagnostic = let msg = $"Link to non-existent {refToHuman ref}" - { Range = Element.range el - Severity = Some severity - Code = Some(code diag) - CodeDescription = None - Source = Some "Marksman" - Message = msg - RelatedInformation = None - Tags = None - Data = None } - - | NonBreakableWhitespace dup -> - { Range = dup - Severity = Some Lsp.DiagnosticSeverity.Warning - Code = Some(code diag) - CodeDescription = None - Source = Some "Marksman" - Message = + { + Range = Element.range el + Severity = Some severity + Code = Some(code diag) + CodeDescription = None + Source = Some "Marksman" + Message = msg + RelatedInformation = None + Tags = None + Data = None + } + + | NonBreakableWhitespace dup -> { + Range = dup + Severity = Some Lsp.DiagnosticSeverity.Warning + Code = Some(code diag) + CodeDescription = None + Source = Some "Marksman" + Message = "Non-breaking whitespace used instead of regular whitespace. This line won't be interpreted as a heading" - RelatedInformation = None - Tags = None - Data = None } + RelatedInformation = None + Tags = None + Data = None + } type FolderDiag = array> diff --git a/Marksman/Doc.fs b/Marksman/Doc.fs index b1d412b..606e4a9 100644 --- a/Marksman/Doc.fs +++ b/Marksman/Doc.fs @@ -16,12 +16,13 @@ open Marksman.Structure open Marksman.Cst [] -type Doc = - { id: DocId - version: option - text: Text - structure: Structure - index: Index } +type Doc = { + id: DocId + version: option + text: Text + structure: Structure + index: Index +} with member this.RootPath = RootedRelPath.rootPath this.id.Path @@ -65,11 +66,13 @@ module Doc = let structure = Parser.parse exts text let index = Index.ofCst (Structure.concreteElements structure) - { id = id - version = version - text = text - structure = structure - index = index } + { + id = id + version = version + text = text + structure = structure + index = index + } let id { id = id } = id let text doc = doc.text @@ -78,10 +81,12 @@ module Doc = let newStructure = Parser.parse exts newText let newIndex = Index.ofCst (Structure.concreteElements newStructure) - { doc with - text = newText - structure = newStructure - index = newIndex } + { + doc with + text = newText + structure = newStructure + index = newIndex + } let applyLspChange exts (change: DidChangeTextDocumentParams) (doc: Doc) : Doc = diff --git a/Marksman/Folder.fs b/Marksman/Folder.fs index cdb2eac..81ab2eb 100644 --- a/Marksman/Folder.fs +++ b/Marksman/Folder.fs @@ -16,11 +16,12 @@ open Marksman.Paths open Marksman.MMap open Marksman.Syms -type MultiFile = - { name: string - root: FolderId - docs: Map - config: option } +type MultiFile = { + name: string + root: FolderId + docs: Map + config: option +} with member this.RootPath = this.root.data @@ -87,10 +88,11 @@ module FolderData = mapping -type FolderLookup = - { docsBySlug: Map> - docsByPath: SuffixTree - config: option } +type FolderLookup = { + docsBySlug: Map> + docsByPath: SuffixTree + config: option +} module FolderLookup = let ofData (data: FolderData) = @@ -358,9 +360,9 @@ module Folder = Seq.empty - collect - (RootPath.toLocal folderId.data) - [ GlobMatcher.mkDefault (RootPath.toSystem folderId.data) ] + collect (RootPath.toLocal folderId.data) [ + GlobMatcher.mkDefault (RootPath.toSystem folderId.data) + ] let private tryLoadFolderConfig (folderId: FolderId) : option = let folderConfigPath = @@ -416,10 +418,12 @@ module Folder = let idsUnchanged = idsBoth - idsChanged - { added = idsAdded - removed = idsRemoved - changed = idsChanged - unchanged = idsUnchanged } + { + added = idsAdded + removed = idsRemoved + changed = idsChanged + unchanged = idsUnchanged + } let symsDifference (before: Folder) (after: Folder) = let docsDifference = docsDifference before after diff --git a/Marksman/GitIgnore.fs b/Marksman/GitIgnore.fs index 3619d67..d0672de 100644 --- a/Marksman/GitIgnore.fs +++ b/Marksman/GitIgnore.fs @@ -25,8 +25,10 @@ let patternToGlob (pat: string) : array = try if isDir then - [| Glob(pat + "**", opts) - Glob(pat.Substring(0, pat.Length - 1), opts) |] + [| + Glob(pat + "**", opts) + Glob(pat.Substring(0, pat.Length - 1), opts) + |] else [| Glob(pat, opts) |] with :? GlobPatternException -> diff --git a/Marksman/Graph.fs b/Marksman/Graph.fs index 3e73734..86d4b74 100644 --- a/Marksman/Graph.fs +++ b/Marksman/Graph.fs @@ -6,8 +6,9 @@ open Marksman.Misc /// Undirected graph type Graph<'V> when 'V: comparison = { edges: MMap<'V, 'V> } -type GraphDifference<'V> when 'V: comparison = - { edgeDifference: Difference<'V * 'V> } +type GraphDifference<'V> when 'V: comparison = { + edgeDifference: Difference<'V * 'V> +} with member this.IsEmpty() = Difference.isEmpty this.edgeDifference diff --git a/Marksman/Index.fs b/Marksman/Index.fs index 14da94b..0f73768 100644 --- a/Marksman/Index.fs +++ b/Marksman/Index.fs @@ -7,15 +7,16 @@ open Marksman.Misc type Dictionary<'K, 'V> = System.Collections.Generic.Dictionary<'K, 'V> -type Index = - { titles: array> - headings: array> - headingsBySlug: Map>> - wikiLinks: array> - mdLinks: array> - linkDefs: array> - tags: array> - yamlFrontMatter: option } +type Index = { + titles: array> + headings: array> + headingsBySlug: Map>> + wikiLinks: array> + mdLinks: array> + linkDefs: array> + tags: array> + yamlFrontMatter: option +} module Index = let ofCst (cels: Cst.Element[]) : Index = @@ -62,14 +63,16 @@ module Index = let headings = headings.ToArray() let tags = tags.ToArray() - { titles = titles - headings = headings - headingsBySlug = headingsBySlug - wikiLinks = wikiLinks - mdLinks = mdLinks - linkDefs = linkDefs - tags = tags - yamlFrontMatter = yaml } + { + titles = titles + headings = headings + headingsBySlug = headingsBySlug + wikiLinks = wikiLinks + mdLinks = mdLinks + linkDefs = linkDefs + tags = tags + yamlFrontMatter = yaml + } let titles index = index.titles diff --git a/Marksman/Lenses.fs b/Marksman/Lenses.fs index 02053b8..2d032a6 100644 --- a/Marksman/Lenses.fs +++ b/Marksman/Lenses.fs @@ -22,22 +22,23 @@ let buildReferenceLens (client: ClientDescription) (folder: Folder) (doc: Doc) ( if refCount > 0 then let data = if client.SupportsLensFindReferences then - let locations = - [| for doc, el in refs -> { Uri = Doc.uri doc; Range = el.Range } |] + let locations = [| for doc, el in refs -> { Uri = Doc.uri doc; Range = el.Range } |] - let data = - { Uri = Doc.uri doc - Position = el.Range.Start - Locations = locations } + let data = { + Uri = Doc.uri doc + Position = el.Range.Start + Locations = locations + } Some [| LspServer.serialize data |] else None - let command = - { Title = humanRefCount refCount - Command = findReferencesLens - Arguments = data } + let command = { + Title = humanRefCount refCount + Command = findReferencesLens + Arguments = data + } Some { Range = el.Range; Command = Some command; Data = None } diff --git a/Marksman/MMap.fs b/Marksman/MMap.fs index 9075bfa..99e6d75 100644 --- a/Marksman/MMap.fs +++ b/Marksman/MMap.fs @@ -4,10 +4,11 @@ open Marksman.Misc type MMap<'K, 'V> when 'K: comparison and 'V: comparison = MMap of Map<'K, Set<'V>> -type MMapDifference<'K, 'V> when 'K: comparison and 'V: comparison = - { removedKeys: Set<'K> - addedKeys: Set<'K> - changedKeys: array<'K * Difference<'V>> } +type MMapDifference<'K, 'V> when 'K: comparison and 'V: comparison = { + removedKeys: Set<'K> + addedKeys: Set<'K> + changedKeys: array<'K * Difference<'V>> +} with member this.IsEmpty() = Set.isEmpty this.removedKeys diff --git a/Marksman/Mapping.fs b/Marksman/Mapping.fs index 863d15c..43e419b 100644 --- a/Marksman/Mapping.fs +++ b/Marksman/Mapping.fs @@ -2,8 +2,10 @@ module Marksman.Mapping open Marksman.MMap -type Mapping<'Dom, 'Cod> when 'Dom: comparison and 'Cod: comparison = - { mapping: Map<'Dom, 'Cod>; inverse: MMap<'Cod, 'Dom> } +type Mapping<'Dom, 'Cod> when 'Dom: comparison and 'Cod: comparison = { + mapping: Map<'Dom, 'Cod> + inverse: MMap<'Cod, 'Dom> +} module Mapping = let empty = { mapping = Map.empty; inverse = MMap.empty } diff --git a/Marksman/Misc.fs b/Marksman/Misc.fs index 3f7193b..19ad7cf 100644 --- a/Marksman/Misc.fs +++ b/Marksman/Misc.fs @@ -230,9 +230,10 @@ type Position with type Range with - static member Mk(startLine: int, startChar: int, endLine: int, endChar: int) : Range = - { Start = Position.Mk(startLine, startChar) - End = Position.Mk(endLine, endChar) } + static member Mk(startLine: int, startChar: int, endLine: int, endChar: int) : Range = { + Start = Position.Mk(startLine, startChar) + End = Position.Mk(endLine, endChar) + } static member Mk(start: Position, end_: Position) : Range = { Start = start; End = end_ } @@ -279,9 +280,10 @@ type Indented<'A> = member this.AsString = this.ToString() -type Difference<'A> when 'A: comparison = - { added: Set<'A> - removed: Set<'A> } +type Difference<'A> when 'A: comparison = { + added: Set<'A> + removed: Set<'A> +} with member this.CompactFormat() = let lines = @@ -312,11 +314,14 @@ module Difference = { added = after - before; removed = before - after } - let map f { added = added; removed = removed } = - { added = Set.map f added; removed = Set.map f removed } - -type FullDifference<'A> when 'A: comparison = - { added: Set<'A> - removed: Set<'A> - changed: Set<'A> - unchanged: Set<'A> } + let map f { added = added; removed = removed } = { + added = Set.map f added + removed = Set.map f removed + } + +type FullDifference<'A> when 'A: comparison = { + added: Set<'A> + removed: Set<'A> + changed: Set<'A> + unchanged: Set<'A> +} diff --git a/Marksman/Parser.fs b/Marksman/Parser.fs index 18675e8..4ef4804 100644 --- a/Marksman/Parser.fs +++ b/Marksman/Parser.fs @@ -210,8 +210,10 @@ module Markdown = let endInclusive = text.lineMap.FindPosition(span.End) let endOffset = if Char.IsSurrogate(text.content, span.End) then 2 else 1 - { Start = start - End = { endInclusive with Character = endInclusive.Character + endOffset } } + { + Start = start + End = { endInclusive with Character = endInclusive.Character + endOffset } + } let scrapeText (text: Text) : array = @@ -246,10 +248,11 @@ module Markdown = let range = sourceSpanToRange text h.Span let heading = - Node.mk - fullText - range - { level = level; title = Node.mkText title titleRange; scope = range } + Node.mk fullText range { + level = level + title = Node.mkText title titleRange + scope = range + } elements.Add(H heading) | :? WikiLinkInline as link -> diff --git a/Marksman/Paths.fsi b/Marksman/Paths.fsi index ccf9928..bbc0d8a 100644 --- a/Marksman/Paths.fsi +++ b/Marksman/Paths.fsi @@ -67,10 +67,10 @@ module RootPath = val filenameStem: RootPath -> string [] -type RootedRelPath = - private - { root: RootPath - path: option } +type RootedRelPath = private { + root: RootPath + path: option +} module RootedRelPath = val mk: RootPath -> LocalPath -> RootedRelPath diff --git a/Marksman/Refactor.fs b/Marksman/Refactor.fs index 5469461..93e6b9e 100644 --- a/Marksman/Refactor.fs +++ b/Marksman/Refactor.fs @@ -57,8 +57,10 @@ let mkWorkspaceEdit if supportsDocumentEdit then { Changes = None; DocumentChanges = Some docChanges } else - { Changes = Some(WorkspaceEdit.DocumentChangesToChanges docChanges) - DocumentChanges = None } + { + Changes = Some(WorkspaceEdit.DocumentChangesToChanges docChanges) + DocumentChanges = None + } let renameMarkdownLabel (newLabel: string) (element: Element) : option = match element with @@ -113,8 +115,10 @@ let renameHeadingLink let toEdit = if Element.isTitle srcHeading then wl.doc else wl.heading toEdit - |> Option.map (fun node -> - { Range = node.range; NewText = WikiEncoded.encodeAsString newTitle }) + |> Option.map (fun node -> { + Range = node.range + NewText = WikiEncoded.encodeAsString newTitle + }) | ML { data = MdLink.IL(_, url, _) } -> let docUrl = url |> Option.map Url.ofUrlNode diff --git a/Marksman/Refs.fsi b/Marksman/Refs.fsi index c3b8fa4..1da63f9 100644 --- a/Marksman/Refs.fsi +++ b/Marksman/Refs.fsi @@ -20,10 +20,11 @@ type FileLinkKind = module FileLinkKind = val detect: ComplWikiStyle -> DocId -> string -> (Doc -> FileLinkKind) -type FileLink = - { link: string - kind: FileLinkKind - doc: Doc } +type FileLink = { + link: string + kind: FileLinkKind + doc: Doc +} module FileLink = val doc: FileLink -> Doc diff --git a/Marksman/Semato.fs b/Marksman/Semato.fs index daf13a1..8e28460 100644 --- a/Marksman/Semato.fs +++ b/Marksman/Semato.fs @@ -27,9 +27,10 @@ module TokenType = let mapping = [| WikiLink; RefLink; Tag |] |> Array.map toLspName -type Token = - { range: Range - typ: TokenType } +type Token = { + range: Range + typ: TokenType +} with override this.ToString() = $"{this.typ}@{this.range}" @@ -61,11 +62,13 @@ module Token = deltaLine, deltaChar - [| uint32 deltaLine - uint32 deltaChar - uint32 (lenSingleLine curTok) - TokenType.toNum curTok.typ - Modifiers |] + [| + uint32 deltaLine + uint32 deltaChar + uint32 (lenSingleLine curTok) + TokenType.toNum curTok.typ + Modifiers + |] let encodeAll (tokens: seq) : array = let tokens = diff --git a/Marksman/Server.fs b/Marksman/Server.fs index 1c2337f..ce710b4 100644 --- a/Marksman/Server.fs +++ b/Marksman/Server.fs @@ -118,21 +118,25 @@ module ServerUtil = (textSyncKind: TextSync) (par: InitializeParams) : ServerCapabilities = - let workspaceFoldersCaps = - { Supported = Some true; ChangeNotifications = Some(Second true) } + let workspaceFoldersCaps = { + Supported = Some true + ChangeNotifications = Some(Second true) + } let glob = mkWatchGlob markdownExts - let markdownFilePattern = - { Glob = glob - Matches = Some FileOperationPatternKind.File - Options = Some { IgnoreCase = Some true } } + let markdownFilePattern = { + Glob = glob + Matches = Some FileOperationPatternKind.File + Options = Some { IgnoreCase = Some true } + } - let markdownFileRegistration = - { Filters = [| { Scheme = None; Pattern = markdownFilePattern } |] } + let markdownFileRegistration = { + Filters = [| { Scheme = None; Pattern = markdownFilePattern } |] + } - let workspaceFileCaps = - { WorkspaceFileOperationsServerCapabilities.Default with + let workspaceFileCaps = { + WorkspaceFileOperationsServerCapabilities.Default with DidCreate = Some markdownFileRegistration DidDelete = Some markdownFileRegistration // VSCode behaves weirdly when communicating file renames, so let's turn this off. @@ -140,27 +144,29 @@ module ServerUtil = // - didClose on the old name, and // - didOpen on the new one // which is enough to keep the state in sync. - DidRename = None } + DidRename = None + } - let workspaceCaps = - { WorkspaceFolders = Some workspaceFoldersCaps - FileOperations = Some workspaceFileCaps } + let workspaceCaps = { + WorkspaceFolders = Some workspaceFoldersCaps + FileOperations = Some workspaceFileCaps + } let syncKind = match textSyncKind with | Full -> TextDocumentSyncKind.Full | Incremental -> TextDocumentSyncKind.Incremental - let textSyncCaps = - { TextDocumentSyncOptions.Default with + let textSyncCaps = { + TextDocumentSyncOptions.Default with OpenClose = Some true - Change = Some syncKind } + Change = Some syncKind + } let clientDesc = ClientDescription.ofParams par - let codeActionOptions = - { CodeActionKinds = None; ResolveProvider = Some false } + let codeActionOptions = { CodeActionKinds = None; ResolveProvider = Some false } let renameOptions = if clientDesc.SupportsPrepareRename then @@ -168,29 +174,33 @@ module ServerUtil = else Some(U2.First true) - { ServerCapabilities.Default with - Workspace = Some workspaceCaps - WorkspaceSymbolProvider = Some(First <| not clientDesc.IsVSCode) - TextDocumentSync = Some textSyncCaps - DocumentSymbolProvider = Some(First <| not clientDesc.IsVSCode) - CompletionProvider = - Some - { TriggerCharacters = Some [| '['; '#'; '(' |] - ResolveProvider = None - AllCommitCharacters = None - CompletionItem = None } - DefinitionProvider = Some true - HoverProvider = Some true - ReferencesProvider = Some true - CodeActionProvider = Some(Second codeActionOptions) - SemanticTokensProvider = - Some - { Legend = { TokenTypes = Semato.TokenType.mapping; TokenModifiers = [||] } - Range = Some true - Full = { Delta = Some false } |> U2.Second |> Some } - RenameProvider = renameOptions - CodeLensProvider = Some { ResolveProvider = None } - ExecuteCommandProvider = Some { commands = Some [||] } } + { + ServerCapabilities.Default with + Workspace = Some workspaceCaps + WorkspaceSymbolProvider = Some(First <| not clientDesc.IsVSCode) + TextDocumentSync = Some textSyncCaps + DocumentSymbolProvider = Some(First <| not clientDesc.IsVSCode) + CompletionProvider = + Some { + TriggerCharacters = Some [| '['; '#'; '(' |] + ResolveProvider = None + AllCommitCharacters = None + CompletionItem = None + } + DefinitionProvider = Some true + HoverProvider = Some true + ReferencesProvider = Some true + CodeActionProvider = Some(Second codeActionOptions) + SemanticTokensProvider = + Some { + Legend = { TokenTypes = Semato.TokenType.mapping; TokenModifiers = [||] } + Range = Some true + Full = { Delta = Some false } |> U2.Second |> Some + } + RenameProvider = renameOptions + CodeLensProvider = Some { ResolveProvider = None } + ExecuteCommandProvider = Some { commands = Some [||] } + } type MarksmanStatusParams = { state: string; docCount: int } @@ -270,8 +280,11 @@ let calcDiagnosticsUpdate ) // TODO: check how the behavior changes when we supply the document version here - let publishParams = - { Uri = docUri.Uri; Diagnostics = newDocDiag; Version = None } + let publishParams = { + Uri = docUri.Uri + Diagnostics = newDocDiag + Version = None + } yield publishParams } @@ -569,8 +582,7 @@ type MarksmanServer(client: MarksmanClient) = let serverCaps = ServerUtil.mkServerCaps configuredExts textSyncKind par - let initResult = - { InitializeResult.Default with Capabilities = serverCaps } + let initResult = { InitializeResult.Default with Capabilities = serverCaps } logger.debug ( Log.setMessage @@ -804,9 +816,11 @@ type MarksmanServer(client: MarksmanClient) = | candidates -> let isIncomplete = Array.length candidates >= maxCompletions - { IsIncomplete = isIncomplete - Items = candidates - ItemDefaults = None } + { + IsIncomplete = isIncomplete + Items = candidates + ItemDefaults = None + } } LspResult.success candidates @@ -825,8 +839,10 @@ type MarksmanServer(client: MarksmanClient) = let locs = refs - |> Seq.map (fun ref -> - { Uri = ref |> Dest.doc |> Doc.uri; Range = (Dest.range ref) }) + |> Seq.map (fun ref -> { + Uri = ref |> Dest.doc |> Doc.uri + Range = (Dest.range ref) + }) |> Array.ofSeq if locs.Length = 0 then return! None @@ -929,15 +945,16 @@ type MarksmanServer(client: MarksmanClient) = <| fun state -> let docPath = opts.TextDocument.Uri |> UriWith.mkAbs - let codeAction title kind edit = - { Title = title - Kind = kind - Diagnostics = None - Command = None - Data = None - IsPreferred = Some false - Disabled = None - Edit = Some edit } + let codeAction title kind edit = { + Title = title + Kind = kind + Diagnostics = None + Command = None + Data = None + IsPreferred = Some false + Disabled = None + Edit = Some edit + } match State.tryFindFolderAndDoc docPath state with | None -> Mutation.output (LspResult.success None) diff --git a/Marksman/State.fs b/Marksman/State.fs index 0c73842..f1096da 100644 --- a/Marksman/State.fs +++ b/Marksman/State.fs @@ -38,10 +38,11 @@ module InitOptions = { preferredTextSyncKind = kind } -type ClientDescription = - { info: ClientInfo option - caps: ClientCapabilities - opts: InitOptions } +type ClientDescription = { + info: ClientInfo option + caps: ClientCapabilities + opts: InitOptions +} with member this.IsVSCode: bool = this.info |> Option.exists (fun x -> x.Name = "Visual Studio Code") @@ -89,15 +90,17 @@ type ClientDescription = this.opts.preferredTextSyncKind module ClientDescription = - let empty = - { info = None - caps = - { Workspace = None - TextDocument = None - General = None - Experimental = None - Window = None } - opts = InitOptions.empty } + let empty = { + info = None + caps = { + Workspace = None + TextDocument = None + General = None + Experimental = None + Window = None + } + opts = InitOptions.empty + } let ofParams (par: InitializeParams) : ClientDescription = let caps = par.Capabilities |> Option.defaultValue empty.caps @@ -109,19 +112,22 @@ module ClientDescription = { info = par.ClientInfo; caps = caps; opts = opts } -type State = - private - { client: ClientDescription - workspace: Workspace - revision: int } +type State = private { + client: ClientDescription + workspace: Workspace + revision: int +} with member this.Diag() : WorkspaceDiag = WorkspaceDiag.mk this.workspace module State = let private logger = LogProvider.getLoggerByName "State" - let mk (client: ClientDescription) (ws: Workspace) = - { client = client; workspace = ws; revision = 0 } + let mk (client: ClientDescription) (ws: Workspace) = { + client = client + workspace = ws + revision = 0 + } let client s = s.client @@ -185,9 +191,11 @@ module State = Workspace.withoutFolders removedUris state.workspace |> Workspace.withFolders addedFolders - { client = state.client - workspace = newWorkspace - revision = state.revision + 1 } + { + client = state.client + workspace = newWorkspace + revision = state.revision + 1 + } let updateFolder (newFolder: Folder) (state: State) : State = let newWs = Workspace.withFolder newFolder state.workspace diff --git a/Marksman/Structure.fs b/Marksman/Structure.fs index 7028462..cd54b55 100644 --- a/Marksman/Structure.fs +++ b/Marksman/Structure.fs @@ -5,13 +5,13 @@ open FSharpPlus.GenericBuilders open Marksman.Syms open Marksman.Mapping -type Structure = - private - { cst: Cst.Cst - ast: Ast.Ast - sym: Set - c2a: Mapping - a2s: Mapping } +type Structure = private { + cst: Cst.Cst + ast: Ast.Ast + sym: Set + c2a: Mapping + a2s: Mapping +} with member this.Cst = this.cst member this.Ast = this.ast @@ -92,8 +92,10 @@ module Structure = let ast: Ast.Ast = { elements = abs.ToArray() } - { cst = cst - ast = ast - sym = syms.ToArray() |> Set.ofArray - c2a = c2a - a2s = a2s } + { + cst = cst + ast = ast + sym = syms.ToArray() |> Set.ofArray + c2a = c2a + a2s = a2s + } diff --git a/Marksman/SuffixTree.fs b/Marksman/SuffixTree.fs index 4f5ce54..b19cac9 100644 --- a/Marksman/SuffixTree.fs +++ b/Marksman/SuffixTree.fs @@ -1,8 +1,10 @@ module Marksman.SuffixTree module Impl = - type SuffixTree<'K, 'V> when 'K: comparison = - { nodes: Map<'K, SuffixTree<'K, 'V>>; value: option<'V> } + type SuffixTree<'K, 'V> when 'K: comparison = { + nodes: Map<'K, SuffixTree<'K, 'V>> + value: option<'V> + } let empty = { nodes = Map.empty; value = None } @@ -69,10 +71,10 @@ module Impl = st |> collectValues [] -type SuffixTree<'K, 'V> when 'V: equality = - private - { splitFn: 'K -> list - tree: Impl.SuffixTree } +type SuffixTree<'K, 'V> when 'V: equality = private { + splitFn: 'K -> list + tree: Impl.SuffixTree +} with override this.Equals(other) = match other with diff --git a/Marksman/Symbols.fs b/Marksman/Symbols.fs index 690836f..9cd6fd9 100644 --- a/Marksman/Symbols.fs +++ b/Marksman/Symbols.fs @@ -19,13 +19,14 @@ let tagToSymbolInfo (docUri: DocId) (t: Node) : SymbolInformation = let kind = SymbolKind.String let location = { Uri = docUri.Uri; Range = t.range } - let sym = - { Name = name - Kind = kind - Location = location - ContainerName = None - Tags = None - Deprecated = None } + let sym = { + Name = name + Kind = kind + Location = location + ContainerName = None + Tags = None + Deprecated = None + } sym @@ -34,13 +35,14 @@ let headingToSymbolInfo (docUri: DocId) (h: Node) : SymbolInformation = let kind = SymbolKind.String let location = { Uri = docUri.Uri; Range = h.range } - let sym = - { Name = name - Kind = kind - Location = location - ContainerName = None - Tags = None - Deprecated = None } + let sym = { + Name = name + Kind = kind + Location = location + ContainerName = None + Tags = None + Deprecated = None + } sym @@ -49,14 +51,16 @@ let rec tagToDocumentSymbol (t: Node) : DocumentSymbol = let kind = SymbolKind.String let range = t.range - { Name = name - Detail = None - Kind = kind - Range = range - SelectionRange = range - Children = None - Tags = None - Deprecated = None } + { + Name = name + Detail = None + Kind = kind + Range = range + SelectionRange = range + Children = None + Tags = None + Deprecated = None + } let rec headingToDocumentSymbol (isEmacs: bool) (cst: Cst) (h: Node) : DocumentSymbol = let name = Heading.name h.data @@ -81,28 +85,31 @@ let rec headingToDocumentSymbol (isEmacs: bool) (cst: Cst) (h: Node) : // Emacs' imenu with consult/counsel/etc. doesn't allow selecting intermediate // nodes that have children. As a workaround we add a '.' this node. else if isEmacs then - let thisHeading = - { Name = "." - Detail = None - Kind = kind - Range = selectionRange - SelectionRange = selectionRange - Children = None - Tags = None - Deprecated = None } + let thisHeading = { + Name = "." + Detail = None + Kind = kind + Range = selectionRange + SelectionRange = selectionRange + Children = None + Tags = None + Deprecated = None + } Some(Array.append [| thisHeading |] children) else Some children - { Name = name - Detail = None - Kind = kind - Range = range - SelectionRange = selectionRange - Children = children - Tags = None - Deprecated = None } + { + Name = name + Detail = None + Kind = kind + Range = range + SelectionRange = selectionRange + Children = children + Tags = None + Deprecated = None + } let docSymbols (hierarchy: bool) diff --git a/Marksman/Text.fs b/Marksman/Text.fs index 167dffb..912330b 100644 --- a/Marksman/Text.fs +++ b/Marksman/Text.fs @@ -70,9 +70,10 @@ type LineMap = [] -type Text = - { content: string - lineMap: LineMap } +type Text = { + content: string + lineMap: LineMap +} with override this.Equals(other: obj) = match other with @@ -222,14 +223,13 @@ let private applyChangeOne (text: Text) (change: TextDocumentContentChangeEvent) let applyTextChange (changeEvents: array) (text: Text) : Text = Array.fold applyChangeOne text changeEvents -type Span = - { - text: Text - /// Inclusive - start: int - /// Exclusive - end_: int - } +type Span = { + text: Text + /// Inclusive + start: int + /// Exclusive + end_: int +} with override this.ToString() = let substr = @@ -244,9 +244,10 @@ type Span = $"start={this.start}; end={this.end_}; substr={substr}" -type Cursor = - { span: Span - pos: int } +type Cursor = { + span: Span + pos: int +} with override this.ToString() = $"{this.span.text.content[this.pos]} @ {this.pos} : {this.span}" @@ -362,9 +363,10 @@ module Span = let startChar = startCursor >> (Option.map Cursor.char) -type Line = - { text: Text - line: int } +type Line = { + text: Text + line: int +} with override this.ToString() = $"Line {this.line}: {this.text}" diff --git a/Marksman/Toc.fs b/Marksman/Toc.fs index ecda703..0427d57 100644 --- a/Marksman/Toc.fs +++ b/Marksman/Toc.fs @@ -24,8 +24,11 @@ type EntryLevel = int type Entry = { level: EntryLevel; title: Title; link: Slug } module Entry = - let Mk (level: EntryLevel, title: Title) = - { level = level; title = title; link = Slug.ofString title } + let Mk (level: EntryLevel, title: Title) = { + level = level + title = title + link = Slug.ofString title + } let renderLink entry minLevel = let offset = String.replicate (entry.level - minLevel) " " diff --git a/Marksman/Workspace.fs b/Marksman/Workspace.fs index ddfd189..07f2a1b 100644 --- a/Marksman/Workspace.fs +++ b/Marksman/Workspace.fs @@ -17,8 +17,10 @@ module Workspace = let ofFolders (userConfig: option) (folders: seq) : Workspace = let folders = folders |> Seq.map (mergeFolderConfig userConfig) - { config = userConfig - folders = folders |> Seq.map (fun f -> Folder.id f, f) |> Map.ofSeq } + { + config = userConfig + folders = folders |> Seq.map (fun f -> Folder.id f, f) |> Map.ofSeq + } let folders (workspace: Workspace) : seq = seq { @@ -38,8 +40,10 @@ module Workspace = else None) - let withoutFolder (keyPath: FolderId) (workspace: Workspace) : Workspace = - { workspace with folders = Map.remove keyPath workspace.folders } + let withoutFolder (keyPath: FolderId) (workspace: Workspace) : Workspace = { + workspace with + folders = Map.remove keyPath workspace.folders + } let withoutFolders (roots: seq) (workspace: Workspace) : Workspace = let newFolders = roots |> Seq.fold (flip Map.remove) workspace.folders diff --git a/Tests/AstTests.fs b/Tests/AstTests.fs index 6397c4e..56f5d37 100644 --- a/Tests/AstTests.fs +++ b/Tests/AstTests.fs @@ -32,16 +32,16 @@ let ast1 = struct1.Ast [] let testAstShape () = - checkInlineSnapshot - ast1.elements - [ "# Doc 1 {doc-1}" - "[collapsedRef][]" - "[[wiki-link]]" - "## Sub 1 {sub-1}" - "[inline-link](url)" - "## Sub 2 {sub-2}" - "#tag" - "[collapsedRef]: DefURL" ] + checkInlineSnapshot ast1.elements [ + "# Doc 1 {doc-1}" + "[collapsedRef][]" + "[[wiki-link]]" + "## Sub 1 {sub-1}" + "[inline-link](url)" + "## Sub 2 {sub-2}" + "#tag" + "[collapsedRef]: DefURL" + ] [] let testAstLookup () = @@ -51,12 +51,11 @@ let testAstLookup () = let csub1 = (Structure.findConcreteForAbstract sub1 struct1) |> Array.ofSeq - Helpers.checkInlineSnapshot - Cst.Element.fmt - csub1 - [ "H2: range=(4,0)-(4,8); scope=(4,0)-(8,0)" - " text=`## Sub 1`" - " title=`Sub 1` @ (4,3)-(4,8)" ] + Helpers.checkInlineSnapshot Cst.Element.fmt csub1 [ + "H2: range=(4,0)-(4,8); scope=(4,0)-(8,0)" + " text=`## Sub 1`" + " title=`Sub 1` @ (4,3)-(4,8)" + ] let shouldBeSub1 = Structure.findMatchingAbstract csub1[0] struct1 Assert.Equal(sub1, shouldBeSub1) diff --git a/Tests/ComplTests.fs b/Tests/ComplTests.fs index 24190e0..c8d9954 100644 --- a/Tests/ComplTests.fs +++ b/Tests/ComplTests.fs @@ -211,10 +211,11 @@ module PartialElementInline = let anchor1 () = let text = Text.mkText "](t# other" - checkSnapshot - [ parsePartialElement text 0 2 - parsePartialElement text 0 3 - parsePartialElement text 0 4 ] + checkSnapshot [ + parsePartialElement text 0 2 + parsePartialElement text 0 3 + parsePartialElement text 0 4 + ] [] let anchor2 () = @@ -300,14 +301,16 @@ module Candidates = path = "doc1.md", contentLines = // 012345678901234567890 - [| "# H1" // 0 - "[[#" - "# A" - "## H2" // 3 - "#B" - "## H2" - "[](/doc%202.md#)" - "[[#]]" |] // 7 + [| + "# H1" // 0 + "[[#" + "# A" + "## H2" // 3 + "#B" + "## H2" + "[](/doc%202.md#)" + "[[#]]" + |] // 7 // 012345678901234567890 ) @@ -433,8 +436,7 @@ module Candidates = let doc3 = FakeDoc.Mk(path = "sub3/this is doc 3.md", contentLines = [| "# Doc 3"; "## H3" |]) - let config = - { Config.Config.Empty with complWikiStyle = Some Config.FilePathStem } + let config = { Config.Config.Empty with complWikiStyle = Some Config.FilePathStem } let folder = FakeFolder.Mk([ doc1; doc2; doc3 ], config = config) @@ -452,8 +454,7 @@ module Candidates = let doc3 = FakeDoc.Mk(path = "sub3/this is doc 3.md", contentLines = [| "# Doc 3"; "## H3" |]) - let config = - { Config.Config.Empty with complWikiStyle = Some Config.FileStem } + let config = { Config.Config.Empty with complWikiStyle = Some Config.FileStem } let folder = FakeFolder.Mk([ doc1; doc2; doc3 ], config = config) @@ -557,13 +558,14 @@ module Candidates = let doc1 = FakeDoc.Mk( path = "doc1.md", - contentLines = - [| "# Doc 1" - "## Foo / Bar" - "## Baz" - //1234 - "[[#f" - "" |] + contentLines = [| + "# Doc 1" + "## Foo / Bar" + "## Baz" + //1234 + "[[#f" + "" + |] ) let folder = FakeFolder.Mk([ doc1 ]) @@ -584,8 +586,7 @@ module Candidates = // 0123456789012345 FakeDoc.Mk(path = "doc2.md", contentLines = [| "[[blah%23blah#]]" |]) - let config = - { Config.Config.Empty with complWikiStyle = Some Config.FileStem } + let config = { Config.Config.Empty with complWikiStyle = Some Config.FileStem } let folder = FakeFolder.Mk([ doc1; doc2 ], config) @@ -596,12 +597,13 @@ module Candidates = let doc1 = FakeDoc.Mk( path = "doc1.md", - contentLines = - [| "We have #tag and #anotherTag" - //12345678901234567 - "And an opening # " - //12345678901234567 - "And partial #ta " |] + contentLines = [| + "We have #tag and #anotherTag" + //12345678901234567 + "And an opening # " + //12345678901234567 + "And partial #ta " + |] ) let doc2 = diff --git a/Tests/ConnTest.fs b/Tests/ConnTest.fs index 2a7ecb1..d0055bb 100644 --- a/Tests/ConnTest.fs +++ b/Tests/ConnTest.fs @@ -14,59 +14,63 @@ open Marksman.Conn let d1 = FakeDoc.Mk( path = "d1.md", - contentLines = - [| "# Doc 1" // - "" - "## D1.S1" - "" - "[[doc-2]]" - "[[doc-NA]]" - "" |] + contentLines = [| + "# Doc 1" // + "" + "## D1.S1" + "" + "[[doc-2]]" + "[[doc-NA]]" + "" + |] ) let d1_dup = FakeDoc.Mk( path = "d1_dup.md", - contentLines = - [| "# Doc 1" // - "" - "[[doc-2]]" - "" |] + contentLines = [| + "# Doc 1" // + "" + "[[doc-2]]" + "" + |] ) let d2 = FakeDoc.Mk( path = "d2.md", - contentLines = - [| "# Doc 2" // - "[[doc-1]]" - "[[doc-1#d1s1]]" - "[[doc-NA2]]" - "" |] + contentLines = [| + "# Doc 2" // + "[[doc-1]]" + "[[doc-1#d1s1]]" + "[[doc-NA2]]" + "" + |] ) let d3 = FakeDoc.Mk( path = "d3.md", - contentLines = - [| "# Doc 3" - "" - "[link1]" - "[link1][]" - "[linkX]" - "" - "[link1]: /url1" - "" |] + contentLines = [| + "# Doc 3" + "" + "[link1]" + "[link1][]" + "[linkX]" + "" + "[link1]: /url1" + "" + |] ) let checkSnapshot (conn: Conn) = conn.CompactFormat().Lines().ShouldMatchSnapshot() -let emptyOracle = - { resolveToScope = fun _ _ -> [||] // - resolveInScope = fun _ _ -> [||] } +let emptyOracle = { + resolveToScope = fun _ _ -> [||] // + resolveInScope = fun _ _ -> [||] +} -let incrConfig = - { Config.Config.Default with coreIncrementalReferences = Some true } +let incrConfig = { Config.Config.Default with coreIncrementalReferences = Some true } let mkFolder docs = FakeFolder.Mk(config = incrConfig, docs = docs) @@ -97,9 +101,10 @@ module ConnGraphTests = let dNA = FakeDoc.Mk( path = "docNA.md", - contentLines = - [| "# Doc NA" // - "" |] + contentLines = [| + "# Doc NA" // + "" + |] ) let f2 = Folder.withDoc dNA f1 @@ -112,16 +117,17 @@ module ConnGraphTests = let d3Update = FakeDoc.Mk( path = "d3.md", - contentLines = - [| "# Doc 3" - "" - "[link1]" - "[link1][]" - "[linkX]" - "" - "[link1]: /url1" - "[linkX]: /url2" - "" |] + contentLines = [| + "# Doc 3" + "" + "[link1]" + "[link1][]" + "[linkX]" + "" + "[link1]: /url1" + "[linkX]: /url2" + "" + |] ) let f2 = Folder.withDoc d3Update f1 @@ -134,12 +140,13 @@ module ConnGraphTests = let d1Update = FakeDoc.Mk( path = "d1.md", - contentLines = - [| "# Doc 1" // - "" - "[[doc-2]]" - "[[doc-NA]]" - "" |] + contentLines = [| + "# Doc 1" // + "" + "[[doc-2]]" + "[[doc-NA]]" + "" + |] ) let f2 = Folder.withDoc d1Update f1 @@ -159,10 +166,11 @@ module ConnGraphTests = let d2 = FakeDoc.Mk(path = "fsharp.md", contentLines = [| "# FSharp"; "[[OCaml#Multicore]]" |]) - let config = - { incrConfig with + let config = { + incrConfig with complWikiStyle = Some Config.FilePathStem - coreParanoid = Some true } + coreParanoid = Some true + } let incr = FakeFolder.Mk(docs = [ d1; d2 ], config = config) diff --git a/Tests/DiagTest.fs b/Tests/DiagTest.fs index 98b8a4c..80cc149 100644 --- a/Tests/DiagTest.fs +++ b/Tests/DiagTest.fs @@ -68,19 +68,23 @@ let noDiagOnRealUrls () = let noDiagOnNonMarkdownFiles () = let doc = FakeDoc.Mk( - [| "# H1" - "## H2" - "[](bad.md)" - "[](another%20bad.md)" - "[](good/folder)" |] + [| + "# H1" + "## H2" + "[](bad.md)" + "[](another%20bad.md)" + "[](good/folder)" + |] ) let folder = FakeFolder.Mk([ doc ]) let diag = checkFolder folder |> diagToHuman Assert.Equal( - [ "fake.md", "Link to non-existent document 'bad.md'" - "fake.md", "Link to non-existent document 'another bad.md'" ], + [ + "fake.md", "Link to non-existent document 'bad.md'" + "fake.md", "Link to non-existent document 'another bad.md'" + ], diag ) @@ -98,15 +102,19 @@ let crossFileDiagOnBrokenWikiLinks () = let noCrossFileDiagOnSingleFileFolders () = let doc = FakeDoc.Mk( - [| "[](bad.md)" // - "[[another-bad]]" - "[bad-ref][bad-ref]" |] + [| + "[](bad.md)" // + "[[another-bad]]" + "[bad-ref][bad-ref]" + |] ) let folder = Folder.singleFile doc None let diag = checkFolder folder |> diagToHuman Assert.Equal( - [ "fake.md", "Link to non-existent link definition with the label 'bad-ref'" ], + [ + "fake.md", "Link to non-existent link definition with the label 'bad-ref'" + ], diag ) diff --git a/Tests/LensesTests.fs b/Tests/LensesTests.fs index 7f8adad..1cb179d 100644 --- a/Tests/LensesTests.fs +++ b/Tests/LensesTests.fs @@ -26,15 +26,14 @@ let basicHeaderLenses () = Lenses.forDoc ClientDescription.empty f d1 |> Array.map (fun lens -> $"{lens.Command.Value}, {lens.Range}") - checkInlineSnapshot - id - lenses - [ "{ Title = \"1 reference\"" - " Command = \"marksman.findReferences\"" - " Arguments = None }, (0,0)-(0,7)" - "{ Title = \"2 references\"" - " Command = \"marksman.findReferences\"" - " Arguments = None }, (1,0)-(1,6)" ] + checkInlineSnapshot id lenses [ + "{ Title = \"1 reference\"" + " Command = \"marksman.findReferences\"" + " Arguments = None }, (0,0)-(0,7)" + "{ Title = \"2 references\"" + " Command = \"marksman.findReferences\"" + " Arguments = None }, (1,0)-(1,6)" + ] [] let basicHeaderLenses_withCommandArguments () = @@ -49,11 +48,13 @@ let basicHeaderLenses_withCommandArguments () = let f = FakeFolder.Mk([ d1; d2 ]) - let client = - { ClientDescription.empty with - caps = - { ClientDescription.empty.caps with - Experimental = Some(JToken.Parse("""{"codeLensFindReferences": true}""")) } } + let client = { + ClientDescription.empty with + caps = { + ClientDescription.empty.caps with + Experimental = Some(JToken.Parse("""{"codeLensFindReferences": true}""")) + } + } let lensesData = Lenses.forDoc client f d1 @@ -85,9 +86,8 @@ let basicLinkDefLenses () = Lenses.forDoc ClientDescription.empty f d1 |> Array.map (fun lens -> $"{lens.Command.Value}, {lens.Range}") - checkInlineSnapshot - id - lenses - [ "{ Title = \"2 references\"" - " Command = \"marksman.findReferences\"" - " Arguments = None }, (4,0)-(4,11)" ] + checkInlineSnapshot id lenses [ + "{ Title = \"2 references\"" + " Command = \"marksman.findReferences\"" + " Arguments = None }, (4,0)-(4,11)" + ] diff --git a/Tests/ParserTests.fs b/Tests/ParserTests.fs index 58ff10c..1e87c10 100644 --- a/Tests/ParserTests.fs +++ b/Tests/ParserTests.fs @@ -75,11 +75,11 @@ module WikiLinkTests = let text = "[[note#heading]]" let document = scrapeString text - checkInlineSnapshot - document - [ "WL: [[note#heading]]; (0,0)-(0,16)" - " doc=note; (0,2)-(0,6)" - " head=heading; (0,7)-(0,14)" ] + checkInlineSnapshot document [ + "WL: [[note#heading]]; (0,0)-(0,16)" + " doc=note; (0,2)-(0,6)" + " head=heading; (0,7)-(0,14)" + ] [] let parser_xref_text_before () = @@ -117,11 +117,11 @@ module WikiLinkTests = let text = "[[T#]]" let doc = scrapeString text - checkInlineSnapshot - doc - [ "WL: [[T#]]; (0,0)-(0,6)" // - " doc=T; (0,2)-(0,3)" - " head=; (0,4)-(0,4)" ] + checkInlineSnapshot doc [ + "WL: [[T#]]; (0,0)-(0,6)" // + " doc=T; (0,2)-(0,3)" + " head=; (0,4)-(0,4)" + ] [] let parse_wiki_escaped_hash () = @@ -198,10 +198,10 @@ module MdLinkTest = let text = "[title](url)" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [title](url) @ (0,0)-(0,12)" - " IL: label=title @ (0,1)-(0,6); url=url @ (0,8)-(0,11); title=∅" ] + checkInlineSnapshot document [ + "ML: [title](url) @ (0,0)-(0,12)" + " IL: label=title @ (0,1)-(0,6); url=url @ (0,8)-(0,11); title=∅" + ] [] let parser_link_2 () = @@ -223,114 +223,114 @@ module MdLinkTest = let text = "[]()" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: []() @ (0,0)-(0,4)" - " IL: label= @ (0,0)-(0,0); url=∅; title=∅" ] + checkInlineSnapshot document [ + "ML: []() @ (0,0)-(0,4)" + " IL: label= @ (0,0)-(0,0); url=∅; title=∅" + ] [] let parser_link_5 () = let text = "[la bel](url \"title\")" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [la bel](url \"title\") @ (0,0)-(0,21)" - " IL: label=la bel @ (0,1)-(0,7); url=url @ (0,9)-(0,12); title=title @ (0,13)-(0,20)" ] + checkInlineSnapshot document [ + "ML: [la bel](url \"title\") @ (0,0)-(0,21)" + " IL: label=la bel @ (0,1)-(0,7); url=url @ (0,9)-(0,12); title=title @ (0,13)-(0,20)" + ] [] let parser_link_6 () = let text = "[la bel](url title)" // without quotation of title only the shortcut parses let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [la bel] @ (0,0)-(0,8)" // - " RS: label=la bel @ (0,1)-(0,7)" ] + checkInlineSnapshot document [ + "ML: [la bel] @ (0,0)-(0,8)" // + " RS: label=la bel @ (0,1)-(0,7)" + ] [] let parser_link_7 () = let text = "[](url)" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [](url) @ (0,0)-(0,7)" - " IL: label= @ (0,0)-(0,0); url=url @ (0,3)-(0,6); title=∅" ] + checkInlineSnapshot document [ + "ML: [](url) @ (0,0)-(0,7)" + " IL: label= @ (0,0)-(0,0); url=url @ (0,3)-(0,6); title=∅" + ] [] let parser_link_8 () = let text = "[short_cut]" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [short_cut] @ (0,0)-(0,11)" - " RS: label=short_cut @ (0,1)-(0,10)" ] + checkInlineSnapshot document [ + "ML: [short_cut] @ (0,0)-(0,11)" + " RS: label=short_cut @ (0,1)-(0,10)" + ] [] let parser_link_9 () = let text = "[short cut][]" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [short cut][] @ (0,0)-(0,13)" - " RC: label=short cut @ (0,1)-(0,10)" ] + checkInlineSnapshot document [ + "ML: [short cut][] @ (0,0)-(0,13)" + " RC: label=short cut @ (0,1)-(0,10)" + ] [] let parser_link_10 () = let text = "[label][ref]" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [label][ref] @ (0,0)-(0,12)" - " RF: text=label @ (0,1)-(0,6); label=ref @ (0,8)-(0,11)" ] + checkInlineSnapshot document [ + "ML: [label][ref] @ (0,0)-(0,12)" + " RF: text=label @ (0,1)-(0,6); label=ref @ (0,8)-(0,11)" + ] [] let parser_link_11 () = let text = "[foo]: /foo 'foo title'" let document = scrapeString text - checkInlineSnapshot - document - [ "MLD: [foo]: /foo 'foo title' @ (0,0)-(0,23)" - " label=foo @ (0,1)-(0,4); url=/foo @ (0,7)-(0,11); title=foo title @ (0,12)-(0,23)" ] + checkInlineSnapshot document [ + "MLD: [foo]: /foo 'foo title' @ (0,0)-(0,23)" + " label=foo @ (0,1)-(0,4); url=/foo @ (0,7)-(0,11); title=foo title @ (0,12)-(0,23)" + ] [] let parser_link_12 () = let text = "[foo]: /foo" let document = scrapeString text - checkInlineSnapshot - document - [ "MLD: [foo]: /foo @ (0,0)-(0,11)" - " label=foo @ (0,1)-(0,4); url=/foo @ (0,7)-(0,11); title=∅" ] + checkInlineSnapshot document [ + "MLD: [foo]: /foo @ (0,0)-(0,11)" + " label=foo @ (0,1)-(0,4); url=/foo @ (0,7)-(0,11); title=∅" + ] [] let parser_link_13 () = let text = "[foo]: /bar\nHere comes [foo]." let document = scrapeString text - checkInlineSnapshot - document - [ "MLD: [foo]: /bar @ (0,0)-(0,11)" - " label=foo @ (0,1)-(0,4); url=/bar @ (0,7)-(0,11); title=∅" - "ML: [foo] @ (1,11)-(1,16)" - " RS: label=foo @ (1,12)-(1,15)" ] + checkInlineSnapshot document [ + "MLD: [foo]: /bar @ (0,0)-(0,11)" + " label=foo @ (0,1)-(0,4); url=/bar @ (0,7)-(0,11); title=∅" + "ML: [foo] @ (1,11)-(1,16)" + " RS: label=foo @ (1,12)-(1,15)" + ] [] let parser_link_14 () = let text = "[label][ref]\n\n[ref]: https://some.url" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [label][ref] @ (0,0)-(0,12)" - " RF: text=label @ (0,1)-(0,6); label=ref @ (0,8)-(0,11)" - "MLD: [ref]: https://some.url @ (2,0)-(2,23)" - " label=ref @ (2,1)-(2,4); url=https://some.url @ (2,7)-(2,23); title=∅" ] + checkInlineSnapshot document [ + "ML: [label][ref] @ (0,0)-(0,12)" + " RF: text=label @ (0,1)-(0,6); label=ref @ (0,8)-(0,11)" + "MLD: [ref]: https://some.url @ (2,0)-(2,23)" + " label=ref @ (2,1)-(2,4); url=https://some.url @ (2,7)-(2,23); title=∅" + ] module FootnoteTests = [] @@ -338,12 +338,12 @@ module FootnoteTests = let text = "[^1]\n\n[^1]: Single line footnote" let document = scrapeString text - checkInlineSnapshot - document - [ "ML: [^1] @ (0,0)-(0,4)" - " RS: label=^1 @ (0,1)-(0,3)" - "MLD: [^1]: Footnote @ (2,0)-(2,14)" - " label=^1 @ (2,1)-(2,3); url=Footnote @ (2,6)-(2,14); title=∅" ] + checkInlineSnapshot document [ + "ML: [^1] @ (0,0)-(0,4)" + " RS: label=^1 @ (0,1)-(0,3)" + "MLD: [^1]: Footnote @ (2,0)-(2,14)" + " label=^1 @ (2,1)-(2,3); url=Footnote @ (2,6)-(2,14); title=∅" + ] module TagsTests = [] @@ -358,13 +358,13 @@ module TagsTests = let text = "(#tag\n(#tag\n(#tag)\n[?](#tag)" let cst = scrapeString text - checkInlineSnapshot - cst - [ "T: name=tag; range=(0,2)-(0,5) @ (0,1)-(0,5)" - "T: name=tag; range=(1,2)-(1,5) @ (1,1)-(1,5)" - "T: name=tag; range=(2,2)-(2,5) @ (2,1)-(2,5)" - "ML: [?](#tag) @ (3,0)-(3,9)" - " IL: label=? @ (3,1)-(3,2); url=#tag @ (3,4)-(3,8); title=∅" ] + checkInlineSnapshot cst [ + "T: name=tag; range=(0,2)-(0,5) @ (0,1)-(0,5)" + "T: name=tag; range=(1,2)-(1,5) @ (1,1)-(1,5)" + "T: name=tag; range=(2,2)-(2,5) @ (2,1)-(2,5)" + "ML: [?](#tag) @ (3,0)-(3,9)" + " IL: label=? @ (3,1)-(3,2); url=#tag @ (3,4)-(3,8); title=∅" + ] [] let tags_3 () = @@ -372,20 +372,20 @@ module TagsTests = let text = "#tag1,#tag2" let cst = scrapeString text - checkInlineSnapshot - cst - [ "T: name=tag1; range=(0,1)-(0,5) @ (0,0)-(0,5)" - "T: name=tag2; range=(0,7)-(0,11) @ (0,6)-(0,11)" ] + checkInlineSnapshot cst [ + "T: name=tag1; range=(0,1)-(0,5) @ (0,0)-(0,5)" + "T: name=tag2; range=(0,7)-(0,11) @ (0,6)-(0,11)" + ] [] let tags_nested () = let text = "#tag1/subtag1,#tag2/subtag2/subsubtag2" let cst = scrapeString text - checkInlineSnapshot - cst - [ "T: name=tag1/subtag1; range=(0,1)-(0,13) @ (0,0)-(0,13)" - "T: name=tag2/subtag2/subsubtag2; range=(0,15)-(0,38) @ (0,14)-(0,38)" ] + checkInlineSnapshot cst [ + "T: name=tag1/subtag1; range=(0,1)-(0,13) @ (0,0)-(0,13)" + "T: name=tag2/subtag2/subsubtag2; range=(0,15)-(0,38) @ (0,14)-(0,38)" + ] module DocUrlTests = let mkUrlNode str = @@ -419,13 +419,13 @@ module RegressionTests = let actual = scrapeString content - checkInlineSnapshot - actual - [ "H2: range=(2,0)-(3,1); scope=(2,0)-(4,0)" - " text=`-" - "-`" - " title=`-" - "-` @ (2,0)-(3,1)" ] + checkInlineSnapshot actual [ + "H2: range=(2,0)-(3,1); scope=(2,0)-(4,0)" + " text=`-" + "-`" + " title=`-" + "-` @ (2,0)-(3,1)" + ] [] let no235 () = @@ -443,22 +443,22 @@ module RegressionTests = let actual = scrapeString content - checkInlineSnapshot - actual - [ "ML: [ " - "'00000048', '00000681', '00000552', '00000206', '00000031', '00000303', " - "'00001268', '00000540', '00000519', '00000821', '00000731', '00001089', " - "'00000311', '00000784', '00000015', '00001052', '00000030', '00000352', " - "'00000758', '00000113', '00000152', '00000099', '00000932', '00000071', " - "'00000126', '00000450', '00000677', '00000722', '00000724', '00000182', " - "'00000507', '00000001', '00000866', '00000147', '00000186', '00000711' " - "] @ (1,0)-(8,1)" - " RS: label='00000048', '00000681', '00000552', '00000206', '00000031', '00000303', " - " '00001268', '00000540', '00000519', '00000821', '00000731', '00001089', " - " '00000311', '00000784', '00000015', '00001052', '00000030', '00000352', " - " '00000758', '00000113', '00000152', '00000099', '00000932', '00000071', " - " '00000126', '00000450', '00000677', '00000722', '00000724', '00000182', " - " '00000507', '00000001', '00000866', '00000147', '00000186', '00000711' @ (2,0)-(7,70)" ] + checkInlineSnapshot actual [ + "ML: [ " + "'00000048', '00000681', '00000552', '00000206', '00000031', '00000303', " + "'00001268', '00000540', '00000519', '00000821', '00000731', '00001089', " + "'00000311', '00000784', '00000015', '00001052', '00000030', '00000352', " + "'00000758', '00000113', '00000152', '00000099', '00000932', '00000071', " + "'00000126', '00000450', '00000677', '00000722', '00000724', '00000182', " + "'00000507', '00000001', '00000866', '00000147', '00000186', '00000711' " + "] @ (1,0)-(8,1)" + " RS: label='00000048', '00000681', '00000552', '00000206', '00000031', '00000303', " + " '00001268', '00000540', '00000519', '00000821', '00000731', '00001089', " + " '00000311', '00000784', '00000015', '00001052', '00000030', '00000352', " + " '00000758', '00000113', '00000152', '00000099', '00000932', '00000071', " + " '00000126', '00000450', '00000677', '00000722', '00000724', '00000182', " + " '00000507', '00000001', '00000866', '00000147', '00000186', '00000711' @ (2,0)-(7,70)" + ] [] let no334 () = diff --git a/Tests/PathsTests.fs b/Tests/PathsTests.fs index b0afa0f..10ca045 100644 --- a/Tests/PathsTests.fs +++ b/Tests/PathsTests.fs @@ -94,10 +94,10 @@ module PathUriTests = let id = UriWith.mkRooted root (LocalPath.ofUri uri) Assert.Equal("file:///a/b/doc.md", id.uri.ToString()) - Helpers.checkInlineSnapshot - (fun x -> x.ToString()) - (id.data.ToString().Lines()) - [ "{ root = RootPath (AbsPath \"/a/b/doc.md\")"; " path = None }" ] + Helpers.checkInlineSnapshot (fun x -> x.ToString()) (id.data.ToString().Lines()) [ + "{ root = RootPath (AbsPath \"/a/b/doc.md\")" + " path = None }" + ] [] let testAccented_issue274 () = diff --git a/Tests/RefactorTests.fs b/Tests/RefactorTests.fs index d847842..5792e27 100644 --- a/Tests/RefactorTests.fs +++ b/Tests/RefactorTests.fs @@ -39,13 +39,15 @@ module RenameTests = Helpers.FakeDoc.Mk( // 0 1 2 // 0123456789012345678901234567890 - [| "# Doc 1" - "Start [lbl1], then [lbl2]." - "Then [lbl1] again." - "And [broken] label." - "" - "[lbl1]: https://url1.com" - "[lbl2]: https://url2.com" |], + [| + "# Doc 1" + "Start [lbl1], then [lbl2]." + "Then [lbl1] again." + "And [broken] label." + "" + "[lbl1]: https://url1.com" + "[lbl2]: https://url2.com" + |], path = "doc1.md" ) @@ -60,11 +62,14 @@ module RenameTests = let res = Refactor.rename true folder doc1 pos "newLbl" let expectedRanges = - Map.ofSeq - [ "doc1.md", - [| Range.Mk(5, 1, 5, 5) - Range.Mk(2, 6, 2, 10) - Range.Mk(1, 7, 1, 11) |] ] + Map.ofSeq [ + "doc1.md", + [| + Range.Mk(5, 1, 5, 5) + Range.Mk(2, 6, 2, 10) + Range.Mk(1, 7, 1, 11) + |] + ] let actualRanges = editRanges res @@ -77,11 +82,14 @@ module RenameTests = let res = Refactor.rename true folder doc1 pos "newLbl" let expectedRanges = - Map.ofSeq - [ "doc1.md", - [| Range.Mk(5, 1, 5, 5) - Range.Mk(2, 6, 2, 10) - Range.Mk(1, 7, 1, 11) |] ] + Map.ofSeq [ + "doc1.md", + [| + Range.Mk(5, 1, 5, 5) + Range.Mk(2, 6, 2, 10) + Range.Mk(1, 7, 1, 11) + |] + ] let actualRanges = editRanges res @@ -93,11 +101,13 @@ module RenameTests = Helpers.FakeDoc.Mk( // 0 1 2 // 0123456789012345678901234567890 - [| "# Doc 1" - "## Doc 1.2" - "## Doc 1.3" - "See [[#doc-12]]" - "Also [](#doc-12)" |], + [| + "# Doc 1" + "## Doc 1.2" + "## Doc 1.3" + "See [[#doc-12]]" + "Also [](#doc-12)" + |], path = "doc1.md" ) @@ -105,12 +115,14 @@ module RenameTests = Helpers.FakeDoc.Mk( // 0 1 2 // 0123456789012345678901234567890 - [| "# Doc 2" - "[[doc-1]]" - "[[doc-1#doc-12]]" - "[](/doc1.md#doc-12)" - // filename wiki-link - "[[doc1]]" |], + [| + "# Doc 2" + "[[doc-1]]" + "[[doc-1#doc-12]]" + "[](/doc1.md#doc-12)" + // filename wiki-link + "[[doc1]]" + |], path = "doc2.md" ) @@ -125,9 +137,10 @@ module RenameTests = let res = Refactor.rename true folder doc1 pos "New Title" let expectedRanges = - Map.ofSeq - [ "doc1.md", [| Range.Mk(0, 2, 0, 7) |] - "doc2.md", [| Range.Mk(2, 2, 2, 7); Range.Mk(1, 2, 1, 7) |] ] + Map.ofSeq [ + "doc1.md", [| Range.Mk(0, 2, 0, 7) |] + "doc2.md", [| Range.Mk(2, 2, 2, 7); Range.Mk(1, 2, 1, 7) |] + ] let actualRanges = editRanges res @@ -141,12 +154,15 @@ module RenameTests = let res = Refactor.rename true folder doc1 pos "New Title" let expectedRanges = - Map.ofSeq - [ "doc1.md", - [| Range.Mk(4, 9, 4, 15) - Range.Mk(3, 7, 3, 13) - Range.Mk(1, 3, 1, 10) |] - "doc2.md", [| Range.Mk(3, 12, 3, 18); Range.Mk(2, 8, 2, 14) |] ] + Map.ofSeq [ + "doc1.md", + [| + Range.Mk(4, 9, 4, 15) + Range.Mk(3, 7, 3, 13) + Range.Mk(1, 3, 1, 10) + |] + "doc2.md", [| Range.Mk(3, 12, 3, 18); Range.Mk(2, 8, 2, 14) |] + ] let actualRanges = editRanges res diff --git a/Tests/RefsTests.fs b/Tests/RefsTests.fs index 6a30f45..4878705 100644 --- a/Tests/RefsTests.fs +++ b/Tests/RefsTests.fs @@ -153,8 +153,10 @@ module FileLinkTests = let folder = FakeFolder.Mk( [ doc1; subDoc1; subSubDoc1; doc2; subDoc2 ], - { Config.Config.Default with - complWikiStyle = Some Config.FilePathStem } + { + Config.Config.Default with + complWikiStyle = Some Config.FilePathStem + } ) let actual = @@ -215,52 +217,54 @@ module BasicRefsTests = let doc1 = FakeDoc.Mk( path = "doc1.md", - contentLines = - [| "# Doc 1" // 0 - "" // 1 - "## D1 H2.1" // 2 - "" // 3 - "[[doc-2#d2-h22]]" // 4 - "" // 5 - "## D1 H2.2" // 6 - "" // 7 - "[[#dup]]" // 8 - "" // 9 - "## Dup" // 10 - "Entry 1" // 11 - "" // 12 - "## Dup" // 13 - "Entry 2" // 14 - "" // 15 - "#tag1 #tag2" |] // 16 + contentLines = [| + "# Doc 1" // 0 + "" // 1 + "## D1 H2.1" // 2 + "" // 3 + "[[doc-2#d2-h22]]" // 4 + "" // 5 + "## D1 H2.2" // 6 + "" // 7 + "[[#dup]]" // 8 + "" // 9 + "## Dup" // 10 + "Entry 1" // 11 + "" // 12 + "## Dup" // 13 + "Entry 2" // 14 + "" // 15 + "#tag1 #tag2" + |] // 16 ) let doc2 = FakeDoc.Mk( path = "doc2.md", - contentLines = - [| "# Doc 2" // 0 - "" // 1 - "# D2 H2.1" // 2 - "" // 3 - "[D2-Link-1]" // 4 - "" // 5 - "[[#d2-h22]]" // 6 - "" // 7 - "[d2-LINK-1]" // 8 - "" // 9 - "# D2 H2.2" // 10 - "" // 11 - "[[doc-1]]" // 12 - "[[doc-1#dup]]" // 13 - "[lbl1](/doc1.md)" // 14 - "[^fn1]" // 15 - "" // 16 - "[d2-link-1]: some-url" // 17 - "" // 18 - "[^fn1]: This is footnote" // 19 - "" //20 - "#tag1" |] //21 + contentLines = [| + "# Doc 2" // 0 + "" // 1 + "# D2 H2.1" // 2 + "" // 3 + "[D2-Link-1]" // 4 + "" // 5 + "[[#d2-h22]]" // 6 + "" // 7 + "[d2-LINK-1]" // 8 + "" // 9 + "# D2 H2.2" // 10 + "" // 11 + "[[doc-1]]" // 12 + "[[doc-1#dup]]" // 13 + "[lbl1](/doc1.md)" // 14 + "[^fn1]" // 15 + "" // 16 + "[d2-link-1]: some-url" // 17 + "" // 18 + "[^fn1]: This is footnote" // 19 + "" //20 + "#tag1" + |] //21 ) let folder = FakeFolder.Mk [ doc1; doc2 ] @@ -283,10 +287,10 @@ module BasicRefsTests = let refs = Dest.findElementRefs true folder doc2 def |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc1.md, (16,0)-(16,5))"; "(doc2.md, (21,0)-(21,5))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc1.md, (16,0)-(16,5))" + "(doc2.md, (21,0)-(21,5))" + ] [] let refToLinkDef_atDef () = @@ -296,10 +300,10 @@ module BasicRefsTests = let refs = Dest.findElementRefs false folder doc2 def |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc2.md, (4,0)-(4,11))"; "(doc2.md, (8,0)-(8,11))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc2.md, (4,0)-(4,11))" + "(doc2.md, (8,0)-(8,11))" + ] [] let refToLinkDef_atDef_withDecl () = @@ -309,12 +313,11 @@ module BasicRefsTests = let refs = Dest.findElementRefs true folder doc2 def |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc2.md, (4,0)-(4,11))" - "(doc2.md, (8,0)-(8,11))" - "(doc2.md, (17,0)-(17,21))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc2.md, (4,0)-(4,11))" + "(doc2.md, (8,0)-(8,11))" + "(doc2.md, (17,0)-(17,21))" + ] [] let refToLinkDef_atLink () = @@ -324,10 +327,10 @@ module BasicRefsTests = let refs = Dest.findElementRefs false folder doc2 def |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc2.md, (4,0)-(4,11))"; "(doc2.md, (8,0)-(8,11))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc2.md, (4,0)-(4,11))" + "(doc2.md, (8,0)-(8,11))" + ] [] let refToLinkDef_atLink_withDecl () = @@ -337,12 +340,11 @@ module BasicRefsTests = let refs = Dest.findElementRefs true folder doc2 def |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc2.md, (4,0)-(4,11))" - "(doc2.md, (8,0)-(8,11))" - "(doc2.md, (17,0)-(17,21))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc2.md, (4,0)-(4,11))" + "(doc2.md, (8,0)-(8,11))" + "(doc2.md, (17,0)-(17,21))" + ] [] let refToFootnote_atLink () = @@ -352,10 +354,10 @@ module BasicRefsTests = let refs = Dest.findElementRefs true folder doc2 fnLink |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc2.md, (19,0)-(19,16))"; "(doc2.md, (15,0)-(15,6))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc2.md, (19,0)-(19,16))" + "(doc2.md, (15,0)-(15,6))" + ] [] let refToDoc_atTitle () = @@ -365,12 +367,11 @@ module BasicRefsTests = let refs = Dest.findElementRefs false folder doc1 title |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc2.md, (12,0)-(12,9))" - "(doc2.md, (13,0)-(13,13))" - "(doc2.md, (14,0)-(14,16))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc2.md, (12,0)-(12,9))" + "(doc2.md, (13,0)-(13,13))" + "(doc2.md, (14,0)-(14,16))" + ] [] let refToDoc_atTitle_withDecl () = @@ -380,13 +381,12 @@ module BasicRefsTests = let refs = Dest.findElementRefs true folder doc1 title |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc1.md, (0,0)-(0,7))" - "(doc2.md, (12,0)-(12,9))" - "(doc2.md, (13,0)-(13,13))" - "(doc2.md, (14,0)-(14,16))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc1.md, (0,0)-(0,7))" + "(doc2.md, (12,0)-(12,9))" + "(doc2.md, (13,0)-(13,13))" + "(doc2.md, (14,0)-(14,16))" + ] [] let refToDoc_atLink () = @@ -396,10 +396,10 @@ module BasicRefsTests = let refs = Dest.findElementRefs false folder doc1 wl |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc1.md, (4,0)-(4,16))"; "(doc2.md, (6,0)-(6,11))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc1.md, (4,0)-(4,16))" + "(doc2.md, (6,0)-(6,11))" + ] [] let refToDoc_atLink_withDecl () = @@ -409,26 +409,26 @@ module BasicRefsTests = let refs = Dest.findElementRefs true folder doc1 wl |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(doc1.md, (4,0)-(4,16))" - "(doc2.md, (6,0)-(6,11))" - "(doc2.md, (10,0)-(10,9))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(doc1.md, (4,0)-(4,16))" + "(doc2.md, (6,0)-(6,11))" + "(doc2.md, (10,0)-(10,9))" + ] module LinkKindRefsTests = let doc1 = FakeDoc.Mk( path = "file1.md", - contentLines = - [| "# Doc 1 Title" - "[[file2]]" - "[[file2.md]]" - "[[file2#doc-2-subtitle]]" - "[[doc-2-title]]" - "[link](file2)" - "[[file3]]" |] + contentLines = [| + "# Doc 1 Title" + "[[file2]]" + "[[file2.md]]" + "[[file2#doc-2-subtitle]]" + "[[doc-2-title]]" + "[link](file2)" + "[[file3]]" + |] ) let doc2 = @@ -448,25 +448,24 @@ module LinkKindRefsTests = let link = requireElementAtPos doc1 1 2 let refs = Dest.findElementRefs false folder doc1 link |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(file1.md, (1,0)-(1,9))" - "(file1.md, (2,0)-(2,12))" - // Referencing a doc should resolve to all sections in the doc - "(file1.md, (3,0)-(3,24))" - "(file1.md, (4,0)-(4,15))" - "(file1.md, (5,0)-(5,13))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(file1.md, (1,0)-(1,9))" + "(file1.md, (2,0)-(2,12))" + // Referencing a doc should resolve to all sections in the doc + "(file1.md, (3,0)-(3,24))" + "(file1.md, (4,0)-(4,15))" + "(file1.md, (5,0)-(5,13))" + ] [] let atWiki_Filenames_Subfolder () = let link = requireElementAtPos doc2 2 3 let refs = Dest.findElementRefs false folder doc2 link |> formatRefs - checkInlineSnapshot - (fun x -> x.ToString()) - refs - [ "(file1.md, (6,0)-(6,9))"; "(file2.md, (2,0)-(2,15))" ] + checkInlineSnapshot (fun x -> x.ToString()) refs [ + "(file1.md, (6,0)-(6,9))" + "(file2.md, (2,0)-(2,15))" + ] module EncodingTests = let doc1 = @@ -506,8 +505,10 @@ module EncodingTests = let folder = FakeFolder.Mk( [ doc1; doc2; doc3 ], - { Config.Config.Default with - complWikiStyle = Some Config.FilePathStem } + { + Config.Config.Default with + complWikiStyle = Some Config.FilePathStem + } ) let exts = (Folder.configOrDefault folder).CoreMarkdownFileExtensions() diff --git a/Tests/ServerTests.fs b/Tests/ServerTests.fs index ab559ea..e8a3d6f 100644 --- a/Tests/ServerTests.fs +++ b/Tests/ServerTests.fs @@ -26,18 +26,20 @@ module ServerUtilTests = [] let textSync_NoConfigEmptyWS_PreferIncr () = - let clientDesc = - { ClientDescription.empty with - opts = { preferredTextSyncKind = Some Incremental } } + let clientDesc = { + ClientDescription.empty with + opts = { preferredTextSyncKind = Some Incremental } + } let ws = Workspace.ofFolders None [] Assert.Equal(("clientOption", Incremental), ServerUtil.calcTextSync None ws clientDesc) [] let textSync_NoConfigNonEmptyWS_PreferIncr () = - let clientDesc = - { ClientDescription.empty with - opts = { preferredTextSyncKind = Some Incremental } } + let clientDesc = { + ClientDescription.empty with + opts = { preferredTextSyncKind = Some Incremental } + } let folder = Folder.multiFile "test" (dummyRootPath [ "test" ] |> mkFolderId) Seq.empty None @@ -47,9 +49,10 @@ module ServerUtilTests = [] let textSync_NonEmptyWS_PreferIncrButConfigTakesPrecedence () = - let clientDesc = - { ClientDescription.empty with - opts = { preferredTextSyncKind = Some Incremental } } + let clientDesc = { + ClientDescription.empty with + opts = { preferredTextSyncKind = Some Incremental } + } let folder = Folder.multiFile diff --git a/Tests/SuffixTreeTests.fs b/Tests/SuffixTreeTests.fs index 1c2cd50..c66b121 100644 --- a/Tests/SuffixTreeTests.fs +++ b/Tests/SuffixTreeTests.fs @@ -6,12 +6,13 @@ module ImplTests = module SuffixTree = SuffixTree.Impl let tree = - SuffixTree.ofSeq - [ [ "a"; "b" ], 0 - [ "a"; "b"; "c" ], 1 - [ "a"; "b"; "d" ], 2 - [ "b" ], 3 - [ "c" ], 4 ] + SuffixTree.ofSeq [ + [ "a"; "b" ], 0 + [ "a"; "b"; "c" ], 1 + [ "a"; "b"; "d" ], 2 + [ "b" ], 3 + [ "c" ], 4 + ] [] let filterTest () = diff --git a/Tests/SymbolsTests.fs b/Tests/SymbolsTests.fs index 335f78d..62de00c 100644 --- a/Tests/SymbolsTests.fs +++ b/Tests/SymbolsTests.fs @@ -9,13 +9,14 @@ open Marksman.Helpers open Marksman.Workspace module WorkspaceSymbol = - let mkSymbolInfo name kind loc = - { Name = name - Kind = kind - Location = loc - Tags = None - Deprecated = None - ContainerName = None } + let mkSymbolInfo name kind loc = { + Name = name + Kind = kind + Location = loc + Tags = None + Deprecated = None + ContainerName = None + } let doc1 = FakeDoc.Mk(path = "doc1.md", contentLines = [| "# A"; "#tag1" |]) @@ -31,26 +32,28 @@ module WorkspaceSymbol = let symbols = Symbols.workspaceSymbols "" workspace Assert.Equal( - [ mkSymbolInfo - "H1: A" - SymbolKind.String - { Uri = doc1.Id.Uri; Range = Range.Mk(0, 0, 0, 3) } - mkSymbolInfo - "Tag: tag1" - SymbolKind.String - { Uri = doc1.Id.Uri; Range = Range.Mk(1, 0, 1, 5) } - mkSymbolInfo - "H1: B" - SymbolKind.String - { Uri = doc2.Id.Uri; Range = Range.Mk(0, 0, 0, 3) } - mkSymbolInfo - "Tag: tag1" - SymbolKind.String - { Uri = doc2.Id.Uri; Range = Range.Mk(1, 0, 1, 5) } - mkSymbolInfo - "Tag: tag2" - SymbolKind.String - { Uri = doc2.Id.Uri; Range = Range.Mk(1, 6, 1, 11) } ], + [ + mkSymbolInfo "H1: A" SymbolKind.String { + Uri = doc1.Id.Uri + Range = Range.Mk(0, 0, 0, 3) + } + mkSymbolInfo "Tag: tag1" SymbolKind.String { + Uri = doc1.Id.Uri + Range = Range.Mk(1, 0, 1, 5) + } + mkSymbolInfo "H1: B" SymbolKind.String { + Uri = doc2.Id.Uri + Range = Range.Mk(0, 0, 0, 3) + } + mkSymbolInfo "Tag: tag1" SymbolKind.String { + Uri = doc2.Id.Uri + Range = Range.Mk(1, 0, 1, 5) + } + mkSymbolInfo "Tag: tag2" SymbolKind.String { + Uri = doc2.Id.Uri + Range = Range.Mk(1, 6, 1, 11) + } + ], symbols ) @@ -59,31 +62,35 @@ module WorkspaceSymbol = let symbols = Symbols.workspaceSymbols "Tag:" workspace Assert.Equal( - [ mkSymbolInfo - "Tag: tag1" - SymbolKind.String - { Uri = doc1.Id.Uri; Range = Range.Mk(1, 0, 1, 5) } - mkSymbolInfo - "Tag: tag1" - SymbolKind.String - { Uri = doc2.Id.Uri; Range = Range.Mk(1, 0, 1, 5) } - mkSymbolInfo - "Tag: tag2" - SymbolKind.String - { Uri = doc2.Id.Uri; Range = Range.Mk(1, 6, 1, 11) } ], + [ + mkSymbolInfo "Tag: tag1" SymbolKind.String { + Uri = doc1.Id.Uri + Range = Range.Mk(1, 0, 1, 5) + } + mkSymbolInfo "Tag: tag1" SymbolKind.String { + Uri = doc2.Id.Uri + Range = Range.Mk(1, 0, 1, 5) + } + mkSymbolInfo "Tag: tag2" SymbolKind.String { + Uri = doc2.Id.Uri + Range = Range.Mk(1, 6, 1, 11) + } + ], symbols ) module DocSymbols = let fakeDoc = FakeDoc.Mk( - [| "# E" // - "## D" - "#t1" - "### B" - "#t2" - "## C" - "# A" |] + [| + "# E" // + "## D" + "#t1" + "### B" + "#t2" + "## C" + "# A" + |] ) [] @@ -97,13 +104,15 @@ module DocSymbols = |> Array.map (fun x -> x.Name) Assert.Equal( - [| "H1: E" - "H2: D" - "H3: B" - "H2: C" - "H1: A" - "Tag: t1" - "Tag: t2" |], + [| + "H1: E" + "H2: D" + "H3: B" + "H2: C" + "H1: A" + "Tag: t1" + "Tag: t2" + |], symNames ) diff --git a/Tests/TextTests.fs b/Tests/TextTests.fs index f4237f4..c98b123 100644 --- a/Tests/TextTests.fs +++ b/Tests/TextTests.fs @@ -34,9 +34,13 @@ let applyTextChange_insert_single () = let actual = Text.applyTextChange - [| { Range = Some(Text.mkRange ((0, 1), (0, 1))) - RangeLength = Some 0 - Text = " Holla!" } |] + [| + { + Range = Some(Text.mkRange ((0, 1), (0, 1))) + RangeLength = Some 0 + Text = " Holla!" + } + |] text let expected = "! Holla!" @@ -48,12 +52,18 @@ let applyTextChange_insert_multiple () = let actual = Text.applyTextChange - [| { Range = Some(Text.mkRange ((0, 1), (0, 1))) - RangeLength = Some 0 - Text = " H" } - { Range = Some(Text.mkRange ((0, 3), (0, 3))) - RangeLength = Some 0 - Text = "i" } |] + [| + { + Range = Some(Text.mkRange ((0, 1), (0, 1))) + RangeLength = Some 0 + Text = " H" + } + { + Range = Some(Text.mkRange ((0, 3), (0, 3))) + RangeLength = Some 0 + Text = "i" + } + |] text let expected = "! Hi" @@ -65,9 +75,13 @@ let applyTextChange_insert_on_empty () = let actual = Text.applyTextChange - [| { Range = Some(Text.mkRange ((0, 0), (0, 0))) - RangeLength = Some 0 - Text = "H" } |] + [| + { + Range = Some(Text.mkRange ((0, 0), (0, 0))) + RangeLength = Some 0 + Text = "H" + } + |] text let expected = "H" @@ -79,9 +93,13 @@ let applyTextChange_insert_next_line () = let actual = Text.applyTextChange - [| { Range = Some(Text.mkRange ((1, 0), (1, 0))) - RangeLength = Some 0 - Text = "B" } |] + [| + { + Range = Some(Text.mkRange ((1, 0), (1, 0))) + RangeLength = Some 0 + Text = "B" + } + |] text let expected = "A\nB" @@ -94,9 +112,13 @@ let applyTextChange_replace_single () = let actual = Text.applyTextChange - [| { Range = Some(Text.mkRange ((0, 0), (0, 5))) - RangeLength = Some 5 - Text = "Bye" } |] + [| + { + Range = Some(Text.mkRange ((0, 0), (0, 5))) + RangeLength = Some 5 + Text = "Bye" + } + |] text let expected = "Bye World!" diff --git a/Tests/TocTests.fs b/Tests/TocTests.fs index a7d5b6e..bde095f 100644 --- a/Tests/TocTests.fs +++ b/Tests/TocTests.fs @@ -29,13 +29,14 @@ module DetectToc = [] let detectToc_withMarker () = let doc = - FakeDoc.Mk - [| StartMarker - "- [T1][#t1]" - " - [T2][#t2]" - EndMarker - "# T1" - "## T2" |] + FakeDoc.Mk [| + StartMarker + "- [T1][#t1]" + " - [T2][#t2]" + EndMarker + "# T1" + "## T2" + |] let toc = (TableOfContents.detect (Doc.text doc)).Value let tocText = (Doc.text doc).Substring toc @@ -64,14 +65,15 @@ module CreateToc = [] let createToc_yamlFrontMatter () = let doc = - FakeDoc.Mk - [| "---" - """title: "First" """ - """tags: ["1", "2"] """ - "---" - "" - "# T1" - "## T2" |] + FakeDoc.Mk [| + "---" + """title: "First" """ + """tags: ["1", "2"] """ + "---" + "" + "# T1" + "## T2" + |] let titles = TableOfContents.mk (Doc.index doc) |> Option.get @@ -104,14 +106,15 @@ module InsertToc = [] let insert_afterYaml () = let doc = - FakeDoc.Mk - [| "---" - """title: "First" """ - """tags: ["1", "2"] """ - "---" - "" - "## T1" - "## T2" |] + FakeDoc.Mk [| + "---" + """title: "First" """ + """tags: ["1", "2"] """ + "---" + "" + "## T1" + "## T2" + |] let insertion = TableOfContents.insertionPoint doc @@ -122,14 +125,15 @@ module InsertToc = [] let insert_afterFirstTitle_withYaml () = let doc = - FakeDoc.Mk - [| "---" - """title: "First" """ - """tags: ["1", "2"] """ - "---" - "" - "# T1" - "## T2" |] + FakeDoc.Mk [| + "---" + """title: "First" """ + """tags: ["1", "2"] """ + "---" + "" + "# T1" + "## T2" + |] let insertion = TableOfContents.insertionPoint doc @@ -148,14 +152,15 @@ module RenderToc = |> Option.get |> TableOfContents.render - let expectedLines = - [| StartMarker - "- [T1](#t1)" - " - [T2](#t2)" - " - [T3](#t3)" - " - [T4](#t4)" - " - [T5](#t5)" - EndMarker |] + let expectedLines = [| + StartMarker + "- [T1](#t1)" + " - [T2](#t2)" + " - [T3](#t3)" + " - [T4](#t4)" + " - [T5](#t5)" + EndMarker + |] let expected = String.concat NewLine expectedLines diff --git a/Tests/WorkspaceTest.fs b/Tests/WorkspaceTest.fs index 9976bf4..0275acd 100644 --- a/Tests/WorkspaceTest.fs +++ b/Tests/WorkspaceTest.fs @@ -72,12 +72,16 @@ module DocTest = let empty = Doc.mk defaultMarkdownExtensions dummyPath None (Text.mkText "") - let insertChange = - { TextDocument = { Uri = RootedRelPath.toSystem dummyPath.Path; Version = 1 } - ContentChanges = - [| { Range = Some(Range.Mk(0, 0, 0, 0)) - RangeLength = Some 0 - Text = "[" } |] } + let insertChange = { + TextDocument = { Uri = RootedRelPath.toSystem dummyPath.Path; Version = 1 } + ContentChanges = [| + { + Range = Some(Range.Mk(0, 0, 0, 0)) + RangeLength = Some 0 + Text = "[" + } + |] + } let updated = Doc.applyLspChange defaultMarkdownExtensions insertChange empty @@ -91,11 +95,12 @@ module DocTest = [] let fromLsp_singleFile () = - let par = - { Uri = "file:///a/b/doc.md" - LanguageId = "md" - Version = 1 - Text = "text" } + let par = { + Uri = "file:///a/b/doc.md" + LanguageId = "md" + Version = 1 + Text = "text" + } let singletonRoot = UriWith.mkRoot par.Uri let doc = Doc.fromLsp defaultMarkdownExtensions singletonRoot par