feat: Add property-argument highlighting for Serilog templates (#15)#17
Merged
willibrandon merged 3 commits intomainfrom Sep 22, 2025
Merged
Conversation
Highlights the connection between template properties and their corresponding arguments when cursor is positioned on either. Supports all Serilog logging patterns including multi-line strings, ForContext chaining, LogError with exceptions, and collection expressions. Also improves brace matching for configuration methods like WriteTo.Console. The changes include: - New PropertyArgumentHighlighter and PropertyArgumentHighlighterProvider classes - Test suite covering all edge cases - Enhanced brace matching to support WriteTo.Console(outputTemplate:...) patterns - Support for all string literal types (regular, verbatim, raw with custom delimiters) - Proper handling of LogError exception parameters - Support for ForContext chained calls with collection expressions
There was a problem hiding this comment.
Pull Request Overview
This PR implements property-argument highlighting for Serilog templates, which visually connects template properties like {UserId} with their corresponding arguments when the cursor is positioned on either element. The feature supports all string literal formats including raw strings with custom delimiters and handles complex scenarios like exception parameters in LogError calls.
- Added
PropertyArgumentHighlighterthat tracks cursor position and highlights matching property-argument pairs - Enhanced
SerilogBraceMatcherto support configuration methods by checking previous line context - Fixed LogError exception parameter handling to correctly map template properties to arguments
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| SerilogSyntax/Tagging/PropertyArgumentHighlighter.cs | Main implementation of property-argument highlighting feature |
| SerilogSyntax/Tagging/PropertyArgumentHighlighterProvider.cs | MEF provider for the highlighter tagger |
| SerilogSyntax/Tagging/SerilogBraceMatcher.cs | Enhanced to support configuration methods on previous lines |
| SerilogSyntax/Classification/SerilogClassificationTypes.cs | Added classification type for property-argument highlights |
| SerilogSyntax/Classification/SerilogClassificationFormats.cs | Added visual format definition for highlights |
| SerilogSyntax.Tests/Tagging/PropertyArgumentHighlighterTests.cs | Comprehensive test suite for the highlighting feature |
| SerilogSyntax.Tests/Tagging/SerilogBraceMatcherTests.cs | Added tests for WriteTo.Console configuration scenarios |
| Example/ExampleService.cs | Fixed casing of ConsoleLoggerScopes variable |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…ighting
Property-argument highlighting no longer triggers on ExpressionTemplate
built-in properties like {@t}, {@l}, {@m}, {@x} since these don't have
corresponding arguments to highlight. Adds test to verify the fix.
Also refactored to use SerilogCallDetector and StringLiteralParser
utilities to eliminate duplicate regex patterns
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.
Description
When cursor is positioned on a Serilog template property like
{UserId}or its corresponding argument, both the property and argument are now highlighted to show their connection. This visual feedback makes it easier to match properties with their values, especially in complex logging calls with multiple parameters.Solution:
PropertyArgumentHighlighterthat tracks cursor position and highlights matching property-argument pairs usingITagger<TextMarkerTag>.Information()afterlog.ForContext<T>())WriteTo.Console(outputTemplate:...)by checking previous line context@"...", raw"""..."""with custom delimiters)Type of change
Checklist
.\scripts\test.ps1)Additional notes
Fixes #15