Closed Ma27 closed 6 months ago
OK, this also breaks string interpolations like "foo ${./bar}"
:(
So not usable yet.
OK, this also breaks string interpolations like "foo ${./bar}" :(
Can you please add a specific test case for this?
Will look into this later.
After playing around with regions, I got something which appears to work more reliably. Also added two new testcases for the issues I encountered with the previous matcher I wrote (path-with-invalid-infix
and path-with-recursive-interpolation
).
Considering that I haven't found any issues in the past week, I decided to mark it as ready to review :)
cc @figsoda @lnl7 :)
@figsoda cannot reproduce. Is the issue also observable with the vim
from the repo's nix-shell? When I hover with the cursor over the -
or the .nix
int he editor and issue :Syntax
it always prints out ['nixInterpolatedPath']
which seems correct to me.
ping @LnL7 I think this is good to go now :)
ping @LnL7
ping @LnL7 I'd still need an approval from you to merge this. Would be cool if we could get this done :)
I'm merging this now, I'm using this patch in my editor for the last months (and I have Nix code open more often than I'd like to admit) without noticing any issues and others seem to have tested it as well.
OK I nerdsniped myself into doing that now, damn it :upside_down_face: Anyways, this is a draft on purpose, because there's one known case of a wrong highlight (see commit message below) and I haven't tested this under real conditions yet. cc @LnL7 @figsoda @aszlig
Closes https://github.com/LnL7/vim-nix/issues/41
A few implementation notes:
nixInterpolatedPath
is on purpose belownixPath
, otherwise the highlighting of top-level expressions, i.e. files containing e.g../foo/bar${baz}
break where
$
is entirely unmatched and{baz}
is misinterpreted as argument destructuring expression.The region's matching behavior now works like this:
First, we expect a path start (i.e. either
~/<further path components>
or<path components>
) and then the beginning of a substitution (${
), however this isn't part of our match anymore (hence\ze
) to make sure this is matched by the subsequentnixInterpolation
.Also,
nixInterpolation
is the only thing allowed in here becausenixPath
would conflict with ourend
&skip
expression and would thus make vim expand thenixInterpolatedPath
over the rest of the file.To summarize, after the start, two things are allowed:
The
skip
regex is to make sure that theend
isn't satisified too early, e.g. in./foo/${bar}/${baz}/suff
the path shouldn't terminate after
${bar}/
since another substitution is followed by only valid path chars.The end regex makes sure that the last substitution was closed (
nixinterpolatedPath
always contains a substitution because ofstart
) and only valid path chars are matched after that. This means that e.g. in./foo/${bar}!x
everything after
${bar}
is not part of the path anymore.In the end a region turned out to be slightly more suitable, so this cannot be composed into a single group with the matcher
nixPath
.Instead,
nixInterpolatedPath
's highlighting group now links tonixPath
to make sure they look the same in the end.