[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"
|
[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 {
|
|
|
|
|
[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
|
|
|
/// \brief Collect declarations (symbols) from an AST.
|
|
|
|
/// 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
|
|
|
|
handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
|
2018-04-09 22:28:52 +08:00
|
|
|
ArrayRef<index::SymbolRelation> Relations,
|
|
|
|
SourceLocation Loc,
|
[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
|
|
|
index::IndexDataConsumer::ASTNodeInfo ASTNode) override;
|
|
|
|
|
2018-07-09 23:31:07 +08:00
|
|
|
bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI,
|
|
|
|
index::SymbolRoleSet Roles,
|
|
|
|
SourceLocation Loc) override;
|
|
|
|
|
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(); }
|
2018-08-31 20:54:13 +08:00
|
|
|
|
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-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;
|
[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
|
|
|
// All refs collected from the AST.
|
|
|
|
// Only symbols declared in preamble (from #include) and referenced from the
|
2018-08-31 20:54:13 +08:00
|
|
|
// main file will be included.
|
[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;
|
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;
|
[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
|
|
|
using DeclRef = 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;
|
[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
|
|
|
llvm::DenseMap<const NamedDecl *, std::vector<DeclRef>> DeclRefs;
|
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
|