Skip to content

Commit e213478

Browse files
authored
feat: Add property-argument highlighting for Serilog templates (#17)
Highlights the connection between template properties and their corresponding arguments when cursor is on either. Pressing ESC dismisses highlights. - Highlights both property and argument when cursor is on either one - Supports all string formats (regular, verbatim, raw strings) - Handles special cases (LogError exceptions, positional parameters, anonymous objects) - Excludes ExpressionTemplate contexts where properties have no arguments
2 parents 315eb0f + 65fbe7c commit e213478

File tree

12 files changed

+1796
-11
lines changed

12 files changed

+1796
-11
lines changed

CLAUDE.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ This extension provides syntax highlighting and navigation for Serilog message t
157157
- **Syntax highlighting** for Serilog.Expressions filter syntax and expression templates
158158
- **Navigation** support (Go to Definition) between template properties and arguments
159159
- **Brace matching** for template property delimiters and expression templates
160+
- **Property-argument highlighting** shows connections between properties and arguments on cursor position
160161

161162
### Technical Stack
162163
- **Roslyn Classification API** - For syntax highlighting via `IClassifier`
@@ -194,14 +195,15 @@ The extension includes these components:
194195
3. **Classification/SerilogClassifierProvider.cs** - MEF export for classifier
195196
4. **Navigation/SerilogNavigationProvider.cs** - Navigation from properties to arguments via light bulb
196197
5. **Tagging/SerilogBraceMatcher.cs** - Implements `ITagger<TextMarkerTag>` for brace matching
197-
6. **Utilities/SerilogCallDetector.cs** - Centralized Serilog call detection logic
198-
7. **Utilities/LruCache.cs** - Thread-safe LRU cache for parsed templates
198+
6. **Tagging/PropertyArgumentHighlighter.cs** - Implements `ITagger<TextMarkerTag>` for property-argument highlighting
199+
7. **Utilities/SerilogCallDetector.cs** - Centralized Serilog call detection logic
200+
8. **Utilities/LruCache.cs** - Thread-safe LRU cache for parsed templates
199201

200202
#### Serilog.Expressions Support
201-
8. **Expressions/ExpressionTokenizer.cs** - Tokenizes Serilog.Expressions syntax
202-
9. **Expressions/ExpressionParser.cs** - Parses expressions and templates into classified regions
203-
10. **Expressions/ExpressionDetector.cs** - Detects expression contexts (filter, template, etc.)
204-
11. **Classification/SyntaxTreeAnalyzer.cs** - Roslyn-based analysis for expression contexts
203+
9. **Expressions/ExpressionTokenizer.cs** - Tokenizes Serilog.Expressions syntax
204+
10. **Expressions/ExpressionParser.cs** - Parses expressions and templates into classified regions
205+
11. **Expressions/ExpressionDetector.cs** - Detects expression contexts (filter, template, etc.)
206+
12. **Classification/SyntaxTreeAnalyzer.cs** - Roslyn-based analysis for expression contexts
205207

206208
### Performance Considerations
207209
- LRU cache for parsed templates (10x improvement for repeated templates)

Example/ExampleService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public class ExampleService(ILogger<ExampleService> logger)
44
{
5-
private static readonly string[] consoleLoggerScopes = [nameof(RunExamplesAsync), nameof(ConsoleLoggerEmulationExample)];
5+
private static readonly string[] ConsoleLoggerScopes = [nameof(RunExamplesAsync), nameof(ConsoleLoggerEmulationExample)];
66

77
public async Task RunExamplesAsync()
88
{
@@ -512,7 +512,7 @@ private async Task ConsoleLoggerEmulationExample()
512512
program.Information("Host listening at {ListenUri}", "https://hello-world.local");
513513

514514
program
515-
.ForContext("Scope", consoleLoggerScopes)
515+
.ForContext("Scope", ConsoleLoggerScopes)
516516
.Information("HTTP {Method} {Path} responded {StatusCode} in {Elapsed:0.000} ms", "GET", "/api/hello", 200, 1.23);
517517

518518
program.Warning("We've reached the end of the line");

Example/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Open `Program.cs` in Visual Studio with the Serilog Syntax extension installed t
9191
### Interactive Features
9292
- **Brace matching** when cursor is on `{` or `}`
9393
- **Light bulb navigation** from properties to arguments
94+
- **Property-argument highlighting** when cursor is on either a property or argument
9495
- **Immediate highlighting** as you type (before closing quotes)
9596
- **Multi-line support** for verbatim and raw strings
9697

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ A Visual Studio 2022 extension that provides syntax highlighting, brace matching
4949
- **Navigate to argument** - jump from template properties to their corresponding arguments
5050
- Click the light bulb and select "Navigate to 'PropertyName' argument"
5151

52+
### 🔦 Property-Argument Highlighting
53+
- **Interactive highlighting** of property-argument connections
54+
- When cursor is on a template property (e.g., `{UserId}`), both the property and its corresponding argument are highlighted
55+
- When cursor is on an argument, both the argument and its template property are highlighted
56+
- Works across all string literal types (regular, verbatim `@"..."`, raw `"""..."""`)
57+
- Supports complex scenarios including multi-line templates, collection expressions, and LogError with exception parameters
58+
5259
### 🔍 Brace Matching
5360
- Highlight matching braces when cursor is positioned on `{` or `}`
5461
- Visual indication of brace pairs in complex templates
@@ -246,6 +253,7 @@ Key components:
246253
- `SerilogClassifier` - Handles syntax highlighting with smart cache invalidation
247254
- `SerilogBraceMatcher` - Provides brace matching
248255
- `SerilogNavigationProvider` - Enables property-to-argument navigation
256+
- `PropertyArgumentHighlighter` - Highlights property-argument connections on cursor position
249257
- `SerilogCallDetector` - Optimized Serilog call detection with pre-check optimization
250258
- `SerilogThemeColors` - Theme-aware color management with WCAG AA compliance
251259
- `TemplateParser` - Parses Serilog message templates

0 commit comments

Comments
 (0)