Skip to content

[Repo Assist] Include type constraints in generated API documentation#1045

Open
github-actions[bot] wants to merge 13 commits intomainfrom
repo-assist/fix-issue-591-type-constraints-9dce2011594bb32d
Open

[Repo Assist] Include type constraints in generated API documentation#1045
github-actions[bot] wants to merge 13 commits intomainfrom
repo-assist/fix-issue-591-type-constraints-9dce2011594bb32d

Conversation

@github-actions
Copy link
Contributor

🤖 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. The FSharpGenericParameter.Constraints property from FCS was available but unused — there was even a commented-out reference to indexedConstraints at SymbolReader.fs:285.

Fix

  • TypeFormatter.fs: Added formatConstraintAsText and formatConstraintsAsText using FSharpGenericParameter.Constraints from FCS. Handles: equality, comparison, struct, not struct, default constructor, unmanaged, coercion (:>), enum, delegate, and member constraints.
  • ApiDocTypes.fs: Added constraints: string list field to ApiDocMemberDetails; added Constraints member and FormatTypeConstraints to ApiDocMember.
  • SymbolReader.fs: Compute constraints from the same tps list used for type parameters; pass empty list for union cases, fields, and static params.
  • GenerateHtml.fs: Display a Constraints: line after Type 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:

Type parameters: 'T
Constraints: 'T : equality

Trade-offs

  • The ApiDocMemberDetails discriminated union gained a new constraints field — 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 constraints (SRTP, e.g. (member Foo : 'T -> int)) are formatted using FSharpDisplayContext.Empty which may include fully-qualified type names in some cases.

Test Status

  • Build: ✅ succeeded
  • Tests: ✅ 72/72 passed, 4 skipped (pre-existing)
  • Formatting: ✅ Fantomas applied

Generated by Repo Assist for issue #591

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@afb00b92a9514fee9a14c583f059a03d05738f70

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 <223556219+Copilot@users.noreply.github.com>
@dsyme dsyme marked this pull request as ready for review February 26, 2026 19:03
@nojaf
Copy link
Collaborator

nojaf commented Feb 27, 2026

/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 <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: 1586689

Generated by Repo Assist

@github-actions

This comment has been minimized.

@dsyme
Copy link
Contributor

dsyme commented Feb 27, 2026

/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 <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: 7101a8f

Generated by Repo Assist

@github-actions

This comment has been minimized.

@dsyme
Copy link
Contributor

dsyme commented Feb 27, 2026

/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 <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: bd301a2

Generated by Repo Assist

Comment on lines +113 to +121
/// 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

Consider adding [] to Discriminated Union
@dsyme
Copy link
Contributor

dsyme commented Feb 27, 2026

/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 <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: e7c0282

Generated by Repo Assist

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor Author

Pull request created: #1053

Generated by Repo Assist

@dsyme
Copy link
Contributor

dsyme commented Feb 28, 2026

/repo-assist revisit PR to address analyzer remarks. Make sure you're working on the right branch for thi pull request. We want it clear of warnings e.g.

Interpolated hole expression without format detected. Use prefix with the correct % to enforce type safety.

…TRING-003)

- Add %s format specifiers to interpolated holes in GenerateHtml.fs and GenerateMarkdown.fs
- Use StringComparison.Ordinal in String.IndexOf calls in ApiDocTypes.fs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Contributor Author

Commit pushed: 33a0667

Generated by Repo Assist

@github-actions
Copy link
Contributor Author

🤖 This is an automated response from Repo Assist.

Done! I've pushed a fix to address all remaining analyzer warnings on this PR branch.

Changes made:

  • GenerateHtml.fs:198 — Added %s format specifiers: $"%s{v} (requires %s{c})" (was $"{v} (requires {c})")
  • GenerateMarkdown.fs:96 — Replaced interpolated string with sprintf "Type parameters: %s (requires %s)" v c (was $"Type parameters: {v} (requires {c})")
  • ApiDocTypes.fs:498,504 — Added StringComparison.Ordinal to String.IndexOf calls to fix GRA-STRING-003 warnings from the new FormatShortTypeConstraints code

Verification:

  • Analyzers: ✅ No more GRA-INTERPOLATED-001 or GRA-STRING-003 warnings from new code
  • Build: ✅ succeeded
  • Tests: ✅ 87/87 passed, 4 skipped (pre-existing)
  • Formatting: ✅ Fantomas confirmed no changes needed

Generated by Repo Assist

Generated by Repo Assist for issue #1045

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@afb00b92a9514fee9a14c583f059a03d05738f70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include type constraints in documentation

2 participants