Understanding Code Fixes
When CommentSense detects a documentation issue, it not only reports the diagnostic but also offers one or more code fixes that can automatically correct the problem. These fixes appear as “lightbulb” suggestions in Visual Studio and other IDEs that support Roslyn code fixes.Available Code Fixes
CommentSense offers code fixes for the following scenarios:Missing Documentation
- CSENSE001: Automatically adds a
<summary>tag with a placeholder - CSENSE018: Inserts an
<inheritdoc />tag for inheriting members - CSENSE002/CSENSE004: Generates missing
<param>or<typeparam>tags - CSENSE006: Adds a
<returns>tag for methods with return values - CSENSE014: Inserts a
<value>tag for properties - CSENSE012: Creates
<exception>tags for undocumented thrown exceptions
Stray and Duplicate Tags
- CSENSE003/CSENSE005: Removes stray parameter tags that don’t match any parameter
- CSENSE009/CSENSE011: Removes duplicate parameter documentation
- CSENSE013: Removes stray
<returns>tags from void methods - CSENSE015: Removes stray
<value>tags - CSENSE022: Removes stray or duplicate
<summary>tags - CSENSE023: Removes stray or duplicate
<exception>tags
Tag Ordering
- CSENSE008/CSENSE010: Reorders parameter tags to match the method signature
- CSENSE024: Reorders top-level documentation tags to follow the configured order
Quality Improvements
- CSENSE016: Automatically capitalizes documentation and adds ending punctuation
- CSENSE019: Wraps C# keywords in
<see langword="..." />tags - CSENSE020/CSENSE021: Wraps parameter references in
<paramref />or<typeparamref />tags
Using Fix All
One of CommentSense’s most powerful features is Fix All support. Every code fix provider inherits fromCodeFixProviderBase and returns WellKnownFixAllProviders.BatchFixer, enabling bulk operations.
Fix All Scopes
You can apply fixes at different scopes:Fix All in Document
Applies the fix to all instances of the diagnostic in the current file.Use case: Quickly clean up documentation in a single file you’re working on.
Fix All in Project
Applies the fix across all files in the current project.Use case: Standardize documentation across a library or application project.
How Fix All Works
The Fix All logic (implemented inCodeFixProviderBase.FixAllProviderBase) follows this pattern:
- Collect diagnostics for the selected scope (document, project, or solution)
- Group diagnostics by file and by member declaration
- Apply all fixes to each member in a single operation to avoid conflicts
- Replace nodes in the syntax tree with updated versions
- Return the updated document/solution
Intelligent Fixes
Fuzzy Matching for Renames
When you rename a parameter but forget to update the documentation, CommentSense detects the mismatch and offers two fixes:- Remove the stray tag (always available)
- Rename the tag to match the current parameter (when similarity is above threshold)
Context-Aware Tag Insertion
When adding missing tags, CommentSense respects your configured tag order and inserts new tags in the correct position:Best Practices
Use Fix All Strategically
Start with “Fix All in Document” to see the changes. Once you’re confident, scale up to project or solution level.
Review Placeholders
Code fixes insert
[Documentation placeholder] text. Replace these with meaningful descriptions.Configure Before Fixing
Set up your
.editorconfig with tag order, langwords, and other preferences before running Fix All.Combine with Source Control
Use Fix All on a separate branch or commit so you can review the changes before merging.
Keyboard Shortcuts
In Visual Studio:- Ctrl + . or Alt + Enter: Show available code fixes
- Ctrl + ., then Tab: Preview Fix All options
- Ctrl + ., Tab, Enter: Apply Fix All in Document