This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Always retrieve ProjectInfo from Base in OverlayCDB
ClosedPublic

Authored by kadircet on Jul 16 2020, 2:35 AM.

Details

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.

Diff Detail

Event Timeline

kadircet created this revision.Jul 16 2020, 2:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2020, 2:35 AM
sammccall accepted this revision.Jul 16 2020, 3:07 AM
sammccall added inline comments.
clang-tools-extra/clangd/GlobalCompilationDatabase.h
136

nit: drop "note that" for readability.

137

I find this comment confusing, you say "might" when I think you mean "might otherwise" (i.e. given the old behavior).
However the claim is true anyway for another reason: headers *may* simply be from a different CDB.

Maybe enough for the header is:
It wouldn't make much sense to treat files with overridden commands specially when
we can't do the same for the (unknown) local headers they include.

Even so I think this comment might belong rather in the implementation file...

This revision is now accepted and ready to land.Jul 16 2020, 3:07 AM
kadircet updated this revision to Diff 278421.Jul 16 2020, 3:33 AM
  • Split comments between implementation and header, and reword.
kadircet marked 2 inline comments as done.Jul 16 2020, 3:34 AM
This revision was automatically updated to reflect the committed changes.