Skip to content

Document how to use C/C++ header files with clangd - #170

Open
Puliuvarthi.Mahesh (MaheshPulivarthi18) wants to merge 1 commit into
microsoft:mainfrom
MaheshPulivarthi18:nightshift/110-c-c-questions-for-header-file-usage-inst
Open

Puliuvarthi.Mahesh (MaheshPulivarthi18) wants to merge 1 commit into
microsoft:mainfrom
MaheshPulivarthi18:nightshift/110-c-c-questions-for-header-file-usage-inst

Conversation

@MaheshPulivarthi18

Copy link
Copy Markdown

Closes #110

Issue #110 asks how to work with header files when using the clangd-based C/C++ language server. The README did not cover this.

This adds a short "C/C++ and header files" section to the README. It is documentation only, with no code changes.

The section explains:

  • {"code_language": "cpp"} starts clangd, which is launched with no extra arguments and the project root as its working directory and workspace root.
  • clangd looks for compile_commands.json or compile_flags.txt in the file's directory and its parents.
  • Compilation databases usually list source files rather than headers, so clangd reuses or infers commands for headers. The database should therefore include representative translation units with the needed include paths and defines.
  • How to generate and link compile_commands.json with CMake, as the existing clangd test does, with a link to the clangd setup guide for other options.
  • Request paths are relative to the project root, and definitions found in headers are returned with a root-relative relativePath. A short example shows both a definition that lands in a header and a request made directly on a header.
  • Without a compilation database, header results may be incomplete, and background indexing on larger projects can change results between queries.

Reviewers may want to check that the clangd behaviour described matches what they expect, and that the example line and column values are fine as illustrative placeholders.

Testing

Documentation-only change (README.md).

Existing suites:

  • PATH="$PWD/.venv/bin:$PATH" timeout 800 .venv/bin/pytest tests/multilspy/test_multilspy_python.py -q --tb=short: passed

Add a README section on how clangd finds compile commands for headers, how to generate compile_commands.json, and how to query headers and definitions that resolve into them. Addresses microsoft#110.

Generated by NightShift

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C/C++ - Questions for header file usage instructions.

2 participants