Skip to content

Commit 9e8ba5d

Browse files
authored
Merge pull request fsprojects#3281 from fsprojects/repo-assist/improve-syntaxoak-du-doc-comments-20260312-3786f35af5294347
[Repo Assist] Add doc comments to 20 undocumented top-level Oak DU types and interfaces
2 parents 96d1d3b + 6441d9d commit 9e8ba5d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/Fantomas.Core/SyntaxOak.fs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ open System.Collections.Generic
44
open System.Text
55
open Fantomas.FCS.Text
66

7+
/// The kind of non-code content that can be attached to a node as trivia.
8+
/// Single-line and line-after-source-code comments carry their text; block comments
9+
/// also record whether blank lines should surround them. <c>Directive</c> covers
10+
/// preprocessor directives and <c>Cursor</c> is used by editor tooling to track the
11+
/// caret position during formatting.
712
type TriviaContent =
813
| CommentOnSingleLine of string
914
| LineCommentAfterSourceCode of comment: string
@@ -31,6 +36,11 @@ type TriviaNode(content: TriviaContent, range: range) =
3136
| Directive s -> $"Directive(%s{rangeStr}, \"%s{s}\")"
3237
| Cursor -> $"Cursor(%s{rangeStr})"
3338

39+
/// The core interface implemented by every node in the Oak intermediate representation.
40+
/// Each node carries trivia (comments, blank lines, directives) that were attached to
41+
/// it during the AST → Oak transformation, together with its source range and child nodes.
42+
/// The printer reads <c>ContentBefore</c> / <c>ContentAfter</c> when emitting each node
43+
/// so that all non-code content is reproduced in the output.
3444
[<Interface>]
3545
type Node =
3646
abstract ContentBefore: TriviaNode seq
@@ -44,6 +54,10 @@ type Node =
4454
abstract AddCursor: pos -> unit
4555
abstract TryGetCursor: pos option
4656

57+
/// Base implementation of <see cref="Node"/> shared by all concrete Oak node types.
58+
/// Manages the mutable trivia queues (<c>ContentBefore</c> / <c>ContentAfter</c>) and
59+
/// the optional in-editor cursor position. Concrete node types inherit from this class
60+
/// and supply their <c>Children</c> override.
4761
[<AbstractClass>]
4862
type NodeBase(range: range) =
4963
let mutable potentialCursor = None
@@ -161,6 +175,9 @@ let combineRanges (ranges: range seq) =
161175
else
162176
Seq.reduce Range.unionRanges ranges
163177

178+
/// A single element of a dotted identifier path, either an identifier token or a dot separator.
179+
/// <c>KnownDot</c> carries the source range of the <c>.</c> when it is present in the source;
180+
/// <c>UnknownDot</c> is used as a synthetic separator when the original range is unavailable.
164181
[<RequireQualifiedAccess; NoComparison>]
165182
type IdentifierOrDot =
166183
| Ident of SingleTextNode
@@ -468,6 +485,9 @@ type TypeIntersectionNode(typesAndSeparators: Choice<Type, SingleTextNode> list,
468485

469486
member val TypesAndSeparators = typesAndSeparators
470487

488+
/// Discriminated union of all F# type expressions in the Oak intermediate representation.
489+
/// Each case wraps a strongly-typed node that carries the substructure of that type form.
490+
/// Use <c>Type.Node</c> to obtain the underlying <see cref="Node"/> for printer dispatch.
471491
[<RequireQualifiedAccess; NoEquality; NoComparison>]
472492
type Type =
473493
| Funs of TypeFunsNode
@@ -696,6 +716,8 @@ type PatIsInstNode(token: SingleTextNode, t: Type, range) =
696716
member val Token = token
697717
member val Type = t
698718

719+
/// Discriminated union of all F# patterns in the Oak intermediate representation.
720+
/// Each case wraps a strongly-typed node. Use <c>Pattern.Node</c> for printer dispatch.
699721
[<RequireQualifiedAccess; NoEquality; NoComparison>]
700722
type Pattern =
701723
| OptionalVal of SingleTextNode
@@ -885,6 +907,9 @@ type InheritConstructorOtherNode(inheritKeyword: SingleTextNode, t: Type, expr:
885907
member val Type = t
886908
member val Expr = expr
887909

910+
/// Discriminated union for the argument form following an <c>inherit</c> declaration.
911+
/// Covers the four constructor syntax variants: bare type, unit <c>()</c>, parenthesised
912+
/// argument list, and any other expression argument form.
888913
[<RequireQualifiedAccess; NoComparison>]
889914
type InheritConstructor =
890915
| TypeOnly of InheritConstructorTypeOnlyNode
@@ -1138,6 +1163,9 @@ type ExprComputationNode(openingBrace: SingleTextNode, bodyExpr: Expr, closingBr
11381163
member val Body = bodyExpr
11391164
member val ClosingBrace = closingBrace
11401165

1166+
/// A single statement inside a computation-expression body.
1167+
/// <c>BindingStatement</c> covers <c>let!</c>, <c>let</c>, <c>use!</c> etc. bindings;
1168+
/// <c>OtherStatement</c> covers any other expression (e.g. <c>return</c>, <c>do!</c>, <c>yield</c>).
11411169
[<RequireQualifiedAccess; NoEquality; NoComparison>]
11421170
type ComputationExpressionStatement =
11431171
| BindingStatement of BindingNode
@@ -1280,6 +1308,9 @@ type ExprPrefixAppNode(operator: SingleTextNode, expr: Expr, range) =
12801308
member val Operator = operator
12811309
member val Expr = expr
12821310

1311+
/// Marker interface implemented by <see cref="ExprSameInfixAppsNode"/> and
1312+
/// <see cref="ExprInfixAppNode"/> to allow the printer to treat both infix-application
1313+
/// forms uniformly when deciding layout (e.g. newline-infix formatting).
12831314
type InfixApp = interface end
12841315

12851316
/// Example: `a + b + c` — a sequence of the *same* operator applied repeatedly (avoids redundant nesting)
@@ -1329,6 +1360,9 @@ type LinkSingleAppUnit(functionName: Expr, unit: UnitNode, range) =
13291360
member val FunctionName = functionName
13301361
member val Unit = unit
13311362

1363+
/// A single link in a method-call or property-access chain (e.g. <c>a.b().c[0]</c>).
1364+
/// The chain is represented as an ordered list of <c>ChainLink</c> values so that the
1365+
/// printer can decide whether to keep the chain on one line or break at each dot.
13321366
[<RequireQualifiedAccess; NoComparison; NoEquality>]
13331367
type ChainLink =
13341368
| Identifier of Expr
@@ -1710,6 +1744,10 @@ type StaticOptimizationConstraintWhenTyparTyconEqualsTyconNode(typar: SingleText
17101744
member val TypeParameter = typar
17111745
member val Type = t
17121746

1747+
/// A static optimisation constraint attached to an <c>Expr.LibraryOnlyStaticOptimization</c>
1748+
/// node (internal compiler use, not user-facing F# syntax).
1749+
/// <c>WhenTyparTyconEqualsTycon</c> represents <c>when 'T = SomeType</c>;
1750+
/// <c>WhenTyparIsStruct</c> represents <c>when 'T: struct</c>.
17131751
[<NoComparison>]
17141752
type StaticOptimizationConstraint =
17151753
| WhenTyparTyconEqualsTycon of StaticOptimizationConstraintWhenTyparTyconEqualsTyconNode
@@ -1828,6 +1866,10 @@ type ExprExplicitConstructorThenExpr(thenNode: SingleTextNode, expr: Expr, range
18281866
member val Then = thenNode
18291867
member val Expr = expr
18301868

1869+
/// Discriminated union of all F# expressions in the Oak intermediate representation.
1870+
/// Each case wraps a strongly-typed node that captures the exact sub-structure needed
1871+
/// for formatting. Use <c>Expr.Node</c> to obtain the underlying <see cref="Node"/>
1872+
/// for printer dispatch, and <c>Expr.NodeRange</c> for range queries.
18311873
[<RequireQualifiedAccess; NoEquality; NoComparison>]
18321874
type Expr =
18331875
| Lazy of ExprLazyNode
@@ -1983,6 +2025,9 @@ type OpenTargetNode(target: Type, range) =
19832025
override val Children: Node array = [| yield Type.Node target |]
19842026
member val Target = target
19852027

2028+
/// Discriminated union for the two forms of <c>open</c> declaration.
2029+
/// <c>ModuleOrNamespace</c> represents <c>open System.IO</c>;
2030+
/// <c>Target</c> represents <c>open type System.Math</c>.
19862031
[<RequireQualifiedAccess; NoEquality; NoComparison>]
19872032
type Open =
19882033
| ModuleOrNamespace of OpenModuleOrNamespaceNode
@@ -2359,6 +2404,9 @@ type TypeNameNode
23592404
member val EqualsToken = equalsToken
23602405
member val WithKeyword = withKeyword
23612406

2407+
/// Interface implemented by all type-definition node types that carry a type name and a
2408+
/// member list. Used to access the common parts of a type definition (its header and
2409+
/// members) without matching on every <see cref="TypeDefn"/> case.
23622410
type ITypeDefn =
23632411
abstract member TypeName: TypeNameNode
23642412
abstract member Members: MemberDefn list
@@ -2560,6 +2608,9 @@ type TypeDefnRegularNode(typeNameNode, members, range) =
25602608
member val TypeName = typeNameNode
25612609
member val Members = members
25622610

2611+
/// Discriminated union of all F# type-definition forms in the Oak representation.
2612+
/// <c>None</c> is used for a bare type name with no body (e.g. <c>type T</c> in a signature);
2613+
/// all other cases wrap a dedicated node type that also implements <see cref="ITypeDefn"/>.
25632614
[<RequireQualifiedAccess; NoEquality; NoComparison>]
25642615
type TypeDefn =
25652616
| Enum of TypeDefnEnumNode
@@ -2848,6 +2899,9 @@ type MemberDefnSigMemberNode(valNode: ValNode, withGetSet: MultipleTextsNode opt
28482899
member val Val = valNode
28492900
member val WithGetSet = withGetSet
28502901

2902+
/// Discriminated union of all member definitions that can appear inside a type body.
2903+
/// Covers everything from <c>inherit</c> and <c>val</c> fields to explicit constructors,
2904+
/// abstract slots, auto-properties, and interface implementations.
28512905
[<RequireQualifiedAccess; NoEquality; NoComparison>]
28522906
type MemberDefn =
28532907
| ImplicitInherit of InheritConstructor
@@ -2894,6 +2948,9 @@ type ConstantMeasureNode(constant: Constant, measure: UnitOfMeasureNode, range)
28942948
member val Constant = constant
28952949
member val Measure = measure
28962950

2951+
/// Discriminated union for the three forms of constant literal in the Oak representation.
2952+
/// <c>FromText</c> covers all ordinary literals (integers, strings, booleans, etc.);
2953+
/// <c>Unit</c> is the <c>()</c> literal; <c>Measure</c> is a numeric literal with a unit annotation.
28972954
[<RequireQualifiedAccess; NoEquality; NoComparison>]
28982955
type Constant =
28992956
| FromText of SingleTextNode
@@ -2962,6 +3019,9 @@ type TyparDeclsPrefixListNode
29623019
member val Decls = decls
29633020
member val ClosingParen = closingParen
29643021

3022+
/// Discriminated union for the three syntactic forms of type-parameter declaration.
3023+
/// <c>PostfixList</c> is the <c>{'T, 'U}</c> style; <c>PrefixList</c> is <c>('T, 'U)</c>;
3024+
/// <c>SinglePrefix</c> is a bare <c>'T</c> in contexts where only one parameter is present.
29653025
[<RequireQualifiedAccess; NoEquality; NoComparison>]
29663026
type TyparDecls =
29673027
| PostfixList of TyparDeclsPostfixListNode
@@ -3022,6 +3082,9 @@ type TypeConstraintWhereNotSupportsNull
30223082
member val Not = notNode
30233083
member val Null = nullNode
30243084

3085+
/// Discriminated union of all type-constraint forms that can appear in <c>when</c> clauses.
3086+
/// Covers simple constraints (<c>'T: comparison</c>), subtype constraints (<c>'T :> T</c>),
3087+
/// member constraints, enum/delegate constraints, and F# 9 null-related constraints.
30253088
[<RequireQualifiedAccess; NoEquality; NoComparison>]
30263089
type TypeConstraint =
30273090
| Single of TypeConstraintSingleNode
@@ -3139,6 +3202,9 @@ type NegateRationalNode(minus: SingleTextNode, rationalConst: RationalConstNode,
31393202
member val Minus = minus
31403203
member val Rational = rationalConst
31413204

3205+
/// Discriminated union for the three forms of a rational-number exponent in a unit-of-measure
3206+
/// type annotation (e.g. <c>m/s^2</c>). An exponent can be a plain integer, a rational
3207+
/// fraction <c>3/2</c>, or a negated form of either.
31423208
[<RequireQualifiedAccess; NoEquality; NoComparison>]
31433209
type RationalConstNode =
31443210
| Integer of SingleTextNode

0 commit comments

Comments
 (0)