clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
629 stars 106 forks source link

designate macro value in project config to control code highlighting #563

Closed guxiao-tetras closed 9 months ago

guxiao-tetras commented 10 months ago

MS intelligence has a feature, Defines, which coud set macro value in the code and control which parts of the code(in #ifdef #else #endif) is activated. This can be useful when reading only part of the code. Can you provide the same feature? Thank you.

HighCommander4 commented 10 months ago

We have a couple of mechanisms to do this already:

  1. Add a compiler flag for the define (e.g. -DNAME=VALUE) to the commands in your compile_commands.json file. See https://clangd.llvm.org/installation#project-setup for more details on different ways to create a compile_commands.json file.
  2. Add the compiler flag using a clangd config file (.clangd file in the project root directory), for example:

    CompileFlags:
      Add: [-DNAME=VALUE]
guxiao-tetras commented 9 months ago
  1. -DNAME=VALUE

Thanks, it works for me.