[PATCH] D151190: [clangd] Do not end inactiveRegions range at position 0 of line

Qingyuan Zheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 20:16:53 PDT 2023


daiyousei-qz added inline comments.


================
Comment at: clang-tools-extra/clangd/unittests/ClangdTests.cpp:1343
 #undef CMDMACRO
 $inactive3[[#ifdef CMDMACRO
   int inactiveInt2;
----------------
hokein wrote:
> While this patch is an improvement, I wonder we should move it further.
> 
> Has been thinking about it more, we seem to have some inconsistent behavior on highlighting the `#if`, `#else`, `#endif` lines:
> 
> - in `$inactive1` case, the `#endif` is marked as inactive (IMO, the highlighting in the editor is confusing, it looks like we're missing a match `endif`, thus I prefer to mark it as active to correspond to the active `#if` branch);
> - in `$inactive3` case, the line `#elif PREAMBLEMACRO > 0` is marked as inactive, this is inconsistent with `$inactive1` case;
> 
> I think it would be nice to have a consistent model. One approach is to always consider `#if`, `#elif`, `#endif`, `#endif` lines active (in the implementation side, this would mean we always use the line range [skipp_range.start.line+1, skipp_range.end.line - 1]).
> 
> What do you think about this?
> 
> 
+1. My perspective is that C++ source code is actually a meta-language (preprocessor) that describes generation of C++ language code. That is, `#if`, `#else`, `#endif` and .etc are always in a sense "executed" to generate the actual code. So they shouldn't be marked as inactive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151190



More information about the cfe-commits mailing list