Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5c1cb81
Initial plan
Copilot Sep 8, 2025
1713662
Add basic XML doc comment position warning - initial implementation
Copilot Sep 8, 2025
8698eef
Add warning for XML documentation comments not positioned as first no…
Copilot Sep 8, 2025
21333cf
Fix XML doc comment position check to analyze actual line content ins…
Copilot Sep 8, 2025
7d2be7e
Address feedback by disabling hardcoded column limit approach tempora…
Copilot Sep 8, 2025
6413c55
Merge branch 'main' into copilot/fix-920e1d4e-0c13-4c25-8d7b-183dbc29…
T-Gro Sep 18, 2025
92f2c02
Address feedback: remove hardcoded column limit, disable warning temp…
Copilot Sep 19, 2025
e12e8cc
Implement XML doc comment position check in LexFilter instead of lexe…
Copilot Sep 19, 2025
fb42cf8
Merge branch 'main' into copilot/fix-920e1d4e-0c13-4c25-8d7b-183dbc29…
T-Gro Sep 22, 2025
28a6204
Fix type constraint mismatch in FSComp.SR.xmlDocNotFirstOnLine() usage
Copilot Sep 22, 2025
56607de
Fix unused variable warning in LexFilter pattern match
Copilot Sep 22, 2025
9d9a664
Merge branch 'main' into copilot/fix-920e1d4e-0c13-4c25-8d7b-183dbc29…
T-Gro Oct 17, 2025
83a3454
Update xlf localization files for xmlDocNotFirstOnLine entry
Copilot Nov 30, 2025
bd22c0e
Add lexer-level tracking for XML doc comment position warning
Copilot Dec 2, 2025
3070e3d
Fix incorrect /// comment usage in infos.fs - should be //
Copilot Dec 2, 2025
1f45f17
Disable XML doc position warning - implementation too aggressive
Copilot Dec 3, 2025
4ac9a26
Re-implement XML doc comment position warning using token position tr…
Copilot Dec 3, 2025
a560672
Add token position tracking to more token types and start updating tests
Copilot Dec 3, 2025
3f936f2
Update XmlDocTests to expect FS3879 warning for misplaced /// comments
Copilot Dec 3, 2025
df81dfb
Fix remaining test failures: update neg45.bsl baseline and type membe…
Copilot Dec 3, 2025
fc51e55
Fix code formatting in LexHelpers.fs and LexHelpers.fsi
Copilot Dec 3, 2025
4b58239
Merge branch 'main' into copilot/fix-920e1d4e-0c13-4c25-8d7b-183dbc29…
abonie Dec 5, 2025
c24643d
Update neg45.bsl baseline with all three FS3879 warnings
Copilot Dec 5, 2025
c2736dc
Fix /// comment in Trimming/Program.fs that was causing build failures
Copilot Dec 5, 2025
e171853
Change triple slash to regular comments
abonie Dec 8, 2025
b4a85cb
Fix XML documentation comment parse errors
abonie Dec 8, 2025
b3984a0
Undo changes to neg45.bsl
abonie Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1813,4 +1813,5 @@ featureAllowLetOrUseBangTypeAnnotationWithoutParens,"Allow let! and use! type an
3876,lexWarnDirectivesMustMatch,"There is another %s for this warning already in line %d."
3877,lexLineDirectiveMappingIsNotUnique,"The file '%s' was also pointed to in a line directive in '%s'. Proper warn directive application may not be possible."
3878,tcAttributeIsNotValidForUnionCaseWithFields,"This attribute is not valid for use on union cases with fields."
3879,xmlDocNotFirstOnLine,"XML documentation comments should be the first non-whitespace text on a line."
featureReturnFromFinal,"Support for ReturnFromFinal/YieldFromFinal in computation expressions to enable tailcall optimization when available on the builder."
29 changes: 29 additions & 0 deletions src/Compiler/SyntaxTree/LexFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,33 @@
delayToken tokenTup
true

and checkXmlDocCommentPosition(tokenTup: TokenTup) =
// Check if the current token is a LINE_COMMENT that appears after other content
match tokenTup.Token with
| LINE_COMMENT cont ->
let commentStartPos = startPosOfTokenTup tokenTup
let lastTokenEndPos = tokenTup.LastTokenPos

// Check if this comment appears after other content on the same line
if lastTokenEndPos.Line = commentStartPos.Line && commentStartPos.Column > 0 then
// This comment appears after other tokens on the same line
//
// We need to be careful here - we want to warn about XML doc comments (///)
// but not regular comments (//).
//
// For now, let's be conservative and only warn in cases where it's likely
// an XML documentation comment. We can infer this from context:
// - The comment appears after what looks like a declaration or definition
// - The comment is positioned in a way that suggests it was meant as documentation

// For the initial implementation, let's warn about LINE_COMMENTS that appear
// immediately after tokens on the same line. This will catch the obvious cases
// of misplaced /// comments. We may need to refine this later.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Add tests that make sure a regular comments (not the /// xml comments) can still appear after some other tokens on the same line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for regular comments. The implementation now properly distinguishes /// XML doc comments from regular // comments by tracking non-whitespace token positions at the lexer level. Tests added:

  • Regular comment after code should not warn
  • Regular comment with double slash after code should not warn
  • Multiple regular comments after code should not warn
  • Four slash comment after code should not warn

Commit: bd22c0e


warn tokenTup (FSComp.SR.xmlDocNotFirstOnLine())

Check failure on line 2653 in src/Compiler/SyntaxTree/LexFilter.fs

View workflow job for this annotation

GitHub Actions / copilot

Type constraint mismatch. The type � 'int * string' �is not compatible with type� 'string'
| _ ->
() // Not a comment, nothing to check

and rulesForBothSoftWhiteAndHardWhite(tokenTup: TokenTup) =
match tokenTup.Token with
| HASH_IDENT ident ->
Expand Down Expand Up @@ -2750,6 +2777,8 @@
true

| _ ->
// Check for XML documentation comments positioned incorrectly after code
checkXmlDocCommentPosition tokenTup
false

and pushCtxtSeqBlock fallbackToken addBlockEnd =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.ComponentTests.Language

open Xunit
open FSharp.Test

module XmlDocCommentPositionTests =

[<Fact>]
let ``XML doc comment after code should warn``() =
FSharp """
let x = 42 /// This should trigger warning
"""
|> compile
|> shouldFail
|> withDiagnostics [
(Warning 3537, Line 2, Col 25, Line 2, Col 28, "XML documentation comments should be the first non-whitespace text on a line.")
]

[<Fact>]
let ``XML doc comment at start of line should not warn``() =
FSharp """
/// This is proper documentation
let x = 42
"""
|> compile
|> shouldSucceed

[<Fact>]
let ``XML doc comment with indentation should not warn``() =
FSharp """
module Test =
/// This is properly indented
let x = 42
"""
|> compile
|> shouldSucceed

[<Fact>]
let ``XML doc comment after let binding should warn``() =
FSharp """
let value = "test" /// Bad position
"""
|> compile
|> shouldFail
|> withDiagnostics [
(Warning 3537, Line 2, Col 25, Line 2, Col 28, "XML documentation comments should be the first non-whitespace text on a line.")
]
Loading