Skip to content

Commit 4453f26

Browse files
Repo AssistCopilot
authored andcommitted
Exclude members with CompilerMessageAttribute(IsHidden=true) from API docs
Members and functions annotated with [<CompilerMessage(..., IsHidden=true)>] are now automatically treated as excluded from API documentation, equivalent to [omit] or <exclude/>. Closes #144 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b20729c commit 4453f26

4 files changed

Lines changed: 22 additions & 0 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* HTML-encode XML doc text nodes and unresolved `<see cref>` values to prevent HTML injection and fix broken output when docs contain characters like `<`, `>`, or backticks in generic type notation. [#748](https://github.com/fsprojects/FSharp.Formatting/issues/748)
1212
* Add uppercase output kind extension (e.g. `HTML`, `IPYNB`) to `ConditionalDefines` so that `#if HTML` and `(*** condition: HTML ***)` work alongside their lowercase variants. [#693](https://github.com/fsprojects/FSharp.Formatting/issues/693)
1313
* Strip `#if SYMBOL` / `#endif // SYMBOL` marker lines from `LiterateCode` source before syntax-highlighting so they do not appear in formatted output. [#693](https://github.com/fsprojects/FSharp.Formatting/issues/693)
14+
* Members and functions annotated with `CompilerMessageAttribute(IsHidden=true)` are now automatically excluded from API docs, matching the behaviour of `[omit]` / `<exclude/>`. [#144](https://github.com/fsprojects/FSharp.Formatting/issues/144)
1415

1516
### Changed
1617
* Update FCS to 43.10.100. [#935](https://github.com/fsprojects/FSharp.Formatting/pull/966)

src/FSharp.Formatting.ApiDocs/GenerateModel.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,21 @@ module internal SymbolReader =
23982398
| Command "exclude" v
23992399
| Let "false" (v, _) -> (v <> "false")
24002400

2401+
let isCompilerHidden =
2402+
let attribs =
2403+
match sym with
2404+
| :? FSharpMemberOrFunctionOrValue as mfv -> mfv.Attributes :> FSharpAttribute seq
2405+
| :? FSharpEntity as ent -> ent.Attributes :> FSharpAttribute seq
2406+
| _ -> Seq.empty
2407+
2408+
attribs
2409+
|> Seq.exists (fun a ->
2410+
a.AttributeType.FullName = "Microsoft.FSharp.Core.CompilerMessageAttribute"
2411+
&& a.NamedArguments
2412+
|> Seq.exists (fun (_, name, _, value) -> name = "IsHidden" && (value :?> bool) = true))
2413+
2414+
let exclude = exclude || isCompilerHidden
2415+
24012416
try
24022417
Some(f cat catindex exclude cmds comment, nsdocs)
24032418
with e ->

tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ let ``ApiDocs excludes items`` (format: OutputFormat) =
179179
files.[(sprintf "fslib-partiallydocumented.%s" format.Extension)]
180180
|> shouldNotContainText "shouldBeExcluded7"
181181

182+
files.[(sprintf "fslib-partiallydocumented.%s" format.Extension)]
183+
|> shouldNotContainText "shouldBeExcludedCompilerHidden"
184+
182185
// We can only expect a warning for "wishItWasExcluded1" & "WishItWasExcluded2"
183186

184187
files.ContainsKey(sprintf "fslib-partiallydocumented-notdocumented1.%s" format.Extension)

tests/FSharp.ApiDocs.Tests/files/TestLib3/Library3.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,7 @@ module PartiallyDocumented =
5858
module NotDocumented3 =
5959
let a = 10
6060

61+
[<CompilerMessage("Internal helper, hidden from IntelliSense", 9999, IsHidden = true)>]
62+
let shouldBeExcludedCompilerHidden x = x
63+
6164
let x = 10

0 commit comments

Comments
 (0)