Skip to content

Add unit tests demonstrating code fix failures in method argument contexts#211

Closed
Copilot wants to merge 5 commits intomainfrom
copilot/fix-whitespace-issue-analyzers
Closed

Add unit tests demonstrating code fix failures in method argument contexts#211
Copilot wants to merge 5 commits intomainfrom
copilot/fix-whitespace-issue-analyzers

Conversation

Copy link
Contributor

Copilot AI commented Dec 29, 2025

Usage analyzer code fix providers fail when static method invocations appear as method arguments rather than variable assignments. The issue affects GetNames, GetValues, Parse, IsDefined, and similar analyzers but not instance method analyzers like ToString and HasFlag.

Changes

  • Added whitespace preservation tests for all usage analyzers covering:

    • Method argument contexts: SomeMethod(Enum.GetNames(typeof(MyEnum)))
    • Extra indentation scenarios
    • Non-assignment expressions (if statements, foreach loops)
  • Test Results:

    • ✅ Instance method analyzers (ToString, HasFlag): All tests pass
    • ❌ Static method analyzers (GetNames, GetValues, Parse, IsDefined, TryParse): Method argument tests fail
    • ✅ Static method analyzers in assignment contexts: Tests pass
  • Attempted Fix in GetNamesCodeFixProvider:

    • Changed from generator.InvocationExpression() with .WithTriviaFrom()
    • To SyntaxFactory.InvocationExpression() with explicit .WithLeadingTrivia() and .WithTrailingTrivia()
    • Issue persists, indicating deeper DocumentEditor node replacement problem

Root Cause

Code fix providers fail when:

  1. Replacing static method calls with different parameter signatures
  2. Target node is embedded in argument list context
  3. Node structure changes significantly (e.g., Enum.GetNames(typeof(T))TExtensions.GetNames())

The tests successfully reproduce the issue and will serve as regression tests once the underlying Roslyn DocumentEditor behavior is properly addressed.

Example Failure

// Test expects this transformation:
SomeMethod(Enum.GetNames(typeof(MyEnum)));
// →
SomeMethod(MyEnumExtensions.GetNames());

// But code fix is not applied at all in this context
// Works correctly when: var names = Enum.GetNames(typeof(MyEnum));
Original prompt

This section details on the original issue you should resolve

<issue_title>Fix whitespace issue in usage analyzers</issue_title>
<issue_description>When working on the usage analyzers for switching to the extension methods, we noticed that in unit tests, where the call is not assigning to a variable, we are sometimes generating the incorrect leading trivia.

We should create unit tests demonstrating the issue for all the analyzers first, and try to understand what's going on and resolve the issue creating incorrect spacing.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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 changed the title [WIP] Fix whitespace issue in usage analyzers Add unit tests demonstrating code fix failures in method argument contexts Dec 29, 2025
Copilot AI requested a review from andrewlock December 29, 2025 22:48
@github-actions
Copy link

github-actions bot commented Dec 29, 2025

Test Results

0 files   -     216  0 suites   - 216   0s ⏱️ - 6h 53m 40s
0 tests  -  29 013  0 ✅  -  29 009  0 💤  -  4  0 ❌ ±0 
0 runs   - 514 243  0 ✅  - 514 171  0 💤  - 72  0 ❌ ±0 

Results for commit 0875df1. ± Comparison against base commit 7a42405.

♻️ This comment has been updated with latest results.

Copilot AI and others added 5 commits February 24, 2026 20:17
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
…sage

Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
@andrewlock andrewlock force-pushed the copilot/fix-whitespace-issue-analyzers branch from bcb387a to 0875df1 Compare February 24, 2026 20:20
@andrewlock
Copy link
Owner

This doesn't work, giving up

@andrewlock andrewlock closed this Feb 25, 2026
@andrewlock andrewlock deleted the copilot/fix-whitespace-issue-analyzers branch February 25, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix whitespace issue in usage analyzers

2 participants