Skip to content

lexer: skip string literals except in interpolation - #2098

Open
ikostia wants to merge 8 commits into
ocaml:mainfrom
ikostia:ikostia/dont-reconstruct-identifiers-in-string-literals
Open

lexer: skip string literals except in interpolation#2098
ikostia wants to merge 8 commits into
ocaml:mainfrom
ikostia:ikostia/dont-reconstruct-identifiers-in-string-literals

Conversation

@ikostia

@ikostia ikostia commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

See commit da0ab7d with a test demonstrating the bug this PR fixes, but TL/DR is that single document on the position of a / in a string literal "/usr/bin/home" would return the division opeartor docs. This is not desired, of course.

It is important to note that deciding that's a correct fix here is tricky:

  1. the lexer runs on a pre-ppx source and ocaml itself does not have any string interpolation, so %{name} in "hello %{name}" is just a bit of a string literal, as per the compiler
  2. however, the PPXes do exist and are common, so from a practical perspective it makes sense to try and treat %{name} as an interpolation for the purposes of documentation/hover etc

I chose to prioritize 2, so this PR handles interpolation inside string literals and skips only non-interpolated bits of string literals.

Testing

Existing tests pass + failure demonstration test now tests the correct behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants