[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
//===--- SymbolCollector.h ---------------------------------------*- C++-*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2018-09-26 04:02:36 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_COLLECTOR_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_SYMBOL_COLLECTOR_H
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
|
2018-02-16 22:15:55 +08:00
|
|
|
#include "CanonicalIncludes.h"
|
2019-12-12 19:12:17 +08:00
|
|
|
#include "CollectMacros.h"
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
#include "Index.h"
|
2019-02-28 20:31:49 +08:00
|
|
|
#include "SymbolOrigin.h"
|
2018-01-10 01:32:00 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2018-11-06 18:55:21 +08:00
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
#include "clang/Index/IndexDataConsumer.h"
|
|
|
|
#include "clang/Index/IndexSymbol.h"
|
2018-01-10 01:32:00 +08:00
|
|
|
#include "clang/Sema/CodeCompleteConsumer.h"
|
2018-11-06 18:55:21 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2019-04-18 02:33:07 +08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2018-11-06 18:55:21 +08:00
|
|
|
#include <functional>
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Collect declarations (symbols) from an AST.
|
[clangd] Add "member" symbols to the index
Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums
The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewers: ioeric, sammccall
Reviewed By: ioeric, sammccall
Subscribers: hokein, sammccall, jkorous, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44954
llvm-svn: 334017
2018-06-05 22:01:40 +08:00
|
|
|
/// It collects most declarations except:
|
|
|
|
/// - Implicit declarations
|
|
|
|
/// - Anonymous declarations (anonymous enum/class/struct, etc)
|
2019-01-14 18:01:17 +08:00
|
|
|
/// - Declarations in anonymous namespaces in headers
|
[clangd] Add "member" symbols to the index
Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums
The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewers: ioeric, sammccall
Reviewed By: ioeric, sammccall
Subscribers: hokein, sammccall, jkorous, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44954
llvm-svn: 334017
2018-06-05 22:01:40 +08:00
|
|
|
/// - Local declarations (in function bodies, blocks, etc)
|
|
|
|
/// - Template specializations
|
|
|
|
/// - Library-specific private declarations (e.g. private declaration generated
|
|
|
|
/// by protobuf compiler)
|
|
|
|
///
|
2019-01-14 18:01:17 +08:00
|
|
|
/// References to main-file symbols are not collected.
|
|
|
|
///
|
2018-06-21 20:12:26 +08:00
|
|
|
/// See also shouldCollectSymbol(...).
|
2018-01-10 22:57:58 +08:00
|
|
|
///
|
|
|
|
/// Clients (e.g. clangd) can use SymbolCollector together with
|
|
|
|
/// index::indexTopLevelDecls to retrieve all symbols when the source file is
|
|
|
|
/// changed.
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
class SymbolCollector : public index::IndexDataConsumer {
|
|
|
|
public:
|
2018-01-10 22:57:58 +08:00
|
|
|
struct Options {
|
2018-02-07 00:10:35 +08:00
|
|
|
/// When symbol paths cannot be resolved to absolute paths (e.g. files in
|
|
|
|
/// VFS that does not have absolute path), combine the fallback directory
|
|
|
|
/// with symbols' paths to get absolute paths. This must be an absolute
|
|
|
|
/// path.
|
2018-01-29 23:13:29 +08:00
|
|
|
std::string FallbackDir;
|
2018-02-16 22:15:55 +08:00
|
|
|
bool CollectIncludePath = false;
|
|
|
|
/// If set, this is used to map symbol #include path to a potentially
|
|
|
|
/// different #include path.
|
|
|
|
const CanonicalIncludes *Includes = nullptr;
|
2018-03-12 22:49:09 +08:00
|
|
|
// Populate the Symbol.References field.
|
|
|
|
bool CountReferences = false;
|
[clangd] SymbolOccurrences -> Refs and cleanup
Summary:
A few things that I noticed while merging the SwapIndex patch:
- SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names,
and these names appear *a lot*. Ref, RefSlab, etc seem clear enough
and read/format much better.
- The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is
confusing and irritating, and doesn't even save much code.
Avoiding RefSlab::Builder was my idea, but it was a bad one; add it.
- DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for
constructing MemIndex - and means many less wasted allocations than the
current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for
slabs.
- RefSlab::find() is not actually used for anything, so we can throw
away the DenseMap and keep the representation much more compact.
- A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs.
Reviewers: ioeric
Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51605
llvm-svn: 341368
2018-09-04 22:39:56 +08:00
|
|
|
/// The symbol ref kinds that will be collected.
|
|
|
|
/// If not set, SymbolCollector will not collect refs.
|
2018-11-07 22:59:24 +08:00
|
|
|
/// Note that references of namespace decls are not collected, as they
|
|
|
|
/// contribute large part of the index, and they are less useful compared
|
|
|
|
/// with other decls.
|
[clangd] SymbolOccurrences -> Refs and cleanup
Summary:
A few things that I noticed while merging the SwapIndex patch:
- SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names,
and these names appear *a lot*. Ref, RefSlab, etc seem clear enough
and read/format much better.
- The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is
confusing and irritating, and doesn't even save much code.
Avoiding RefSlab::Builder was my idea, but it was a bad one; add it.
- DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for
constructing MemIndex - and means many less wasted allocations than the
current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for
slabs.
- RefSlab::find() is not actually used for anything, so we can throw
away the DenseMap and keep the representation much more compact.
- A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs.
Reviewers: ioeric
Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51605
llvm-svn: 341368
2018-09-04 22:39:56 +08:00
|
|
|
RefKind RefFilter = RefKind::Unknown;
|
2018-10-17 16:38:36 +08:00
|
|
|
/// If set to true, SymbolCollector will collect all refs (from main file
|
|
|
|
/// and included headers); otherwise, only refs from main file will be
|
|
|
|
/// collected.
|
|
|
|
/// This flag is only meaningful when RefFilter is set.
|
|
|
|
bool RefsInHeaders = false;
|
2018-07-05 14:20:41 +08:00
|
|
|
// Every symbol collected will be stamped with this origin.
|
|
|
|
SymbolOrigin Origin = SymbolOrigin::Unknown;
|
2018-07-09 23:31:07 +08:00
|
|
|
/// Collect macros.
|
|
|
|
/// Note that SymbolCollector must be run with preprocessor in order to
|
|
|
|
/// collect macros. For example, `indexTopLevelDecls` will not index any
|
|
|
|
/// macro even if this is true.
|
|
|
|
bool CollectMacro = false;
|
2019-01-14 18:01:17 +08:00
|
|
|
/// Collect symbols local to main-files, such as static functions
|
|
|
|
/// and symbols inside an anonymous namespace.
|
|
|
|
bool CollectMainFileSymbols = true;
|
2019-02-26 00:00:00 +08:00
|
|
|
/// If set to true, SymbolCollector will collect doc for all symbols.
|
|
|
|
/// Note that documents of symbols being indexed for completion will always
|
|
|
|
/// be collected regardless of this option.
|
|
|
|
bool StoreAllDocumentation = false;
|
2018-11-06 18:55:21 +08:00
|
|
|
/// If this is set, only collect symbols/references from a file if
|
|
|
|
/// `FileFilter(SM, FID)` is true. If not set, all files are indexed.
|
|
|
|
std::function<bool(const SourceManager &, FileID)> FileFilter = nullptr;
|
2018-01-10 22:57:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
SymbolCollector(Options Opts);
|
|
|
|
|
2018-06-21 20:12:26 +08:00
|
|
|
/// Returns true is \p ND should be collected.
|
2018-12-03 21:16:04 +08:00
|
|
|
static bool shouldCollectSymbol(const NamedDecl &ND, const ASTContext &ASTCtx,
|
2019-01-14 18:01:17 +08:00
|
|
|
const Options &Opts, bool IsMainFileSymbol);
|
2018-06-21 20:12:26 +08:00
|
|
|
|
2018-01-10 01:32:00 +08:00
|
|
|
void initialize(ASTContext &Ctx) override;
|
|
|
|
|
|
|
|
void setPreprocessor(std::shared_ptr<Preprocessor> PP) override {
|
|
|
|
this->PP = std::move(PP);
|
|
|
|
}
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
|
|
|
|
bool
|
2019-12-16 17:33:56 +08:00
|
|
|
handleDeclOccurrence(const Decl *D, index::SymbolRoleSet Roles,
|
|
|
|
ArrayRef<index::SymbolRelation> Relations,
|
|
|
|
SourceLocation Loc,
|
|
|
|
index::IndexDataConsumer::ASTNodeInfo ASTNode) override;
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
|
2019-12-16 17:33:56 +08:00
|
|
|
bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI,
|
|
|
|
index::SymbolRoleSet Roles,
|
|
|
|
SourceLocation Loc) override;
|
2018-07-09 23:31:07 +08:00
|
|
|
|
2019-12-12 19:12:17 +08:00
|
|
|
void handleMacros(const MainFileMacros &MacroRefsToIndex);
|
|
|
|
|
2017-12-24 03:38:03 +08:00
|
|
|
SymbolSlab takeSymbols() { return std::move(Symbols).build(); }
|
[clangd] SymbolOccurrences -> Refs and cleanup
Summary:
A few things that I noticed while merging the SwapIndex patch:
- SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names,
and these names appear *a lot*. Ref, RefSlab, etc seem clear enough
and read/format much better.
- The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is
confusing and irritating, and doesn't even save much code.
Avoiding RefSlab::Builder was my idea, but it was a bad one; add it.
- DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for
constructing MemIndex - and means many less wasted allocations than the
current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for
slabs.
- RefSlab::find() is not actually used for anything, so we can throw
away the DenseMap and keep the representation much more compact.
- A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs.
Reviewers: ioeric
Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51605
llvm-svn: 341368
2018-09-04 22:39:56 +08:00
|
|
|
RefSlab takeRefs() { return std::move(Refs).build(); }
|
2019-06-04 12:25:44 +08:00
|
|
|
RelationSlab takeRelations() { return std::move(Relations).build(); }
|
2018-08-31 20:54:13 +08:00
|
|
|
|
2019-08-20 16:54:30 +08:00
|
|
|
/// Returns true if we are interested in references and declarations from \p
|
|
|
|
/// FID. If this function return false, bodies of functions inside those files
|
|
|
|
/// will be skipped to decrease indexing time.
|
|
|
|
bool shouldIndexFile(FileID FID);
|
|
|
|
|
2018-03-12 22:49:09 +08:00
|
|
|
void finish() override;
|
|
|
|
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
private:
|
[clangd] Add support for type hierarchy (super types only for now)
Summary:
Patch by Nathan Ridge(@nridge)!
This is an LSP extension proposed here:
https://github.com/Microsoft/vscode-languageserver-node/pull/426
An example client implementation can be found here:
https://github.com/theia-ide/theia/pull/3802
Reviewers: kadircet, sammccall
Reviewed By: kadircet
Subscribers: jdoerfert, sammccall, cfe-commits, mgorny, dschaefer, simark, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet
Tags: #clang
Differential Revision: https://reviews.llvm.org/D56370
llvm-svn: 356445
2019-03-19 17:27:04 +08:00
|
|
|
const Symbol *addDeclaration(const NamedDecl &, SymbolID,
|
|
|
|
bool IsMainFileSymbol);
|
2018-02-09 22:42:01 +08:00
|
|
|
void addDefinition(const NamedDecl &, const Symbol &DeclSymbol);
|
2019-06-04 12:25:44 +08:00
|
|
|
void processRelations(const NamedDecl &ND, const SymbolID &ID,
|
|
|
|
ArrayRef<index::SymbolRelation> Relations);
|
2018-02-09 22:42:01 +08:00
|
|
|
|
2019-04-18 02:33:07 +08:00
|
|
|
llvm::Optional<std::string> getIncludeHeader(llvm::StringRef QName, FileID);
|
|
|
|
bool isSelfContainedHeader(FileID);
|
2019-04-26 01:47:07 +08:00
|
|
|
// Heuristically headers that only want to be included via an umbrella.
|
|
|
|
static bool isDontIncludeMeHeader(llvm::StringRef);
|
2019-04-18 02:33:07 +08:00
|
|
|
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
// All Symbols collected from the AST.
|
2017-12-24 03:38:03 +08:00
|
|
|
SymbolSlab::Builder Symbols;
|
2019-05-03 21:17:29 +08:00
|
|
|
// File IDs for Symbol.IncludeHeaders.
|
|
|
|
// The final spelling is calculated in finish().
|
|
|
|
llvm::DenseMap<SymbolID, FileID> IncludeFiles;
|
|
|
|
void setIncludeLocation(const Symbol &S, SourceLocation);
|
|
|
|
// Indexed macros, to be erased if they turned out to be include guards.
|
|
|
|
llvm::DenseSet<const IdentifierInfo *> IndexedMacros;
|
[clangd] Collect the refs when the main file is header.
Summary:
Previously, we only collect refs of the symbols which are declared in
the preamble and referenced in the main file, it works well when the
main file is .cpp file.
However, when the main file is .h file (when opening a .h file in the
editor), we don't collect refs of the symbol declared in this file, so we miss
these refs in our dynamic index.
A typical scenario:
1. Open Foo.h (which contains class Foo)
2. Open Foo.cpp, call find references for Foo
And we only get refs from Foo.cpp.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63818
llvm-svn: 364893
2019-07-02 17:16:21 +08:00
|
|
|
// All refs collected from the AST. It includes:
|
|
|
|
// 1) symbols declared in the preamble and referenced from the main file (
|
|
|
|
// which is not a header), or
|
|
|
|
// 2) symbols declared and referenced from the main file (which is a header)
|
[clangd] SymbolOccurrences -> Refs and cleanup
Summary:
A few things that I noticed while merging the SwapIndex patch:
- SymbolOccurrences and particularly SymbolOccurrenceSlab are unwieldy names,
and these names appear *a lot*. Ref, RefSlab, etc seem clear enough
and read/format much better.
- The asymmetry between SymbolSlab and RefSlab (build() vs freeze()) is
confusing and irritating, and doesn't even save much code.
Avoiding RefSlab::Builder was my idea, but it was a bad one; add it.
- DenseMap<SymbolID, ArrayRef<Ref>> seems like a reasonable compromise for
constructing MemIndex - and means many less wasted allocations than the
current DenseMap<SymbolID, vector<Ref*>> for FileIndex, and none for
slabs.
- RefSlab::find() is not actually used for anything, so we can throw
away the DenseMap and keep the representation much more compact.
- A few naming/consistency fixes: e.g. Slabs,Refs -> Symbols,Refs.
Reviewers: ioeric
Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51605
llvm-svn: 341368
2018-09-04 22:39:56 +08:00
|
|
|
RefSlab::Builder Refs;
|
2019-06-04 12:25:44 +08:00
|
|
|
// All relations collected from the AST.
|
|
|
|
RelationSlab::Builder Relations;
|
2018-01-10 01:32:00 +08:00
|
|
|
ASTContext *ASTCtx;
|
|
|
|
std::shared_ptr<Preprocessor> PP;
|
|
|
|
std::shared_ptr<GlobalCodeCompletionAllocator> CompletionAllocator;
|
|
|
|
std::unique_ptr<CodeCompletionTUInfo> CompletionTUInfo;
|
2018-01-10 22:57:58 +08:00
|
|
|
Options Opts;
|
2019-11-20 22:18:54 +08:00
|
|
|
using SymbolRef = std::pair<SourceLocation, index::SymbolRoleSet>;
|
2018-07-09 23:31:07 +08:00
|
|
|
// Symbols referenced from the current TU, flushed on finish().
|
2018-03-12 22:49:09 +08:00
|
|
|
llvm::DenseSet<const NamedDecl *> ReferencedDecls;
|
2018-07-09 23:31:07 +08:00
|
|
|
llvm::DenseSet<const IdentifierInfo *> ReferencedMacros;
|
2019-11-20 22:18:54 +08:00
|
|
|
llvm::DenseMap<const NamedDecl *, std::vector<SymbolRef>> DeclRefs;
|
|
|
|
llvm::DenseMap<SymbolID, std::vector<SymbolRef>> MacroRefs;
|
2018-06-04 19:31:55 +08:00
|
|
|
// Maps canonical declaration provided by clang to canonical declaration for
|
|
|
|
// an index symbol, if clangd prefers a different declaration than that
|
|
|
|
// provided by clang. For example, friend declaration might be considered
|
|
|
|
// canonical by clang but should not be considered canonical in the index
|
|
|
|
// unless it's a definition.
|
|
|
|
llvm::DenseMap<const Decl *, const Decl *> CanonicalDecls;
|
2018-11-06 18:55:21 +08:00
|
|
|
// Cache whether to index a file or not.
|
|
|
|
llvm::DenseMap<FileID, bool> FilesToIndexCache;
|
2019-04-18 02:33:07 +08:00
|
|
|
llvm::DenseMap<FileID, bool> HeaderIsSelfContainedCache;
|
[clangd] Introduce a "Symbol" class.
Summary:
* The "Symbol" class represents a C++ symbol in the codebase, containing all the
information of a C++ symbol needed by clangd. clangd will use it in clangd's
AST/dynamic index and global/static index (code completion and code
navigation).
* The SymbolCollector (another IndexAction) will be used to recollect the
symbols when the source file is changed (for ASTIndex), or to generate
all C++ symbols for the whole project.
In the long term (when index-while-building is ready), clangd should share a
same "Symbol" structure and IndexAction with index-while-building, but
for now we want to have some stuff working in clangd.
Reviewers: ioeric, sammccall, ilya-biryukov, malaperle
Reviewed By: sammccall
Subscribers: malaperle, klimek, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D40897
llvm-svn: 320486
2017-12-12 23:42:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
2019-02-28 20:31:49 +08:00
|
|
|
|
2018-09-26 04:02:36 +08:00
|
|
|
#endif
|