2021-01-14 17:38:42 +00:00
|
|
|
//===--- ASTSignals.cpp ------------------------------------------*- C++-*-===//
|
2021-01-10 15:23:03 +00:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ASTSignals.h"
|
|
|
|
#include "AST.h"
|
|
|
|
#include "FindTarget.h"
|
[clangd] Full support for #import insertions
These are still disabled by default, but will work in ObjC code if you
enable the `-import-insertions` flag.
Completion requires ASTSignals to be available; before ASTSignals are
available, we will always use #include. Once they are available, the
behavior varies as follows:
- For source files, use #import if the ObjC language flag is enabled
- For header files:
- If the ObjC language flag is disabled, use #include
- If the header file contains any #imports, use #import
- If the header file references any ObjC decls, use #import
- Otherwise, use #include
IncludeFixer support is similar, but it does not rely upon ASTSignals,
instead it does the above checks excluding the scan for ObjC symbols.
Differential Revision: https://reviews.llvm.org/D139458
2022-12-06 21:33:12 +00:00
|
|
|
#include "Headers.h"
|
2022-04-28 12:27:43 +00:00
|
|
|
#include "support/Trace.h"
|
[clangd] Full support for #import insertions
These are still disabled by default, but will work in ObjC code if you
enable the `-import-insertions` flag.
Completion requires ASTSignals to be available; before ASTSignals are
available, we will always use #include. Once they are available, the
behavior varies as follows:
- For source files, use #import if the ObjC language flag is enabled
- For header files:
- If the ObjC language flag is disabled, use #include
- If the header file contains any #imports, use #import
- If the header file references any ObjC decls, use #import
- Otherwise, use #include
IncludeFixer support is similar, but it does not rely upon ASTSignals,
instead it does the above checks excluding the scan for ObjC symbols.
Differential Revision: https://reviews.llvm.org/D139458
2022-12-06 21:33:12 +00:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2021-01-10 15:23:03 +00:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
ASTSignals ASTSignals::derive(const ParsedAST &AST) {
|
2022-04-28 12:27:43 +00:00
|
|
|
trace::Span Span("ASTSignals::derive");
|
2021-01-10 15:23:03 +00:00
|
|
|
ASTSignals Signals;
|
[clangd] Full support for #import insertions
These are still disabled by default, but will work in ObjC code if you
enable the `-import-insertions` flag.
Completion requires ASTSignals to be available; before ASTSignals are
available, we will always use #include. Once they are available, the
behavior varies as follows:
- For source files, use #import if the ObjC language flag is enabled
- For header files:
- If the ObjC language flag is disabled, use #include
- If the header file contains any #imports, use #import
- If the header file references any ObjC decls, use #import
- Otherwise, use #include
IncludeFixer support is similar, but it does not rely upon ASTSignals,
instead it does the above checks excluding the scan for ObjC symbols.
Differential Revision: https://reviews.llvm.org/D139458
2022-12-06 21:33:12 +00:00
|
|
|
Signals.InsertionDirective = preferredIncludeDirective(
|
|
|
|
AST.tuPath(), AST.getLangOpts(),
|
|
|
|
AST.getIncludeStructure().MainFileIncludes, AST.getLocalTopLevelDecls());
|
2021-01-10 15:23:03 +00:00
|
|
|
const SourceManager &SM = AST.getSourceManager();
|
2021-01-18 07:58:43 +00:00
|
|
|
findExplicitReferences(
|
|
|
|
AST.getASTContext(),
|
|
|
|
[&](ReferenceLoc Ref) {
|
|
|
|
for (const NamedDecl *ND : Ref.Targets) {
|
|
|
|
if (!isInsideMainFile(Ref.NameLoc, SM))
|
|
|
|
continue;
|
|
|
|
SymbolID ID = getSymbolID(ND);
|
|
|
|
if (!ID)
|
|
|
|
continue;
|
|
|
|
unsigned &SymbolCount = Signals.ReferencedSymbols[ID];
|
|
|
|
SymbolCount++;
|
|
|
|
// Process namespace only when we see the symbol for the first time.
|
|
|
|
if (SymbolCount != 1)
|
|
|
|
continue;
|
|
|
|
if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) {
|
|
|
|
if (NSD->isAnonymousNamespace())
|
|
|
|
continue;
|
|
|
|
std::string NS = printNamespaceScope(*NSD);
|
|
|
|
if (!NS.empty())
|
|
|
|
Signals.RelatedNamespaces[NS]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
AST.getHeuristicResolver());
|
2021-01-10 15:23:03 +00:00
|
|
|
return Signals;
|
|
|
|
}
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|