This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Revert the symbol collector behavior to old pre-include-cleaner-library behavior due to a regression.
ClosedPublic

Authored by VitaNuo on Jul 27 2023, 1:44 AM.

Diff Detail

Event Timeline

VitaNuo created this revision.Jul 27 2023, 1:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2023, 1:44 AM
VitaNuo requested review of this revision.Jul 27 2023, 1:44 AM
kadircet added inline comments.Jul 27 2023, 1:57 AM
clang-tools-extra/clangd/index/SymbolCollector.cpp
841–858

can you also get rid of this piece, and SymbolProviders map ?

883–884

we can drop this too

910–934

rather than duplicating some of the checks, can we rewrite this block as:

llvm::StringRef IncludeHeader = getStdlibHeader(*S, ASTCtx->getLangOpts());
if (IncludeHeader.empty())
  IncludeHeader = HeaderFileURIs->getIncludeHeader(FID);
if (!IncludeHeader.empty()) {
      auto NewSym = *S;
      NewSym.IncludeHeaders.push_back({IncludeHeader, 1, Directives});
      Symbols.insert(NewSym);
}
912

let's pass in the language options from ASTCtx into here

915–919

i think the old order of, first dealing with std::move and then using tooling::stdlib is less error-prone and the order in which we apply the mapping in include-cleaner, so that would be a more compatible change going forward.

919–954

let's drop this block to not create confusion

VitaNuo updated this revision to Diff 544684.Jul 27 2023, 3:16 AM
VitaNuo marked 6 inline comments as done.

Address comments.

kadircet accepted this revision.Jul 27 2023, 3:25 AM
kadircet added inline comments.
clang-tools-extra/clangd/index/SymbolCollector.cpp
910

we shouldn't be overriding the include header if it's already set above. also i think it would be easier to have this out of the way so that reverting to old behaviour is easier:

llvm::StringRef getStdHeader(const Symbol *S, const LanguageOptions &LO) {
  tooling::stdlib::Lang Lang = tooling::stdlib::Lang::CXX;
    if (ASTCtx->getLangOpts().C11)
      Lang = tooling::stdlib::Lang::C;
    else if(!ASTCtx->getLangOpts().CPlusPlus)
      return "";

    if (S->Scope == "std::" && S->Name == "move") {
      if (!S->Signature.contains(','))
        return "<utility>";
      return "<algorithm>";
    }
   
    if (auto StdSym = tooling::stdlib::Symbol::named(S->Scope, S->Name, Lang))
     if (auto Header = StdSym->header())
       return Header->name();
    return "";
}
This revision is now accepted and ready to land.Jul 27 2023, 3:25 AM
VitaNuo updated this revision to Diff 544689.Jul 27 2023, 3:33 AM
VitaNuo marked an inline comment as done.

Address comment.

kadircet added inline comments.Jul 27 2023, 3:34 AM
clang-tools-extra/clangd/index/SymbolCollector.cpp
842–858

can you also move this into an anonymous namespace?

This revision was landed with ongoing or failed builds.Jul 27 2023, 3:34 AM
This revision was automatically updated to reflect the committed changes.