Add support for <include> XML documentation tag
#19186
Draft
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.
Implements
<include file="..." path="..."/>XML documentation tag support, matching C# functionality. F# developers can now reference external XML files in doc comments.Changes
Core Implementation
XmlDocIncludeExpandermodule: Parses and expands<include>tags recursively with XPath evaluationFSharp.Compiler.Caches.Cachewith case-insensitive path comparisonIntegration
XmlDocFileWriter.fs: CallsexpandIncludesbefore writing XML outputFSComp.txt: Added error 3395 (xmlDocIncludeError) for include-related warningsTest Infrastructure
withXmlDoc,verifyXmlDocContains,verifyXmlDocNotContainsExample Usage
The generated XML documentation will contain the expanded content from the external file.
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: