Add support for <include> XML documentation tag#19186
Draft
Conversation
Copilot
AI
changed the title
[WIP] Add support for <include> XML documentation tag
Add support for Dec 31, 2025
<include> XML documentation tag
Member
|
/run fantomas |
Contributor
❗ Release notes required
|
Contributor
🔧 CLI Command Report
✅ Patch applied: |
Member
|
/run ilverify |
Contributor
🔧 CLI Command Report
✅ Command succeeded, no changes needed. |
Member
|
/run ilverify |
Contributor
🔧 CLI Command Report
✅ Patch applied: |
T-Gro
added a commit
that referenced
this pull request
Apr 21, 2026
Implement support for expanding <include file="..." path="..."/> elements in XML doc comments when generating documentation files via --doc. - Add XmlDocIncludeExpander module with file loading, XPath evaluation, circular include detection, and thread-safe caching - Integrate expansion in XmlDocFileWriter before XML text generation - Add diagnostic 3390 (xmlDocIncludeError) for include-related warnings - Add 10 comprehensive tests covering absolute paths, XPath selection, nested includes, circular detection, missing files, and rich XML content - Add test helpers: withXmlDoc, verifyXmlDocContains, verifyXmlDocNotContains Fixes #19175 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ebdd20c to
3ebdd36
Compare
T-Gro
added a commit
that referenced
this pull request
Apr 21, 2026
Implement support for expanding <include file="..." path="..."/> elements in XML doc comments when generating documentation files via --doc. - Add XmlDocIncludeExpander module with file loading, XPath evaluation, circular include detection, and thread-safe caching - Integrate expansion in XmlDocFileWriter before XML text generation - Add diagnostic 3390 (xmlDocIncludeError) for include-related warnings - Add 10 comprehensive tests covering absolute paths, XPath selection, nested includes, circular detection, missing files, and rich XML content - Add test helpers: withXmlDoc, verifyXmlDocContains, verifyXmlDocNotContains Fixes #19175 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implement support for expanding <include file="..." path="..."/> elements in XML doc comments when generating documentation files via --doc. - Add XmlDocIncludeExpander module with file loading, XPath evaluation, circular include detection, and thread-safe caching - Integrate expansion in XmlDocFileWriter before XML text generation - Add diagnostic 3390 (xmlDocIncludeError) for include-related warnings - Add 10 comprehensive tests covering absolute paths, XPath selection, nested includes, circular detection, missing files, and rich XML content - Add test helpers: withXmlDoc, verifyXmlDocContains, verifyXmlDocNotContains Fixes #19175 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rmed include warnings - Replace global static XDocument cache with per-expansion local Dictionary to avoid stale data in IDE/long-running compiler scenarios - Use case-insensitive HashSet for cycle detection (fixes Windows path casing) - Add warnings for <include> elements missing required file/path attributes via 3-state classifyInclude (not-include / malformed / valid) - Thread ExpansionContext record through recursive expansion - Add tests for missing file and path attributes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The ProjectActivePatternInSig test was using the shared global checker instance, causing race conditions when tests run in parallel. Give it a dedicated FSharpChecker instance, matching the pattern used by other project-analysis test modules. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wrap resolveFilePath in try/with to prevent Path.GetFullPath from throwing on malformed include file paths. Convert exceptions to Result.Error so they surface as compiler warnings instead of crashes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Final Status: XML Documentation Include Tag Support ✅
Completed
Test Results
Implementation Details
The implementation processes XML documentation by:
<include file="..." path="..."/>tags in XML doc commentsArchitecture
Clean separation of concerns:
expandIncludes: Entry point, works on XmlDoc line arraysresolveSingleIncludeandexpandAllIncludeNodes: Mutually recursive functions for expansionmayContainInclude: Single helper for quick string checks(|ParsedXmlInclude|_|): Active pattern for parsing include directivesMutual recursion: Uses
rec/andkeywords for clean function interdependency.No string-level recursion: All expansion happens at the XElement level before final string conversion.
Proper node handling: Elements are passed directly to expansion (not just their children), with child nodes processed recursively in a single location.
Performance Optimizations
mayContainIncludehelper used everywhereresolveSingleIncludefunction for all error handlingArray.collectthroughout - no Seq conversion overheadCode Quality Improvements
resolveSingleIncludeandexpandAllIncludeNodesusingandkeyword(|ParsedXmlInclude|_|)for idiomatic include parsingResult.bindandResult.mapfor clean error handlingwhen not (mayContainInclude s))Array.collect- no seq conversionsTesting Approach
All tests use absolute paths to ensure consistent behavior across different compilation scenarios. Tests cover:
In production usage, both absolute and relative paths are supported. Relative paths are resolved relative to the source file location.
Original prompt
Add support for
<include>XML documentation tagImplement support for the
<include file="..." path="..."/>XML documentation tag, allowing F# developers to reference external XML files for documentation. This addresses issue #19175.Background
C# supports
<include>tags in XML doc comments (see C# docs). F# currently does not expand these tags. The goal is to expand<include>elements when generating the XML documentation file via--doc.Files to Create
1.
src/Compiler/SyntaxTree/XmlDocIncludeExpander.fsi2.
src/Compiler/SyntaxTree/XmlDocIncludeExpander.fsCreate a module that:
<include file="..." path="..."/>elements from XmlDoc contentdoc.Range.FileName)XDocument.LoadXPathSelectElements<include>elements with the selected contentSet<string>of in-progress file pathswarning (Error(FSComp.SR.xmlDocIncludeError msg, range))for errors (missing file, bad XPath, etc.)FSharp.Compiler.Caches.Cache<string, Result<XDocument, string>>for thread-safe caching of loaded XML filesKey implementation details:
FSharp.Compiler.IO.FileSystem.FileExistsShimfor file existence checksFSharp.Compiler.DiagnosticsLogger.warningandErrorfor diagnostics (same pattern asXmlDoc.fsline 83)FSharp.Compiler.Caches.CachewithCacheOptions.getDefault StringComparer.OrdinalIgnoreCasefor thread-safe cachingdoc.IsEmptyor if content doesn't contain<include(case-insensitive)<root>...</root>before parsing to handle multiple top-level elements3.
tests/FSharp.Compiler.ComponentTests/Miscellaneous/XmlDocInclude.fsCreate end-to-end compilation tests using the
FSharp.Test.Compilerinfrastructure:Files to Modify
4.
src/Compiler/FSharp.Compiler.Service.fsprojFind these lines:
Add immediately after:
5.
src/Compiler/FSComp.txtFind the xmlDoc error messages section (search for
xmlDocMissingParameterName) and add nearby:6.
src/Compiler/Driver/XmlDocFileWriter.fsAdd to the opens at top:
Modify the
addMemberfunction (around line 86-89):Before:
After: