[PATCH] D143260: [clangd] Add semantic token for labels

Christian Kandeler via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 13 08:13:05 PST 2023


ckandeler added a comment.

In D143260#4122523 <https://reviews.llvm.org/D143260#4122523>, @kadircet wrote:

> at hindsight i can't see why `goto X;` and `X:` is not enough for clients to implement this without any need for semantic analysis. are there contexts where this kind of syntactical match is not enough?

I suppose the label *use* could be identified by looking at the previous token, but not the label *declaration* (see below).

> moreover there are other label-like constructs that we're not handling, e.g. access specifiers and switch cases.

But access specifiers are a completely different thing semantically, that's the point: The user does not tell the client: "I want everything  that is followed by a single colon in this color"; that would be silly. They say "I want goto labels in this color", exactly because then they immediately stand out compared to access specifiers.
switch cases are indeed similar semantically, but the difference is that they already have a category assigned: They are either enum values (a semantic token type in clangd), macros (ditto) or number literals (likely to be its own category in the client's syntax highlighter).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143260/new/

https://reviews.llvm.org/D143260



More information about the cfe-commits mailing list