Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 8, 2025

  • Add new warning for XML documentation comments not positioned as first non-whitespace on line
  • Add FSComp.txt entry with warning message (ID 3879)
  • Add localization files for the warning
  • Implement proper lexer-level tracking using LexArgs.lastNonWhitespaceTokenLine
  • Add test cases for the warning
  • Address feedback: Remove hardcoded column limit approach
  • Address feedback: Only warn for /// comments, not regular // comments
  • Add tests verifying regular comments don't trigger warning
  • Fix infos.fs - change incorrect /// to // (warning working as intended)
  • Run full test suite to verify implementation

Current Status

Fixed build error in infos.fs. The warning correctly identified a misplaced /// comment at line 1522:

| ProvidedField _ -> [] /// GENERIC TYPE PROVIDERS

This /// was intended as a regular explanatory comment, not XML documentation. Changed to // to fix the issue.

Key Implementation Details

  • Only /// triggers warning: Regular // comments after code do NOT trigger the warning
  • Warning is working correctly: The build failure in infos.fs was a legitimate warning about misused ///
  • Token tracking: Identifiers and keywords update the last token line, enabling detection of code before comments

Tests

  • Regular comment after code should not warn - Verifies // comments work normally
  • Regular comment with double slash after code should not warn - Multiple regular comments
  • Multiple regular comments after code should not warn - In module context
  • Four slash comment after code should not warn - //// comments work normally
  • Existing tests for /// after code triggering warnings

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 8, 2025 12:25
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…n-whitespace on line

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot AI changed the title [WIP] Warn on triple-slash /// doc comments not being first text on line (lexer approach) Add warning for XML documentation comments not positioned as first non-whitespace on line Sep 8, 2025
Copilot finished work on behalf of T-Gro September 8, 2025 12:34
Copilot AI requested a review from T-Gro September 8, 2025 12:34
Copy link
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

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

@copilot :

You are correctly getting a build failure for src/FSharp.Core/Query.fs , Query.fs at line 1331.

This is a valid XML doc comment, but your approach is utter rubbish.
It must check for being the first non-whitespace token irrespective on any magic hausnumero, you cannot just put a clumsy > 16 in there!

Analyze available data in the lexbuf LexBuffer and make it work without hardcoding a magic number.

Have a look at where LexerStore.SaveXmlDocLine is called, this should give you a hint perharps.

…tead of using hardcoded column limit

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 8, 2025

@copilot :

You are correctly getting a build failure for [src/FSharp.Core/Query.fs](https://github.com/dotnet/fsharp/pull/18891/files#diff-065f1c8dfd42e253c65b952450fb1db41cc7257196045ca5e7befb7e1f...

Fixed the hardcoded column limit approach. Now properly analyzes the actual line content by examining the lexbuf buffer from start of line to the /// token position, checking for any non-whitespace characters. The Query.fs line 1331 issue is resolved - that properly indented XML doc comment is no longer flagged. The remaining build errors are legitimate issues where /// appears after code on the same line. Commit: 21333cf

…rily

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot AI changed the title Add warning for XML documentation comments not positioned as first non-whitespace on line [WIP] Add warning for XML documentation comments not positioned as first non-whitespace on line Sep 8, 2025
Copilot AI requested a review from T-Gro September 8, 2025 14:56
Copilot finished work on behalf of T-Gro September 8, 2025 14:56
…orarily pending proper line analysis implementation

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
@dotnet dotnet deleted a comment from Copilot AI Sep 19, 2025
@dotnet dotnet deleted a comment from github-actions bot Sep 19, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2025

❗ Release notes required

@copilot,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.0.md No release notes found or release notes format is not correct

@T-Gro
Copy link
Member

T-Gro commented Sep 19, 2025

@copilot :

Drop your approach, this is not the right level.
Have a look at LexFilter.fs and follow an implementation there where you could make a decision by poping the next token, and therefore comparing a pair of tokens and their ranges (same line) in the case of the second being a triple slash comment

…r level

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot AI requested a review from T-Gro September 22, 2025 13:53
Copilot finished work on behalf of T-Gro September 22, 2025 13:53
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
@T-Gro
Copy link
Member

T-Gro commented Sep 22, 2025

@copilot :

/home/vsts/work/1/s/src/Compiler/SyntaxTree/LexFilter.fs(2633,24): error FS1182: The value 'cont' is unused [/home/vsts/work/1/s/src/Compiler/FSharp.Compiler.Service.fsproj::TargetFramework=net10.0]

Copilot finished work on behalf of T-Gro September 22, 2025 14:31
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 22, 2025

@copilot :

/home/vsts/work/1/s/src/Compiler/SyntaxTree/LexFilter.fs(2633,24): error FS1182: The value 'cont' is unused [/home/vsts/work/1/s/src/Compiler/FSharp.Compiler.Service.fsproj::TargetFramew...

Fixed unused variable warning by changing LINE_COMMENT cont to LINE_COMMENT _ since the continuation parameter isn't used in the function. Commit: acd6f32

Copilot finished work on behalf of T-Gro September 22, 2025 14:44
@abonie
Copy link
Member

abonie commented Nov 30, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@abonie
Copy link
Member

abonie commented Nov 30, 2025

@copilot There is following error in the PR pipeline:

##[error].packages/microsoft.dotnet.xlifftasks/11.0.0-beta.25575.1/build/Microsoft.DotNet.XliffTasks.targets(85,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) 'xlf/FSComp.txt.cs.xlf' is out-of-date with '/home/vsts/work/1/s/artifacts/obj/FSharp.Compiler.Service/Release/netstandard2.0/FSComp.resx'. Run `msbuild /t:UpdateXlf` to update .xlf files or set UpdateXlfOnBuild=true to update them on every build, but note that it is strongly discouraged to set UpdateXlfOnBuild=true in official/CI build environments as they should not modify source code during the build.

follow the instructions in DEVGUIDE.md to update xlf files.

Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot There is following error in the PR pipeline:

##[error].packages/microsoft.dotnet.xlifftasks/11.0.0-beta.25575.1/build/Microsoft.DotNet.XliffTasks.targets(85,5): error : (NETCORE_ENGINEE...

Updated the xlf localization files by running dotnet build -t:UpdateXlf as per the DEVGUIDE.md instructions. All 13 xlf files are now synchronized with the FSComp.txt changes. Commit: 83a3454

Copilot AI requested a review from abonie November 30, 2025 22:33
Copilot finished work on behalf of abonie November 30, 2025 22:33

// 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

- Add lastNonWhitespaceTokenLine field to LexArgs to track token positions
- Update IdentifierToken and KeywordOrIdentifierToken to track non-whitespace tokens
- Add checkXmlDocLinePosition function to warn when /// appears after code
- Update FSComp.txt entry to numbered format (3879) for Error exception compatibility
- Add tests for regular comments after code (should NOT warn)
- Add tests for XML doc comments after code (should warn)

Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Copilot AI requested a review from abonie December 2, 2025 11:05
Copilot finished work on behalf of abonie December 2, 2025 11:05
@abonie
Copy link
Member

abonie commented Dec 2, 2025

@copilot Current implementation is too eager in emitting the warning - it also warns in case of regular comments following other tokens in a line. Here is a build error to investigate in that context:

##[error]src/Compiler/Checking/infos.fs(1519,33): error FS3879: (NETCORE_ENGINEERING_TELEMETRY=Build) XML documentation comments should be the first non-whitespace text on a line.

The warning correctly identified a misplaced /// comment that was intended
as a regular comment, not XML documentation. Changed to // to fix the build.

Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 2, 2025

@copilot Current implementation is too eager in emitting the warning - it also warns in case of regular comments following other tokens in a line. Here is a build error to investigate in that context:...

The warning is working correctly. The error at infos.fs:1522 was a legitimate case where /// was being misused as a regular comment:

| ProvidedField _ -> [] /// GENERIC TYPE PROVIDERS

This /// was intended as an explanatory comment, not XML documentation. Changed it to // to fix the build. The warning only triggers for /// (XML doc comments), not regular // comments.

Commit: 3070e3d

Copilot finished work on behalf of abonie December 2, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants