Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Avoid recomputing `List.length` on the shrinking remainder for every scanned character when splitting a Markdown pipe-table row into cells (`pipeTableFindSplits` in `MarkdownTableParser.fs`). The scan now tracks the number of consumed characters incrementally, turning an O(n²) split into an O(n) one for rows with many delimiters, with no behavior change.
* Avoided a per-character `Seq.windowed`/`String()` allocation in `StartsWithNTimesTrimIgnoreStartWhitespace`, the active pattern used to count repeated fence characters (`` ` `` / `~`) when parsing code fences and headers. The count is now computed with `String.CompareOrdinal` over string offsets, with no intermediate substring allocations. Behavior is unchanged.

### Fixed
* A `<see langword="..."/>` in a doc comment rendered as nothing, so `Returns <see langword="true"/> when …` read "Returns when …". The API docs show the keyword as inline code, the same as `<c>true</c>`, and a tool tip on a code snippet keeps the word. [#1371](https://github.com/fsprojects/FSharp.Formatting/pull/1371)

## [23.0.0-alpha.8] - 2026-09-18

### Added
Expand Down
8 changes: 8 additions & 0 deletions src/FSharp.Formatting.ApiDocs/XmlDocReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ module internal XmlDocReader =
urlMap.ResolveCref cname |> ignore
let crefAsHtml = HttpUtility.HtmlEncode cref.Value
html.Append(crefAsHtml) |> ignore
else
// a keyword such as <see langword="true"/> has nothing to link to,
// so it reads as code, the same as <c>true</c>
match elem.Attribute(XName.Get "langword") with
| null -> ()
| langword ->
html.AppendFormat("<code>{0}</code>", HttpUtility.HtmlEncode langword.Value)
|> ignore
| "c" ->
html.Append("<code>") |> ignore

Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Formatting.CodeFormat/ToolTipReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ let private tryReadXmlDoc (text: string) =
// document, so give it a root of its own before parsing
let root = XElement.Parse("<fsdocs>" + text + "</fsdocs>", LoadOptions.PreserveWhitespace)

// a <see cref="T:Foo.Bar"/> keeps its text in an attribute, so it would leave a
// hole in the sentence around it once we ask an element for its text
// a <see cref="T:Foo.Bar"/> or a <see langword="true"/> keeps its text in an attribute,
// so it would leave a hole in the sentence around it once we ask an element for its text
for reference in List.ofSeq (root.Descendants()) do
match reference.Name.LocalName with
| "see"
| "seealso"
| "paramref"
| "typeparamref" ->
let named =
[ "cref"; "name" ]
[ "cref"; "name"; "langword" ]
|> List.tryPick (fun name ->
match reference.Attribute(XName.Get name) with
| null -> None
Expand Down
38 changes: 38 additions & 0 deletions tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,44 @@ let ``Math in XML generated ok`` (format: OutputFormat) =
files.[(sprintf "creflib2-mathtest.%s" format.Extension)]
|> shouldContainText """1 &lt; 2 &lt; 3 &gt; 0"""

[<Test>]
[<TestCaseSource("formats")>]
let ``See langword renders as inline code`` (format: OutputFormat) =
let libraries = [ testBin </> "crefLib1.dll"; testBin </> "crefLib2.dll" ] |> fullpaths

let output = getOutputDir format "crefLibs_langword"
printfn "Output: %s" output

let inputs =
[
for lib in libraries ->
ApiDocInput.FromFile(
lib,
sourceRepo = "https://github.com/fsprojects/FSharp.Formatting/tree/master",
sourceFolder = (__SOURCE_DIRECTORY__ </> "../.."),
mdcomments = false
)
]

let _model, _searchIndex =
DocsGenerator(format)
.Run(
inputs,
output,
collectionName = "CrefLibs",
template = docTemplate format,
substitutions = substitutions,
libDirs = ([ testBin ] |> fullpaths)
)

let fileNames = Directory.GetFiles(output </> "reference")

let files = dict [ for f in fileNames -> Path.GetFileName(f), File.ReadAllText(f) ]

// a keyword has no cref to link, so it reads as code, the same as <c>true</c>
files.[(sprintf "creflib2-class12.%s" format.Extension)]
|> shouldContainText "Returns <code>true</code> when it works, otherwise <code>false</code>."

[<Test>]
[<TestCaseSource("formats")>]
let ``ApiDocs test that csharp (publiconly) support works`` (format: OutputFormat) =
Expand Down
6 changes: 6 additions & 0 deletions tests/FSharp.ApiDocs.Tests/files/crefLib2/Library2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ type Class10() =
/// </summary>
type Class11() =
member this.X = "F#"

/// <summary>
/// Returns <see langword="true"/> when it works, otherwise <see langword="false"/>.
/// </summary>
type Class12() =
member this.X = "F#"
13 changes: 13 additions & 0 deletions tests/FSharp.CodeFormat.Tests/CodeFormatTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,19 @@ let m = make ()
let _content, tooltip = getContentAndToolTip source
tooltip |> shouldContainText "Produces a Marker value"

[<Test>]
let ``A see langword keeps its keyword in the sentence it sits in`` () =
let source =
"""
/// Returns <see langword="true"/> when it works
let works () = true

let w = works ()
"""

let _content, tooltip = getContentAndToolTip source
tooltip |> shouldContainText "Returns true when it works"

// --------------------------------------------------------------------------------------
// Tests for cross-assembly type resolution in tooltips (issue #1085)
// --------------------------------------------------------------------------------------
Expand Down
Loading