[Repo Assist] Include type constraints in generated API documentation#1045
[Repo Assist] Include type constraints in generated API documentation#1045github-actions[bot] wants to merge 11 commits intomainfrom
Conversation
Fixes #591. Type constraints on generic parameters (e.g. 'T : equality, 'T : comparison, 'T :> IComparable) are now extracted from FCS symbols and displayed in the member tooltip in the 'Constraints:' line. Changes: - TypeFormatter.fs: add formatConstraintAsText and formatConstraintsAsText using FSharpGenericParameter.Constraints from FCS; supports equality, comparison, struct, reference-type, default-ctor, unmanaged, coercesTo, enum, delegate, and member constraints - ApiDocTypes.fs: add 'constraints: string list' field to ApiDocMemberDetails; add Constraints member and FormatTypeConstraints to ApiDocMember - SymbolReader.fs: compute constraints from generic type parameters and pass to ApiDocMemberDetails; empty list for union cases, fields, static params - GenerateHtml.fs: display 'Constraints:' line after 'Type parameters:'; also fix: type parameters now show independently of modifiers Co-authored-by: Copilot <[email protected]>
|
/repo-assist revisit PR to address analyzer remarks. |
…r.fs Address GRA-INTERPOLATED-001 analyzer warnings by adding %s type specifiers to all 19 interpolated holes in formatConstraintAsText. Co-authored-by: Copilot <[email protected]>
|
Commit pushed:
|
This comment has been minimized.
This comment has been minimized.
|
/repo-assist I'd like this feature to be opt in please, via a documented project setting. This is because the inferred type constraints can be long and verbose and often unhelpful as they might overwhelm. Also please make sure all the project settings that we have available are all documented, may as well do that in this PR too |
…all project settings - Add FsDocsShowTypeConstraints MSBuild property (default: false) - Thread through ProjectCracker → BuildCommand → ApiDocInput → SymbolReader - Gate formatConstraintsAsText behind ctx.ShowTypeConstraints - Add ShowTypeConstraints: bool to ApiDocInput and ReadingContext - Expand docs/commandline.md with comprehensive project settings table - Update RELEASE_NOTES.md to describe the opt-in flag Co-authored-by: Copilot <[email protected]>
|
Commit pushed:
|
This comment has been minimized.
This comment has been minimized.
|
/repo-assist I'd like you to study the "shortConstraints" option in the F# compiler. I want you to make this "Short" form the default behaviour for fsdocs, with the project file setting having values None, Short and Full. Full should be pretty much as you have it. https://github.com/dotnet/fsharp/blob/main/src/Compiler/Checking/NicePrint.fs#L799 Also add systematic tests for everything you've added and update the docs |
…hort/Full) - Replace ShowTypeConstraints: bool with TypeConstraintDisplayMode DU - Short (default): shows constraints inline as 'when' clause - Full: shows separate 'Constraints:' section - None: hides constraints entirely - Update MSBuild property from FsDocsShowTypeConstraints to FsDocsTypeConstraints - Update GenerateMarkdown.fs to also render constraints - Add TypeConstraintTests module to FsLib2 test library - Add 10 systematic NUnit tests covering all modes - Update docs/commandline.md and RELEASE_NOTES.md Co-authored-by: Copilot <[email protected]>
|
Commit pushed:
|
| /// Controls how type constraints on generic members are displayed in generated API docs. | ||
| [<RequireQualifiedAccess>] | ||
| type TypeConstraintDisplayMode = | ||
| /// Do not display type constraints. | ||
| | None | ||
| /// Display constraints inline as a 'when' clause appended to the type parameters (default). | ||
| | Short | ||
| /// Display constraints in a separate 'Constraints:' section in the member tooltip. | ||
| | Full |
Check notice
Code scanning / Ionide.Analyzers.Cli
Short description about StructDiscriminatedUnionAnalyzer Note
|
/repo-assist Fix the code scanning code review alerts |
…matic constraint tests - Short mode now renders constraints as 'T (requires equality) matching the F# compiler's shortConstraints=true DisplayEnv format - Add FormatShortTypeConstraints property that strips the type-variable prefix from constraint strings (e.g. 'T : equality -> equality) - Add requiresCoercion, requiresStruct, requiresUnmanaged test fixtures - Add systematic model-level tests for FormatShortTypeConstraints verifying abbreviation is correct for equality, comparison, coercion, struct - Update Full mode tests to verify full-form 'T : equality text - Update docs and RELEASE_NOTES to describe (requires ...) style Co-authored-by: Copilot <[email protected]>
|
Commit pushed:
|
|
🤖 This is an automated response from Repo Assist. I've updated the PR to implement the ChangesShort mode now uses F# compiler's
|
| Mode | Output example |
|---|---|
None |
No constraint information shown |
Short (default) |
'T (requires equality) inline with type params |
Full |
Separate Constraints: section: 'T : equality |
Tests
Added systematic tests covering:
FormatShortTypeConstraintsabbreviates correctly for equality, comparison, coercion (:>), struct- Short output file contains
requiresandequality/comparisonkeywords - Full output file still shows
Constraints:label with full constraint text - None output file still has no
Constraints:label - New fixtures:
requiresCoercion,requiresStruct,requiresUnmanaged
All 11 constraint tests pass ✅
Generated by Repo Assist for issue #1045
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/repo-assist.md@afb00b92a9514fee9a14c583f059a03d05738f70
| else | ||
| let toShort (full: string) = | ||
| // Coercion: "'T :> Type" → ":> Type" | ||
| let coerceIdx = full.IndexOf(" :> ") |
Check warning
Code scanning / Ionide.Analyzers.Cli
Verifies the correct usage of System.String.IndexOf Warning
| full[coerceIdx + 1 ..] | ||
| else | ||
| // Regular constraint: "'T : equality" → "equality" | ||
| let colonIdx = full.IndexOf(" : ") |
Check warning
Code scanning / Ionide.Analyzers.Cli
Verifies the correct usage of System.String.IndexOf Warning
| if m.TypeConstraintDisplayMode = TypeConstraintDisplayMode.Short then | ||
| match m.FormatShortTypeConstraints with | ||
| | None -> encode v | ||
| | Some c -> encode ($"{v} (requires {c})") |
Check warning
Code scanning / Ionide.Analyzers.Cli
Warns about missing type specifiers in interpolated strings Warning
| if m.TypeConstraintDisplayMode = TypeConstraintDisplayMode.Short then | ||
| match m.FormatShortTypeConstraints with | ||
| | None -> encode v | ||
| | Some c -> encode ($"{v} (requires {c})") |
Check warning
Code scanning / Ionide.Analyzers.Cli
Warns about missing type specifiers in interpolated strings Warning
| if m.TypeConstraintDisplayMode = TypeConstraintDisplayMode.Short then | ||
| match m.FormatShortTypeConstraints with | ||
| | None -> p [ !!("Type parameters: " + v) ] | ||
| | Some c -> p [ !!($"Type parameters: {v} (requires {c})") ] |
Check warning
Code scanning / Ionide.Analyzers.Cli
Warns about missing type specifiers in interpolated strings Warning
| if m.TypeConstraintDisplayMode = TypeConstraintDisplayMode.Short then | ||
| match m.FormatShortTypeConstraints with | ||
| | None -> p [ !!("Type parameters: " + v) ] | ||
| | Some c -> p [ !!($"Type parameters: {v} (requires {c})") ] |
Check warning
Code scanning / Ionide.Analyzers.Cli
Warns about missing type specifiers in interpolated strings Warning
|
Pull request created: #1053
|
🤖 This PR was created by Repo Assist, an automated AI assistant.
Closes #591
Root Cause
Type constraints on generic parameters (e.g.
'T : equality,'T : comparison,'T :> IComparable) were not extracted or displayed in generated API docs. TheFSharpGenericParameter.Constraintsproperty from FCS was available but unused — there was even a commented-out reference toindexedConstraintsatSymbolReader.fs:285.Fix
TypeFormatter.fs: AddedformatConstraintAsTextandformatConstraintsAsTextusingFSharpGenericParameter.Constraintsfrom FCS. Handles:equality,comparison,struct,not struct, default constructor,unmanaged, coercion (:>), enum, delegate, and member constraints.ApiDocTypes.fs: Addedconstraints: string listfield toApiDocMemberDetails; addedConstraintsmember andFormatTypeConstraintstoApiDocMember.SymbolReader.fs: Compute constraints from the sametpslist used for type parameters; pass empty list for union cases, fields, and static params.GenerateHtml.fs: Display aConstraints:line afterType parameters:in the member tooltip. Also fixed a pre-existing issue where type parameters were only shown when modifiers were non-empty.Example
For
val hash : 'T -> int when 'T : equality, the generated docs will now show:Trade-offs
ApiDocMemberDetailsdiscriminated union gained a newconstraintsfield — this is a minor breaking change for any external code that pattern-matches on it (same category of change as any field addition to this DU).(member Foo : 'T -> int)) are formatted usingFSharpDisplayContext.Emptywhich may include fully-qualified type names in some cases.Test Status