[Repo Assist] Fix doc comment (///) at end of file being duplicated#3266
Conversation
A triple-slash doc comment (///) without an associated declaration
was duplicated when formatting. For example, a file containing only:
/// Returns `unit` if validation was successful.
would be formatted to:
/// Returns `unit` if validation was successful.
/// Returns `unit` if validation was successful.
Root cause: in `collectCodeComments` (Parse.fs), when a `///` comment
appears at end-of-file, the lexer saves it in both `CommentStore` (via
`SaveSingleLineComment`) AND `XmlDocStore` (via `SaveXmlDocLine`/
`trySaveXmlDoc`). Both stores are then combined in `collectCodeComments`,
resulting in two identical `LineComment` trivia entries for the same
source range.
Fix: deduplicate the combined comment list by `(StartLine, StartColumn)`
before sorting, so no two entries share the same source position.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/repo-assist looks reasonable but misses a changelog entry. |
- Replace List.distinctBy (runs for every format) with a conditional that only builds a position Set when orphan /// comments exist. For well-formed code tripleSlashComments is empty so there is zero overhead; the Set is only constructed in the rare EOF edge-case. - Add CHANGELOG entry for #2499 under [Unreleased]. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
This comment has been minimized.
This comment has been minimized.
|
/repo-assist you can probably be even more strict when check for the first three |
When deduplicating /// comments that appear in both CommentStore and XmlDocStore at EOF, verify that the LineComment from CommentStore actually starts with '///' before treating it as a duplicate. This is achieved by stashing the ISourceText in lexbuf.BufferLocalStore during createLexbuf and reading it back in collectCodeComments to inspect the character content at the comment's range position. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
|
/repo-assist I think you are not checking if |
…ment-10e89c3f45a0db9c
|
/repo-assist you did not format your code. How dare you! |
- Rewrite `col + 2 < line.Length` as `line.Length > col + 2` for clarity - Replace `List.filter + List.map` with `List.choose` Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
…ment-10e89c3f45a0db9c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
|
🤖 This is an automated response from Repo Assist. My sincerest apologies for the unformatted code! I've now run
|
Closes #2499
Problem
A
///XML doc comment without an associated declaration (e.g. at end of file) was duplicated when formatting:Input:
/// Returns `unit` if validation was successful otherwise will throw an `Exception`.Before this fix:
After this fix:
/// Returns `unit` if validation was successful otherwise will throw an `Exception`.Root cause
In
collectCodeComments(Parse.fs in the vendored FCS), when a///comment is at end-of-file, the lexer saves it in bothCommentStore(viaSaveSingleLineComment) andXmlDocStore(viatrySaveXmlDoc→SaveXmlDocLine). Both stores are then yielded in the combined list, producing two identicalLineCommenttrivia entries at the same source position.This is a lexer-level issue: a
///comment followed by a newline is only saved toXmlDocStore(guarded byif Option.isNone buff), but the EOF case unconditionally calls bothtrySaveXmlDocandCommentStore.SaveSingleLineComment. Sincelex.fsis generated code, the fix is applied inParse.fswhere the two stores are combined.Fix
Deduplicate the combined comment list by
(StartLine, StartColumn)before sorting. No two comments can legitimately share the same source position, so this is safe and has no effect on normal code.Test Status
🤖 This PR was created by Repo Assist, an automated AI assistant. Please review carefully.