[clangd] Do not treat line as inactive if skipped range ends at character position 0

Fixes https://github.com/clangd/clangd/issues/602

Differential Revision: https://reviews.llvm.org/D92148
This commit is contained in:
Nathan Ridge 2020-11-25 21:31:09 -05:00
parent 345fcccb33
commit d1fd91ddaf
2 changed files with 13 additions and 4 deletions

View File

@ -234,6 +234,10 @@ public:
// with line-based diffing.
assert(R.start.line <= R.end.line);
for (int Line = R.start.line; Line <= R.end.line; ++Line) {
// If the end of the inactive range is at the beginning
// of a line, that line is not inactive.
if (Line == R.end.line && R.end.character == 0)
continue;
// Copy tokens before the inactive line
for (; It != NonConflicting.end() && It->R.start.line < Line; ++It)
WithInactiveLines.push_back(std::move(*It));

View File

@ -623,18 +623,23 @@ $InactiveCode[[#endif]]
// Code after the preamble.
// Code inside inactive blocks does not get regular highlightings
// because it's not part of the AST.
$InactiveCode[[#ifdef test]]
#define $Macro[[test2]]
$InactiveCode[[#if defined(test)]]
$InactiveCode[[int Inactive2;]]
$InactiveCode[[#elif defined(test2)]]
int $Variable[[Active1]];
$InactiveCode[[#else]]
$InactiveCode[[int Inactive3;]]
$InactiveCode[[#endif]]
#ifndef $Macro[[test]]
int $Variable[[Active1]];
int $Variable[[Active2]];
#endif
$InactiveCode[[#ifdef test]]
$InactiveCode[[int Inactive3;]]
$InactiveCode[[int Inactive4;]]
$InactiveCode[[#else]]
int $Variable[[Active2]];
int $Variable[[Active3]];
#endif
)cpp",
// Argument to 'sizeof...'