Always include gtest include paths in compilation database for first-party code

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Issue Summary

      When generating the compilation database, there is a challenge with clangd locating the correct compile commands for test files (e.g., foo_test.cpp) because the include paths for gtest are not always present. This can lead to issues with clangd's prefix matching, where it falls back to the closest available command (e.g., foo.cpp), which may lack the necessary gtest includes.

      Context

      • clangd uses prefix matching to find compile commands for files.
      • Test files such as foo_test.cpp often require gtest include paths, but these may not be present if the compile command is inferred from a non-test file.
      • This can cause problems with code completion, navigation, and other clangd features for test files.

      Proposed Solution

      • When generating the compilation database, always include the gtest include paths in every compile command for first-party code.
      • This ensures that even when clangd falls back to a non-test file's command, the necessary gtest includes are present, improving the developer experience.

       

      Alternative Solution

      Add a .clangd file with a section that adds the gtest include paths to each file matching src/mongo/.*_test.*\.(h|cpp)

            Assignee:
            John Daniels
            Reporter:
            Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: