[clangd] Always retrieve ProjectInfo from Base in OverlayCDB
authorKadir Cetinkaya <kadircet@google.com>
Thu, 16 Jul 2020 09:27:31 +0000 (11:27 +0200)
committerKadir Cetinkaya <kadircet@google.com>
Thu, 16 Jul 2020 10:33:54 +0000 (12:33 +0200)
commit46c921003c2ce5f1cdc4de9ef613eb001980780c
treed6b889aea8b9502bcd317318717d88d76d78efa8
parentb9a6fb64281b6836e565ee39fb0d543bf184fd88
[clangd] Always retrieve ProjectInfo from Base in OverlayCDB

Summary:
Clangd is returning current working directory for overriden commands.
This can cause inconsistencies between:
- header and the main files, as OverlayCDB only contains entries for the main
  files it direct any queries for the headers to the base, creating a
  discrepancy between the two.
- different clangd instances, as the results will be different depending on the
  timing of execution of the query and override of the command. hence clangd
  might see two different project infos for the same file between different
  invocations.
- editors and the way user has invoked it, as current working directory of
  clangd will depend on those, hence even when there's no underlying base CWD
  might change depending on the editor, or the directory user has started the
  editor in.

This patch gets rid of that discrepency by always directing queries to base or
returning llvm::None in absence of it.

For a sample bug see https://reviews.llvm.org/D83099#2154185.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83934
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/GlobalCompilationDatabase.h
clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp