Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json config with glob pattern and editor variables support #650

Open
Hedgefog opened this issue Jul 6, 2024 · 1 comment
Open

json config with glob pattern and editor variables support #650

Hedgefog opened this issue Jul 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Hedgefog
Copy link

Hedgefog commented Jul 6, 2024

Hi there,

I've recently started using clangd and noticed a lack of support for glob patterns in include paths. This feature is crucial for projects with large libraries and frameworks that have complex nested directory structures.

Currently, the C++ Language Server uses the c_cpp_properties.json file, which supports glob patterns and vscode variables. Here is an example configuration:

{
  "env": {
    "_BUILD_PLATFORM_DIR": "${config:myproject.buildPlatform}",
    "_GLOB_HEADERS_DIR": "{,headers,classes}",
    "_GLOB_LIBRARY_CORE_DIR": "{common,core}",
    "_GLOB_LIBRARY_MODULES_DIR": "{modules,plugins}",
    "_GLOB_LIBRARY_SOURCE_PATH": "${config:myproject.libraryPath}/src",
    "_GLOB_LIBRARY_INCLUDE_PATH": "${_GLOB_LIBRARY_SOURCE_PATH}/${_GLOB_LIBRARY_CORE_DIR}/*/${_GLOB_HEADERS_DIR}",
    "_GLOB_LIBRARY_MODULES_INCLUDE_PATH": "${_GLOB_LIBRARY_SOURCE_PATH}/${_GLOB_LIBRARY_MODULES_DIR}/*/src/${_GLOB_HEADERS_DIR}",
    "_INCLUDE_PATH": [
      "${workspaceFolder}/src",
      "${_GLOB_LIBRARY_SOURCE_PATH}",
      "${_GLOB_LIBRARY_INCLUDE_PATH}",
      "${_GLOB_LIBRARY_MODULES_INCLUDE_PATH}"
    ]
  },
  "configurations": [
    {
      "name": "Win64",
      "compilerPath": "${config:myproject.msvcPath}/bin/Hostx64/x64/cl.exe",
      "intelliSenseMode": "msvc-x64",
      "cStandard": "c17",
      "cppStandard": "c++20",
      "includePath": [
        "${env:_INCLUDE_PATH}"
      ]
    }
  ]
}

env section allows set environment variables used during compilation.
config:* - variables reference settings from the settings.json file.
env:* - environment variables (can be defined within the env section)

VSCode Glob Pattern References:
https://code.visualstudio.com/docs/editor/glob-patterns
https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options

I think integrating support for glob patterns and variables would greatly enhance its utility for large projects.

@Hedgefog Hedgefog added the enhancement New feature or request label Jul 6, 2024
@Hedgefog Hedgefog changed the title Add json config with glob and variables support json config with glob pattern and editor variables support Jul 6, 2024
@HighCommander4
Copy link
Contributor

Clangd expects to get information about include paths from a compile_commands.json file, as described at https://clangd.llvm.org/installation#project-setup.

This file is intended to be generated by the build system, and should reflect the same commands used to actually compile the files.

The idea behind this approach is that information about the project's include paths, is only specified in one place: wherever the build system gets it from (often a metadata file like CMakeLists.txt). The build system then uses the same information both for the actual build, and for generating the compile_commands.json file which clangd then uses. If you make a modification such as adding a new include path, you only have to make it in one place (e.g. in CMakeLists.txt); it's not necessary to make the update in a second place which is specific to the editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants