Skip to content

Fix multi-line Serilog template navigation position calculation#14

Merged
willibrandon merged 2 commits intomainfrom
fix/multi-line-navigation
Sep 9, 2025
Merged

Fix multi-line Serilog template navigation position calculation#14
willibrandon merged 2 commits intomainfrom
fix/multi-line-navigation

Conversation

@willibrandon
Copy link
Owner

@willibrandon willibrandon commented Sep 9, 2025

Description

Multi-line navigation in the Serilog extension worked but highlighted incorrect arguments due to position calculation errors. Navigation would appear for some properties but select the wrong corresponding arguments because of whitespace and position offset issues in multi-line string templates.

Root cause: Three position calculation issues were causing multi-line navigation failures:

  1. Multi-line template detection failed when cursor was positioned on the first line of a multi-line template
  2. Template end position calculation returned the position of the closing quote instead of the position after it, causing argument parsing to start at the wrong location
  3. Argument parsing was starting from the comma delimiter position instead of after the comma, creating spurious first arguments and shifting all subsequent argument positions

Solution:

  • Added fallback to ReconstructMultiLineTemplate() when single-line template detection fails to handle cursors on first line of multi-line templates
  • Fixed template end position calculation by changing absolutePosition - 1 to absolutePosition + 1 to point after the closing quote
  • Enhanced argument parsing in FindArgumentInMultiLineCall() to find comma delimiter and start parsing from commaIndex + 1 instead of the comma position
  • Added test coverage for verbatim strings (@"..."), raw string literals ("""..."""), and regular multi-line string scenarios

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 #11

- Fix template detection for multi-line verbatim and raw string literals
- Correct argument position calculation by starting after comma delimiter
- Add multi-line navigation test coverage
- Handle template end position calculation for proper argument parsing

Fixes navigation from template properties to arguments when Serilog calls span multiple lines, including verbatim strings (@"...") and raw string literals ("""...""").
@willibrandon willibrandon self-assigned this Sep 9, 2025
@willibrandon willibrandon added bug Something isn't working visual-studio Visual Studio extension functionality and integration labels Sep 9, 2025
@willibrandon willibrandon requested a review from Copilot September 9, 2025 06:51
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 fixes multi-line Serilog template navigation position calculation issues that caused incorrect argument highlighting. The navigation would appear for some properties but select the wrong corresponding arguments due to whitespace and position offset errors in multi-line string templates.

Key changes include:

  • Enhanced multi-line template detection to handle cursors positioned on the first line of multi-line templates
  • Fixed template end position calculation to correctly identify where arguments start
  • Improved argument parsing to handle comma delimiters properly in multi-line method calls

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
SerilogNavigationProvider.cs Core navigation logic with multi-line template detection, position calculation fixes, and argument parsing improvements
SerilogClassifier.cs Added multi-line Serilog call detection to support classification across multiple lines
SerilogNavigationProviderTests.cs Comprehensive test coverage for multi-line scenarios including verbatim strings, raw string literals, and complex formatting
SerilogClassifierTests.cs Added test for multi-line LogError classification behavior
ExampleService.cs Added example of multi-line LogError call for testing purposes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

- Fix template end position consistency across string types
- Extract repeated commaIndex + 1 calculation into ParseArgumentsAfterComma helper
- Make ArgumentStart/ArgumentLength properties internal for better encapsulation
@willibrandon willibrandon merged commit 405be17 into main Sep 9, 2025
1 check passed
@willibrandon willibrandon deleted the fix/multi-line-navigation branch September 9, 2025 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working visual-studio Visual Studio extension functionality and integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation (Go to Definition) fails for multi-line Serilog calls

1 participant