Skip to content

Commit e58318b

Browse files
authored
Merge branch 'main' into repo-assist/fix-issue-1022-split-buildcommand-7a7c06d9bd38078d
2 parents 7040c3c + cacabf3 commit e58318b

12 files changed

Lines changed: 126 additions & 9 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Added
1010

11+
* Add `///` documentation comments to all public types, modules and members, and succinct internal comments, as part of ongoing effort to document the codebase. [#1035](https://github.com/fsprojects/FSharp.Formatting/issues/1035)
1112
* Add "Copy" button to all code blocks in generated documentation, making it easy to copy code samples to the clipboard. [#72](https://github.com/fsprojects/FSharp.Formatting/issues/72)
1213
* Add `<FsDocsAllowExecutableProject>true</FsDocsAllowExecutableProject>` project file setting to include executable projects (OutputType=Exe/WinExe) in API documentation generation. [#918](https://github.com/fsprojects/FSharp.Formatting/issues/918)
1314
* Add `{{fsdocs-logo-alt}}` substitution (configurable via `<FsDocsLogoAlt>` MSBuild property, defaults to `Logo`) for accessible alt text on the header logo image. [#626](https://github.com/fsprojects/FSharp.Formatting/issues/626)

src/FSharp.Formatting.ApiDocs/Categorise.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/// Internal helpers for grouping API doc entities and members by their declared categories
12
[<RequireQualifiedAccess>]
23
module internal FSharp.Formatting.ApiDocs.Categorise
34

45
open System
56

6-
// Honour the CategoryIndex to put the categories in the right order
7+
/// Returns entities/members sorted by CategoryIndex then category name, with excluded items removed
78
let private getSortedCategories xs exclude category categoryIndex =
89
xs
910
|> List.filter (exclude >> not)
@@ -12,7 +13,7 @@ let private getSortedCategories xs exclude category categoryIndex =
1213
|> List.sortBy (fun (cat, _xs, x) -> categoryIndex x, cat)
1314
|> List.map (fun (cat, xs, _x) -> cat, xs)
1415

15-
// Group all members by their category
16+
/// Groups members by their Category/CategoryIndex, sorts alphabetically within each category
1617
let getMembersByCategory (members: ApiDocMember list) =
1718
getSortedCategories members (fun m -> m.Exclude) (fun m -> m.Category) (fun m -> m.CategoryIndex)
1819
|> List.mapi (fun i (key, elems) ->
@@ -26,6 +27,7 @@ let getMembersByCategory (members: ApiDocMember list) =
2627

2728
(i, elems, name))
2829

30+
/// Returns the categorised, sorted, and (optionally) suppressed entity list for a namespace
2931
let entities (nsIndex: int, ns: ApiDocNamespace, suppress) =
3032
let entities = ns.Entities
3133

@@ -105,6 +107,7 @@ let entities (nsIndex: int, ns: ApiDocNamespace, suppress) =
105107

106108
allByCategory
107109

110+
/// Returns the category groups for every namespace in the model, skipping empty namespaces
108111
let model (apiDocModel: ApiDocModel) =
109112
[ for (nsIndex, ns) in Seq.indexed apiDocModel.Collection.Namespaces do
110113
let allByCategory = entities (nsIndex, ns, true)

src/FSharp.Formatting.ApiDocs/GenerateSearchIndex.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
/// Internal module for building the JSON search index from an <see cref="ApiDocModel"/>
12
module internal FSharp.Formatting.ApiDocs.GenerateSearchIndex
23

34
open FSharp.Formatting.ApiDocs
45

6+
/// Bundles all entity and model data needed while building search entries
57
type AssemblyEntities =
68
{ Entities: ApiDocEntity list
79
GeneratorOutput: ApiDocModel }
810

911

12+
/// Recursively collects an entity and all its nested entities
1013
let rec collectEntities (m: ApiDocEntity) =
1114
[ yield m; yield! m.NestedEntities |> List.collect collectEntities ]
1215

16+
/// The search index type tag used to identify API-docs entries
1317
[<Literal>]
1418
let ApiDocs = "apiDocs"
1519

20+
/// Builds all search index entries for the given <see cref="ApiDocModel"/>
1621
let searchIndexEntriesForModel (model: ApiDocModel) =
1722
let allEntities =
1823
[ for n in model.Collection.Namespaces do
@@ -23,6 +28,7 @@ let searchIndexEntriesForModel (model: ApiDocModel) =
2328
{ Entities = allEntities
2429
GeneratorOutput = model }
2530

31+
/// Builds a single search entry for a member under the given enclosing entity name
2632
let doMember enclName (memb: ApiDocMember) =
2733
let cnt =
2834
[ yield enclName + "." + memb.Name
@@ -41,7 +47,7 @@ let searchIndexEntriesForModel (model: ApiDocModel) =
4147

4248
let refs =
4349
[| for nsp in model.Collection.Namespaces do
44-
// the entry is found when searching for types and modules
50+
// Namespace entry: content lists all child type/module names for search
4551
let ctn =
4652
[ for e in nsp.Entities do
4753
e.Name ]
@@ -53,7 +59,7 @@ let searchIndexEntriesForModel (model: ApiDocModel) =
5359
``type`` = ApiDocs
5460
headings = List.empty }
5561

56-
// generate a search index entry for each entity in the assembly
62+
// One entry per entity (type/module), plus one per member
5763
for e in entities.Entities do
5864
let cnt =
5965
[ e.Name
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,102 @@
1+
/// Internal CSS class name constants used when emitting syntax-highlighted HTML
12
module internal FSharp.Formatting.CodeFormat.Constants
23

4+
/// CSS class name constants for syntax token categories
35
[<RequireQualifiedAccessAttribute>]
46
module CSS =
57

8+
/// CSS class for comment tokens
69
[<Literal>]
710
let Comment = "c"
811

12+
/// CSS class for default/plain tokens
913
[<Literal>]
1014
let Default = ""
1115

16+
/// CSS class for identifier tokens
1217
[<Literal>]
1318
let Identifier = "id"
1419

20+
/// CSS class for inactive (excluded by conditional compilation) tokens
1521
[<Literal>]
1622
let Inactive = "inactive"
1723

24+
/// CSS class for keyword tokens
1825
[<Literal>]
1926
let Keyword = "k"
2027

28+
/// CSS class for numeric literal tokens
2129
[<Literal>]
2230
let Number = "n"
2331

32+
/// CSS class for operator tokens
2433
[<Literal>]
2534
let Operator = "o"
2635

36+
/// CSS class for preprocessor directive tokens
2737
[<Literal>]
2838
let Preprocessor = "pp"
2939

40+
/// CSS class for string literal tokens
3041
[<Literal>]
3142
let String = "s"
3243

44+
/// CSS class for module/namespace tokens
3345
[<Literal>]
3446
let Module = "m"
3547

48+
/// CSS class for reference type tokens
3649
[<Literal>]
3750
let ReferenceType = "rt"
3851

52+
/// CSS class for value type tokens
3953
[<Literal>]
4054
let ValueType = "vt"
4155

56+
/// CSS class for function tokens
4257
[<Literal>]
4358
let Function = "fn"
4459

60+
/// CSS class for pattern match tokens
4561
[<Literal>]
4662
let Pattern = "pat"
4763

64+
/// CSS class for mutable variable tokens
4865
[<Literal>]
4966
let MutableVar = "mv"
5067

68+
/// CSS class for printf format string tokens
5169
[<Literal>]
5270
let Printf = "pf"
5371

72+
/// CSS class for escaped character tokens
5473
[<Literal>]
5574
let Escaped = "esc"
5675

76+
/// CSS class for disposable tokens
5777
[<Literal>]
5878
let Disposable = "d"
5979

80+
/// CSS class for type argument tokens
6081
[<Literal>]
6182
let TypeArgument = "ta"
6283

84+
/// CSS class for punctuation tokens
6385
[<Literal>]
6486
let Punctuation = "pn"
6587

88+
/// CSS class for enumeration tokens
6689
[<Literal>]
6790
let Enumeration = "en"
6891

92+
/// CSS class for interface tokens
6993
[<Literal>]
7094
let Interface = "if"
7195

96+
/// CSS class for property tokens
7297
[<Literal>]
7398
let Property = "prop"
7499

100+
/// CSS class for union case tokens
75101
[<Literal>]
76102
let UnionCase = "uc"

src/FSharp.Formatting.Common/Log.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,48 @@ namespace FSharp.Formatting.Common
22

33
open System.Diagnostics
44

5+
/// Internal logging helpers backed by a <see cref="System.Diagnostics.TraceSource"/>
56
module internal Log =
7+
/// The shared TraceSource used by all FSharp.Formatting logging
68
let source = new System.Diagnostics.TraceSource "FSharp.Formatting"
79

10+
/// Creates a TraceListener that writes to the console
811
let ConsoleListener () =
912
{ new TraceListener() with
1013
override __.WriteLine(s: string) = System.Console.WriteLine(s)
1114
override __.Write(s: string) = System.Console.Write(s) }
1215

16+
/// Creates a TraceListener that writes to a file
1317
let TextListener (file: string) = new TextWriterTraceListener(file)
1418

19+
/// Clears existing listeners, sets the level to All, and attaches the given listeners to the source
1520
let SetupSource (listeners: _ array) (source: TraceSource) =
1621
source.Listeners.Clear()
1722
source.Switch.Level <- System.Diagnostics.SourceLevels.All
1823
source.Listeners.AddRange listeners
1924

25+
/// Configures a listener with the given trace output options and event level filter
2026
let SetupListener traceOptions levels (listener: TraceListener) =
2127
listener.Filter <- new EventTypeFilter(levels)
2228
listener.TraceOutputOptions <- traceOptions
2329
listener
2430

31+
/// Adds a listener to the given TraceSource
2532
let AddListener listener (source: TraceSource) = source.Listeners.Add listener |> ignore
2633

34+
/// Emits a trace event of the given type using printf-style formatting
2735
let traceEventf t f =
2836
Printf.kprintf (fun s -> source.TraceEvent(t, 0, s)) f
2937

38+
/// Logs an informational message
3039
let infof f =
3140
traceEventf TraceEventType.Information f
3241

42+
/// Logs an error message
3343
let errorf f = traceEventf TraceEventType.Error f
44+
/// Logs a warning message
3445
let warnf f = traceEventf TraceEventType.Warning f
46+
/// Logs a critical message
3547
let critf f = traceEventf TraceEventType.Critical f
48+
/// Logs a verbose message
3649
let verbf f = traceEventf TraceEventType.Verbose f

src/FSharp.Formatting.Common/Menu.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
/// Internal helpers for building navigation menu HTML from template files
12
module FSharp.Formatting.Common.Menu
23

34
open System
45
open System.IO
56
open FSharp.Formatting.Templating
67

8+
/// A single navigation menu item with its link, display text, and active state
79
type MenuItem =
810
{ Link: string
911
Content: string
1012
IsActive: bool }
1113

14+
/// Converts a display string to a snake_case HTML id attribute value
1215
let private snakeCase (v: string) =
1316
System.Text.RegularExpressions.Regex.Replace(v, "[A-Z]", "$0").Replace(" ", "_").ToLower()
1417

18+
/// Renders an HTML navigation menu for the given header and items using template files in `input`
1519
let createMenu (input: string) (isCategoryActive: bool) (header: string) (items: MenuItem list) : string =
1620
let pwd = Directory.GetCurrentDirectory()
1721
let menuTemplate = File.ReadAllText(Path.Combine(pwd, input, "_menu_template.html"))
@@ -39,12 +43,14 @@ let createMenu (input: string) (isCategoryActive: bool) (header: string) (items:
3943
ParamKeys.``fsdocs-menu-items``, menuItems |]
4044
menuTemplate
4145

46+
/// Returns true when both required menu template files exist in `input`
4247
let isTemplatingAvailable (input: string) : bool =
4348
let pwd = Directory.GetCurrentDirectory()
4449
let menuTemplate = Path.Combine(pwd, input, "_menu_template.html")
4550
let menuItemTemplate = Path.Combine(pwd, input, "_menu-item_template.html")
4651
File.Exists(menuTemplate) && File.Exists(menuItemTemplate)
4752

53+
/// Returns the last-write timestamps of the two menu template files
4854
let getLastWriteTimes (input: string) : DateTime list =
4955
let pwd = Directory.GetCurrentDirectory()
5056

src/FSharp.Formatting.Common/PageContentList.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
module FSharp.Formatting.Common.PageContentList
1+
/// Builds a "page content" table-of-contents menu by scanning heading links in rendered HTML
2+
module FSharp.Formatting.Common.PageContentList
23

34
open System.Text.RegularExpressions
45
open FSharp.Formatting.HtmlModel
56
open FSharp.Formatting.HtmlModel.Html
67

8+
/// Placeholder HTML emitted when a page has no headings to list
79
[<Literal>]
810
let EmptyContent = "<div class=\"empty\"></div>"
911

12+
/// Parses the rendered HTML to extract heading links and builds a nested <ul> table-of-contents.
1013
/// We process the html to collect the table of content.
1114
/// We can't use the doc.MarkdownDocument because we cannot easily get the generated id values.
1215
/// It is safer to parse the html.

src/FSharp.Formatting.Common/Range.fs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
namespace FSharp.Formatting.Markdown
22

3+
/// <summary>
4+
/// Represents a source range in a Markdown document, identified by start and end line/column positions.
5+
/// Used to track where each parsed element originated in the source text.
6+
/// </summary>
37
[<Struct>]
48
type MarkdownRange =
5-
{ StartLine: int
6-
StartColumn: int
7-
EndLine: int
8-
EndColumn: int }
9+
{
10+
/// The 1-based line number where the element starts
11+
StartLine: int
12+
/// The 0-based column index where the element starts
13+
StartColumn: int
14+
/// The 1-based line number where the element ends
15+
EndLine: int
16+
/// The 0-based column index where the element ends
17+
EndColumn: int
18+
}
919

1020

21+
/// Helper functions for working with <see cref="MarkdownRange"/> values
1122
module MarkdownRange =
1223

24+
/// A zero range used as a default/placeholder when no real range is available
1325
let zero =
1426
{ StartLine = 0
1527
StartColumn = 0
1628
EndLine = 0
1729
EndColumn = 0 }
1830

31+
/// Merges a list of ranges into one spanning range that covers all of them
1932
let mergeRanges (ranges: MarkdownRange list) =
2033
let startRange = ranges |> List.minBy (fun r -> r.StartLine, r.StartColumn)
2134

src/FSharp.Formatting.Markdown/MarkdownFormatting.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// Format a document as a .md
33
// --------------------------------------------------------------------------------------
44

5+
/// Internal module for re-serializing a parsed Markdown AST back to Markdown text
56
module internal FSharp.Formatting.Markdown.MarkdownFormatting
67

78
open MarkdownUtils
89

10+
/// Formats a list of paragraphs, collecting all output lines
911
let rec formatParagraphs ctx (paragraphs: MarkdownParagraph list) =
1012
paragraphs |> Seq.collect (formatParagraph ctx)
1113

14+
/// Formats a full Markdown document as a Markdown string
1215
let formatAsMarkdown links replacements newline crefResolver mdlinkResolver paragraphs =
1316
let ctx =
1417
{ Links = links

0 commit comments

Comments
 (0)