Skip to content

Commit

Permalink
fmt: Use stroustrup bracket style
Browse files Browse the repository at this point in the history
stack-info: PR: #346, branch: artempyanykh/stack/6
  • Loading branch information
artempyanykh committed Nov 17, 2024
1 parent b8da6ba commit 244f97e
Show file tree
Hide file tree
Showing 44 changed files with 1,232 additions and 1,013 deletions.
8 changes: 7 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
fsharp_max_elmish_width=70

[Marksman/*.{fs,fsi}]
fsharp_multiline_bracket_style = stroustrup

[Tests/*.{fs,fsi}]
fsharp_multiline_bracket_style = stroustrup
32 changes: 18 additions & 14 deletions Marksman/Ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
heading: option<string> }
type WikiLink = {
doc: option<string>
heading: option<string>
} with

member this.CompactFormat() =
let doc = this.doc |> Option.defaultValue ""
Expand All @@ -29,10 +31,11 @@ type WikiLink =


// [text](url "title")
type MdLink =
{ text: string
url: option<string>
anchor: option<string> }
type MdLink = {
text: string
url: option<string>
anchor: option<string>
} with

member this.CompactFormat() =
let url =
Expand Down Expand Up @@ -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}"
Expand Down
110 changes: 64 additions & 46 deletions Marksman/Compl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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<CompletionItem> =
Expand Down Expand Up @@ -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<CompletionItem> =
let targetPath = (Doc.pathFromRoot doc) |> RelPath.toSystem
Expand All @@ -519,38 +528,42 @@ 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 =
path
|> 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
Expand All @@ -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
Expand All @@ -604,23 +619,25 @@ 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 =
$"[{text.text}]({targetPathEncoded}#{Slug.str targetHeading})"

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
Expand All @@ -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<InternName>) : seq<Doc> =
Expand Down
Loading

0 comments on commit 244f97e

Please sign in to comment.