Skip to content

Have CompleteStatement handle EOF statements#83205

Merged
mwiemer-microsoft merged 18 commits intomainfrom
copilot/fix-complete-statement-issue
Apr 20, 2026
Merged

Have CompleteStatement handle EOF statements#83205
mwiemer-microsoft merged 18 commits intomainfrom
copilot/fix-complete-statement-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

@mwiemer-microsoft authored:

When there was absolutely no whitespace or trivia after the statement to complete, the complete statement handler would fail with an exception. This PR adds a guard against checking for tokens on the right of the last token in the file to fix this. We also had to update some test code to handle unnoticed exceptions.

This PR also adds some tests to the FindTokenOnRightOfPosition and FindTokenOnLeftOfPosition functions. Those functions implicitly throw when given some invalid positions, a behavior not previously documented, but maybe necessary for other parts of the codebase.

Agent-Logs-Url: https://github.com/dotnet/roslyn/sessions/33cec84c-4105-42df-9d1a-53427e6e70ab

Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix complete statement functionality in top-level code Add regression tests for CompleteStatement with top-level code (C# 9+ global statements) Apr 16, 2026
Copilot AI requested a review from mwiemer-microsoft April 16, 2026 18:04
@mwiemer-microsoft
Copy link
Copy Markdown
Member

They're good tests but they don't pass lol, we need to fix the actual bug first.

@mwiemer-microsoft mwiemer-microsoft changed the title Add regression tests for CompleteStatement with top-level code (C# 9+ global statements) Have CompleteStatement handle EOF statements Apr 16, 2026
@mwiemer-microsoft
Copy link
Copy Markdown
Member

@copilot add tests for the other sections of code I modified, try to test the public functions directly instead of going through the command handler

…n boundary conditions

Agent-Logs-Url: https://github.com/dotnet/roslyn/sessions/7e632c50-f6c2-4baa-be77-58e0b6502157

Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 17, 2026

They're good tests but they don't pass lol, we need to fix the actual bug first.

The bug is fixed in commit 38f8fca7 (the guards in FindTokenOnRightOfPosition/FindTokenOnLeftOfPosition). My top-level code tests should now pass with that fix in place.

@copilot add tests for the other sections of code I modified, try to test the public functions directly instead of going through the command handler

Added 6 tests in SyntaxNodeTests.cs (commit 27ea2780) that directly call FindTokenOnRightOfPosition and FindTokenOnLeftOfPosition to cover the boundary conditions introduced by both guards:

  • FindTokenOnRightOfPosition at EOF, past EOF → default
  • FindTokenOnRightOfPosition at valid start position → correct token
  • FindTokenOnLeftOfPosition at SOF, past EOF → default
  • FindTokenOnLeftOfPosition at EOF → last real token

@mwiemer-microsoft
Copy link
Copy Markdown
Member

mwiemer-microsoft commented Apr 17, 2026

The four AfterFirst___Argument tests are failing, everything else looks good, debugging now

src\EditorFeatures\CSharpTest\Completion\CompletionProviders\SuggestionModeCompletionProviderTests.cs:

  • AfterFirstExplicitArgument
  • AfterFirstImplicitArgument
  • AfterFirstImplicitArgumentInMethodCall
  • AfterFirstExplicitArgumentInMethodCall

Assert.NotNull(finalMethodDecl);
Assert.NotEqual(finalMethodDecl, methodDecl);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

with the changes reverted in SyntaxNodeExtensions these tests can also be reverted

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think more tests are good, would you prefer these come in a separate PR though? I specifically kept the non-controversial behavior ones only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we need more tests then it'd be good to have a separate PR explaining that -- otherwise it's odd why we're adding tests for helpers that we're not really changing.

@mwiemer-microsoft
Copy link
Copy Markdown
Member

Test failure on cdf6cdf was transient Helix failure, should be resolved in this run

Comment thread src/Workspaces/CoreTest/SyntaxNodeTests.cs Outdated
Comment thread src/Workspaces/CoreTest/SyntaxNodeTests.cs Outdated
public void FindTokenOnRightOfPosition_AtStartOfFile_ReturnsTokenAtStartOfFile()
{
var root = GetRootForFindTokenTests();
var token = root.FindTokenOnRightOfPosition(root.FullSpan.Start);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why no FindTokenOnRightOfPosition for root.FullSpan.End?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we are discussing internally, it will be a separate PR if it's added :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's one more test here? Why a whole different pr for that?

@mwiemer-microsoft mwiemer-microsoft enabled auto-merge (squash) April 17, 2026 22:35
Assert.NotNull(finalMethodDecl);
Assert.NotEqual(finalMethodDecl, methodDecl);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we need more tests then it'd be good to have a separate PR explaining that -- otherwise it's odd why we're adding tests for helpers that we're not really changing.

@mwiemer-microsoft
Copy link
Copy Markdown
Member

mwiemer-microsoft commented Apr 20, 2026

Last failure looks like transient Helix issue:

  1. https://github.com/dotnet/roslyn/pull/83205/checks?check_run_id=71916148773
  2. https://dev.azure.com/dnceng-public/public/_build/results?buildId=1384938&view=logs&jobId=4f4b926f-8abe-5536-d4a9-2361289b3c74&j=4f4b926f-8abe-5536-d4a9-2361289b3c74&t=9c448d94-9b37-5a69-a1cf-b85a48a8c8cf
  3. https://helixr1107v0xdeko0k025g8.blob.core.windows.net/dotnet-roslyn-refs-pull-83205-merge-02e6000172304f8484/workitem_6/1/console.044d2f23.log?helixlogtype=result
...
  Passed Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertToRecord.ConvertToRecordCodeRefactoringTests.TestMovePropertiesAndDeleteSimpleEquals1 [182 ms]
  Passed Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertToRecord.ConvertToRecordCodeRefactoringTests.TestSelectOnProperty_NoAction [130 ms]
The active test run was aborted. Reason: Test host process crashed
Data collector 'Blame' message: procdump64.exe could not be found, please make sure that the executable is available on PATH. Alternatively set PROCDUMP_PATH environment variable to a directory that contains procdump64.exe executable.
Data collector 'Blame' message: The specified inactivity time of 15 minutes has elapsed. Collecting hang dumps from testhost and its child processes.
Data collector 'Blame' message: Dumping 4436 - testhost.net472.x86.
Results File: work-item-test-results.xml

Attachments:
  C:\h\w\97EA08AA\w\B24A09DF\e\de864d46-fcbb-411c-885f-118fcc3960e8\Sequence_172858858def4bb2b7ae8c98dd15f394.xml
  C:\h\w\97EA08AA\w\B24A09DF\e\de864d46-fcbb-411c-885f-118fcc3960e8\testhost.net472.x86_4436_20260418T002403_hangdump.dmp
Test Run Aborted.
Total tests: Unknown
     Passed: 9821
    Skipped: 39
 Total time: 26.2168 Minutes

The active Test Run was aborted because the host process exited unexpectedly. Please inspect the call stack above, if available, to get more information about where the exception originated from.
The test running when the crash occurred: 
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.ConvertToRecord.ConvertToRecordCodeRefactoringTests.TestMovePropertiesAndProvideThisInitializerValuesComplex

This test may, or may not be the source of the crash.
...

Going to manually trigger re-run of the failing job and work with coworkers to confirm:

You have successfully requested roslyn-CI (Windows_Release_Desktop Test_Windows_Desktop_Release_32) be rerun.

@mwiemer-microsoft mwiemer-microsoft merged commit 135e26f into main Apr 20, 2026
24 of 25 checks passed
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Apr 20, 2026
@mwiemer-microsoft mwiemer-microsoft deleted the copilot/fix-complete-statement-issue branch April 20, 2026 19:47
333fred added a commit to 333fred/roslyn that referenced this pull request Apr 20, 2026
…ture

* upstream/main: (77 commits)
  Fix ArgumentNullException in VB Edit and Continue (dotnet#83250)
  Fix property pattern completion filtering out member being edited (dotnet#83230)
  Add branch merge skill (dotnet#83229)
  [main] Source code updates from dotnet/dotnet (dotnet#83215)
  Support MatchPriority comparison in LSP completion (dotnet#83164)
  Have CompleteStatement handle EOF statements (dotnet#83205)
  Minor cleanups related to attributes in VB (dotnet#83206)
  Simplify
  Address additional PR feedback
  Port remaining unit test projects to Linux (dotnet#83153)
  Unsafe evolution: allow unsafe property accessors (dotnet#83115)
  Address PR review feedback
  Allow cohost rename in Razor source-generated docs
  Refine code review skill (dotnet#82666)
  Review feedback
  Allow creation of DocumentUri instances even if System.Uri cannot parse it
  Improve TextLine and line table performance by packing existing data into unused bits (dotnet#83000)
  Skip TestFindReferencesAsync_UsingAlias on non-Windows platforms (dotnet#83188)
  [main] Source code updates from dotnet/dotnet (dotnet#83174)
  fix comment
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete statement doesnt work in top-level code

6 participants