fix: point analyzer diagnostics to specific parameters instead of methods#4924
Merged
fix: point analyzer diagnostics to specific parameters instead of methods#4924
Conversation
…hods When an analyzer diagnostic is about a specific parameter issue (unknown parameter type, missing data source, wrong argument type), the diagnostic location now points to the offending parameter rather than the method name. This gives users more precise IDE feedback about exactly which parameter has the problem. Analyzers updated: - TimeoutCancellationTokenAnalyzer: points to last parameter when it's not CancellationToken - GlobalTestHooksAnalyzer: points to first unknown parameter - AssemblyTestHooksAnalyzer: points to first unknown parameter - ClassHooksAnalyzer: points to first unknown parameter - InstanceTestHooksAnalyzer: points to first unknown parameter - MatrixAnalyzer: points to parameter with wrong matrix value type - TestMethodParametersAnalyzer: points to first parameter needing data source All locations use the fallback pattern: parameter.Locations.FirstOrDefault() ?? context.Symbol.Locations.FirstOrDefault() to ensure graceful degradation. Closes #4899
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. The change is clean and well-executed. The pattern of using A few observations worth noting:
Good improvement to developer experience — squiggles on the specific bad parameter rather than the whole method name is exactly the right UX. |
thomhurst
added a commit
that referenced
this pull request
Feb 19, 2026
…alyzer PR #4924 introduced a reference to `lastParameter` without declaring it, causing CS0103 build errors. Add the variable declaration and also point the CancellationTokenMustBeLastParameter diagnostic at the actual CancellationToken parameter location.
2 tasks
This was referenced Feb 22, 2026
Open
This was referenced Feb 23, 2026
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CombinedDataSourceAnalyzer(parameter.Locations.FirstOrDefault() ?? context.Symbol.Locations.FirstOrDefault()) to seven other analyzersAnalyzers updated:
CancellationTokenTest plan
GlobalTestHooksAnalyzerTeststo expect diagnostic at parameter locationTestMethodParametersAnalyzerTeststo expect diagnostic at parameter locationAssemblyTestHooksAnalyzer,ClassHooksAnalyzer,InstanceTestHooksAnalyzer(no test files exist)MatrixDataSourceAnalyzerTestspass (the changed diagnostic path has no dedicated test case)TimeoutCancellationTokenAnalyzerTestspass (no test covers the "last param is not CancellationToken" scenario)Closes #4899