A screenshot in VSCode (with the LSP's v3.16 semanticToken enabled)
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Yup, this is a nice improvement, though there are further things we could do.
As discussed offline, we could consider mapping "disabled" to an attribute but we can't really consume that well in VSCode (or any other editor yet) so let's leave it.
clang-tools-extra/clangd/SemanticHighlighting.cpp | ||
---|---|---|
238 | A little more direct and avoiding the special case: StringRef LineText = MainCode.drop_front(StartOfLine).take_until([](char C) { return C == '\n'; }); ... {Position{Line, 0}, Position{Line, lspLength(LineText)}} | |
242 | this may overlap existing tokens. For now this can actually happen, as we consider #ifndef FOO to be disabled if FOO is defined, but also a usage of the macro FOO. In future, I think we probably want to reduce the scope of the disabled regions to not include the directive itself, then this can become an assert. | |
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp | ||
83 | AIUI the extra complexity here is to accommodate overlapping ranges, which we can likely get rid of. |
I think the code could be a bit clearer, but up to you. The tests are good so feel free to submit any version you're happy with.
clang-tools-extra/clangd/SemanticHighlighting.cpp | ||
---|---|---|
242 | Hmm, the role of NonConflicting is pretty confusing here: it has an invariant preserved as we construct it, then we violate it by dumping a bunch of ranges into it, then try to restore it. What about: // Merge token stream with "inactive line" markers. vector WithInactiveLines; auto It = NonConflicting.begin(); for (Range &R : Ranges) { for (int Line : R) { // Copy tokens before the inactive line for (; It != NonConflicting.end() && It->position.begin.line < Line) WithInactiveLines.push_back(std::move(*It)); // Add a token for the inactive line itself. WithInactiveLines.push_back(createInactiveLineToken(MainCode, Line)); // Skip any other tokens on the inactive line while (It != NonConflicting.end() && It->position.begin.line == Line) ++It; } } // Copy tokens after the last inactive line for (; It != NonOverlapping.end(); ++It) WithInactiveLines.push_back(std::move(*It)); The only real assumption here is "a token is associated with a line", which is pretty fundamental anyway. |
A little more direct and avoiding the special case: