Skip to content

feat: Add property-argument highlighting for Serilog templates (#15)#17

Merged
willibrandon merged 3 commits intomainfrom
feature/property-argument-highlighting
Sep 22, 2025
Merged

feat: Add property-argument highlighting for Serilog templates (#15)#17
willibrandon merged 3 commits intomainfrom
feature/property-argument-highlighting

Conversation

@willibrandon
Copy link
Owner

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:

  • Added PropertyArgumentHighlighter that tracks cursor position and highlights matching property-argument pairs using ITagger<TextMarkerTag>
  • Enhanced pattern matching to support ForContext chained calls (.Information() after log.ForContext<T>())
  • Fixed LogError exception parameter handling where template is second parameter after exception
  • Improved brace matching for configuration methods like WriteTo.Console(outputTemplate:...) by checking previous line context
  • Handles all string literal formats (regular, verbatim @"...", raw """...""" with custom delimiters)

Type of change

  • Bug fix
  • New feature
  • Performance improvement
  • Documentation update

Checklist

  • Tests pass (.\scripts\test.ps1)
  • Benchmarks checked (if performance-related)
  • Documentation updated (if needed)

Additional notes

Fixes #15

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
@willibrandon willibrandon self-assigned this Sep 22, 2025
@willibrandon willibrandon added documentation Improvements or additions to documentation enhancement New feature or request visual-studio Visual Studio extension functionality and integration labels Sep 22, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 PropertyArgumentHighlighter that tracks cursor position and highlights matching property-argument pairs
  • Enhanced SerilogBraceMatcher to 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
@willibrandon willibrandon merged commit e213478 into main Sep 22, 2025
1 check passed
@willibrandon willibrandon deleted the feature/property-argument-highlighting branch September 22, 2025 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request visual-studio Visual Studio extension functionality and integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add property-argument highlighting

1 participant