2017-12-15 20:25:02 +08:00
|
|
|
//===--- FileIndex.cpp - Indexes for files. ------------------------ C++-*-===//
|
2017-12-14 22:50:58 +08:00
|
|
|
//
|
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
|
2017-12-14 22:50:58 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-12-15 20:25:02 +08:00
|
|
|
#include "FileIndex.h"
|
2019-12-12 19:12:17 +08:00
|
|
|
#include "CollectMacros.h"
|
2018-09-07 17:40:36 +08:00
|
|
|
#include "Logger.h"
|
2019-09-04 17:46:06 +08:00
|
|
|
#include "ParsedAST.h"
|
2018-08-22 20:43:17 +08:00
|
|
|
#include "SymbolCollector.h"
|
2019-02-05 00:19:57 +08:00
|
|
|
#include "index/CanonicalIncludes.h"
|
2018-09-18 18:30:44 +08:00
|
|
|
#include "index/Index.h"
|
2018-11-06 18:55:21 +08:00
|
|
|
#include "index/MemIndex.h"
|
2018-09-18 18:30:44 +08:00
|
|
|
#include "index/Merge.h"
|
2019-02-28 20:31:49 +08:00
|
|
|
#include "index/SymbolOrigin.h"
|
2018-10-16 16:53:52 +08:00
|
|
|
#include "index/dex/Dex.h"
|
2019-11-16 08:36:00 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2017-12-14 22:50:58 +08:00
|
|
|
#include "clang/Index/IndexingAction.h"
|
2019-09-07 04:08:32 +08:00
|
|
|
#include "clang/Index/IndexingOptions.h"
|
2018-09-19 17:35:04 +08:00
|
|
|
#include "clang/Lex/MacroInfo.h"
|
2018-05-24 23:50:15 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2018-11-06 18:55:21 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-09-18 18:30:44 +08:00
|
|
|
#include <memory>
|
2017-12-14 22:50:58 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2017-12-15 20:25:02 +08:00
|
|
|
|
2019-06-15 10:26:47 +08:00
|
|
|
static SlabTuple indexSymbols(ASTContext &AST, std::shared_ptr<Preprocessor> PP,
|
|
|
|
llvm::ArrayRef<Decl *> DeclsToIndex,
|
2019-12-12 19:12:17 +08:00
|
|
|
const MainFileMacros *MacroRefsToIndex,
|
2019-06-15 10:26:47 +08:00
|
|
|
const CanonicalIncludes &Includes,
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
bool IsIndexMainAST, llvm::StringRef Version) {
|
2018-01-10 22:57:58 +08:00
|
|
|
SymbolCollector::Options CollectorOpts;
|
2019-02-05 00:19:57 +08:00
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CollectorOpts.Includes = &Includes;
|
2018-03-12 22:49:09 +08:00
|
|
|
CollectorOpts.CountReferences = false;
|
2018-09-18 18:30:44 +08:00
|
|
|
CollectorOpts.Origin = SymbolOrigin::Dynamic;
|
2018-02-20 02:48:44 +08:00
|
|
|
|
2017-12-15 20:25:02 +08:00
|
|
|
index::IndexingOptions IndexOpts;
|
2018-03-12 22:49:09 +08:00
|
|
|
// We only need declarations, because we don't count references.
|
2017-12-15 20:25:02 +08:00
|
|
|
IndexOpts.SystemSymbolFilter =
|
2018-03-12 22:49:09 +08:00
|
|
|
index::IndexingOptions::SystemSymbolFilterKind::DeclarationsOnly;
|
2017-12-15 20:25:02 +08:00
|
|
|
IndexOpts.IndexFunctionLocals = false;
|
2018-09-19 17:35:04 +08:00
|
|
|
if (IsIndexMainAST) {
|
2018-09-18 18:30:44 +08:00
|
|
|
// We only collect refs when indexing main AST.
|
[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
|
|
|
CollectorOpts.RefFilter = RefKind::All;
|
2019-02-26 00:00:00 +08:00
|
|
|
// Comments for main file can always be obtained from sema, do not store
|
|
|
|
// them in the index.
|
|
|
|
CollectorOpts.StoreAllDocumentation = false;
|
2019-02-05 00:19:57 +08:00
|
|
|
} else {
|
2018-09-19 17:35:04 +08:00
|
|
|
IndexOpts.IndexMacrosInPreprocessor = true;
|
|
|
|
CollectorOpts.CollectMacro = true;
|
2019-02-26 00:00:00 +08:00
|
|
|
CollectorOpts.StoreAllDocumentation = true;
|
2018-09-19 17:35:04 +08:00
|
|
|
}
|
2018-09-01 03:53:37 +08:00
|
|
|
|
|
|
|
SymbolCollector Collector(std::move(CollectorOpts));
|
|
|
|
Collector.setPreprocessor(PP);
|
2019-12-12 19:12:17 +08:00
|
|
|
if (MacroRefsToIndex)
|
|
|
|
Collector.handleMacros(*MacroRefsToIndex);
|
2018-09-18 16:52:14 +08:00
|
|
|
index::indexTopLevelDecls(AST, *PP, DeclsToIndex, Collector, IndexOpts);
|
2018-05-24 23:50:15 +08:00
|
|
|
|
2018-09-01 03:53:37 +08:00
|
|
|
const auto &SM = AST.getSourceManager();
|
|
|
|
const auto *MainFileEntry = SM.getFileEntryForID(SM.getMainFileID());
|
2020-01-29 03:23:46 +08:00
|
|
|
std::string FileName =
|
|
|
|
std::string(MainFileEntry ? MainFileEntry->getName() : "");
|
2018-09-01 03:53:37 +08:00
|
|
|
|
|
|
|
auto Syms = Collector.takeSymbols();
|
[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
|
|
|
auto Refs = Collector.takeRefs();
|
2019-06-15 10:26:47 +08:00
|
|
|
auto Relations = Collector.takeRelations();
|
2019-12-12 19:12:17 +08:00
|
|
|
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
vlog("indexed {0} AST for {1} version {2}:\n"
|
|
|
|
" symbol slab: {3} symbols, {4} bytes\n"
|
|
|
|
" ref slab: {5} symbols, {6} refs, {7} bytes\n"
|
|
|
|
" relations slab: {8} relations, {9} bytes",
|
|
|
|
IsIndexMainAST ? "file" : "preamble", FileName, Version, Syms.size(),
|
|
|
|
Syms.bytes(), Refs.size(), Refs.numRefs(), Refs.bytes(),
|
|
|
|
Relations.size(), Relations.bytes());
|
2019-06-16 09:09:41 +08:00
|
|
|
return std::make_tuple(std::move(Syms), std::move(Refs),
|
|
|
|
std::move(Relations));
|
2017-12-15 20:25:02 +08:00
|
|
|
}
|
|
|
|
|
2019-06-15 10:26:47 +08:00
|
|
|
SlabTuple indexMainDecls(ParsedAST &AST) {
|
2018-09-18 18:30:44 +08:00
|
|
|
return indexSymbols(AST.getASTContext(), AST.getPreprocessorPtr(),
|
2019-12-12 19:12:17 +08:00
|
|
|
AST.getLocalTopLevelDecls(), &AST.getMacros(),
|
|
|
|
AST.getCanonicalIncludes(),
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
/*IsIndexMainAST=*/true, AST.version());
|
2018-09-18 18:30:44 +08:00
|
|
|
}
|
|
|
|
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST,
|
|
|
|
std::shared_ptr<Preprocessor> PP,
|
2019-06-15 10:26:47 +08:00
|
|
|
const CanonicalIncludes &Includes) {
|
2018-09-18 18:30:44 +08:00
|
|
|
std::vector<Decl *> DeclsToIndex(
|
|
|
|
AST.getTranslationUnitDecl()->decls().begin(),
|
|
|
|
AST.getTranslationUnitDecl()->decls().end());
|
2019-12-12 19:12:17 +08:00
|
|
|
return indexSymbols(AST, std::move(PP), DeclsToIndex,
|
|
|
|
/*MainFileMacros=*/nullptr, Includes,
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
/*IsIndexMainAST=*/false, Version);
|
[clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.
Summary:
This is now handled by a wrapper class SwapIndex, so MemIndex/DexIndex can be
immutable and focus on their job.
Old and busted:
I have a MemIndex, which holds a shared_ptr<vector<Symbol*>>, which keeps the
symbol slab alive. I update by calling build(shared_ptr<vector<Symbol*>>).
New hotness: I have a SwapIndex, which holds a unique_ptr<SymbolIndex>, which
holds a MemIndex, which holds a shared_ptr<void>, which keeps backing
data alive.
I update by building a new MemIndex and calling SwapIndex::reset().
Reviewers: kbobyrev, ioeric
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51422
llvm-svn: 341318
2018-09-03 22:37:43 +08:00
|
|
|
}
|
2018-06-15 16:55:00 +08:00
|
|
|
|
[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
|
|
|
void FileSymbols::update(PathRef Path, std::unique_ptr<SymbolSlab> Symbols,
|
2019-06-15 10:26:47 +08:00
|
|
|
std::unique_ptr<RefSlab> Refs,
|
|
|
|
std::unique_ptr<RelationSlab> Relations,
|
|
|
|
bool CountReferences) {
|
2017-12-14 22:50:58 +08:00
|
|
|
std::lock_guard<std::mutex> Lock(Mutex);
|
[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
|
|
|
if (!Symbols)
|
|
|
|
FileToSymbols.erase(Path);
|
2017-12-14 22:50:58 +08:00
|
|
|
else
|
[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
|
|
|
FileToSymbols[Path] = std::move(Symbols);
|
2019-05-09 22:22:07 +08:00
|
|
|
if (!Refs) {
|
[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
|
|
|
FileToRefs.erase(Path);
|
2019-06-15 10:26:47 +08:00
|
|
|
} else {
|
|
|
|
RefSlabAndCountReferences Item;
|
|
|
|
Item.CountReferences = CountReferences;
|
|
|
|
Item.Slab = std::move(Refs);
|
|
|
|
FileToRefs[Path] = std::move(Item);
|
2019-05-09 22:22:07 +08:00
|
|
|
}
|
2019-06-15 10:26:47 +08:00
|
|
|
if (!Relations)
|
|
|
|
FileToRelations.erase(Path);
|
|
|
|
else
|
|
|
|
FileToRelations[Path] = std::move(Relations);
|
2017-12-14 22:50:58 +08:00
|
|
|
}
|
|
|
|
|
2018-10-16 16:53:52 +08:00
|
|
|
std::unique_ptr<SymbolIndex>
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle) {
|
[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
|
|
|
std::vector<std::shared_ptr<SymbolSlab>> SymbolSlabs;
|
|
|
|
std::vector<std::shared_ptr<RefSlab>> RefSlabs;
|
2019-06-15 10:26:47 +08:00
|
|
|
std::vector<std::shared_ptr<RelationSlab>> RelationSlabs;
|
2019-05-09 22:22:07 +08:00
|
|
|
std::vector<RefSlab *> MainFileRefs;
|
2017-12-14 22:50:58 +08:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> Lock(Mutex);
|
[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
|
|
|
for (const auto &FileAndSymbols : FileToSymbols)
|
|
|
|
SymbolSlabs.push_back(FileAndSymbols.second);
|
2019-05-09 22:22:07 +08:00
|
|
|
for (const auto &FileAndRefs : FileToRefs) {
|
|
|
|
RefSlabs.push_back(FileAndRefs.second.Slab);
|
|
|
|
if (FileAndRefs.second.CountReferences)
|
|
|
|
MainFileRefs.push_back(RefSlabs.back().get());
|
|
|
|
}
|
2019-06-15 10:26:47 +08:00
|
|
|
for (const auto &FileAndRelations : FileToRelations)
|
|
|
|
RelationSlabs.push_back(FileAndRelations.second);
|
2017-12-14 22:50:58 +08:00
|
|
|
}
|
[clangd] Factor out the data-swapping functionality from MemIndex/DexIndex.
Summary:
This is now handled by a wrapper class SwapIndex, so MemIndex/DexIndex can be
immutable and focus on their job.
Old and busted:
I have a MemIndex, which holds a shared_ptr<vector<Symbol*>>, which keeps the
symbol slab alive. I update by calling build(shared_ptr<vector<Symbol*>>).
New hotness: I have a SwapIndex, which holds a unique_ptr<SymbolIndex>, which
holds a MemIndex, which holds a shared_ptr<void>, which keeps backing
data alive.
I update by building a new MemIndex and calling SwapIndex::reset().
Reviewers: kbobyrev, ioeric
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51422
llvm-svn: 341318
2018-09-03 22:37:43 +08:00
|
|
|
std::vector<const Symbol *> AllSymbols;
|
2018-11-06 18:55:21 +08:00
|
|
|
std::vector<Symbol> SymsStorage;
|
|
|
|
switch (DuplicateHandle) {
|
|
|
|
case DuplicateHandling::Merge: {
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::DenseMap<SymbolID, Symbol> Merged;
|
2018-11-06 18:55:21 +08:00
|
|
|
for (const auto &Slab : SymbolSlabs) {
|
|
|
|
for (const auto &Sym : *Slab) {
|
2019-05-09 22:22:07 +08:00
|
|
|
assert(Sym.References == 0 &&
|
|
|
|
"Symbol with non-zero references sent to FileSymbols");
|
2018-11-06 18:55:21 +08:00
|
|
|
auto I = Merged.try_emplace(Sym.ID, Sym);
|
|
|
|
if (!I.second)
|
2018-11-07 20:25:27 +08:00
|
|
|
I.first->second = mergeSymbol(I.first->second, Sym);
|
2018-11-06 18:55:21 +08:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 22:22:07 +08:00
|
|
|
for (const RefSlab *Refs : MainFileRefs)
|
|
|
|
for (const auto &Sym : *Refs) {
|
|
|
|
auto It = Merged.find(Sym.first);
|
2019-05-09 23:07:53 +08:00
|
|
|
// This might happen while background-index is still running.
|
|
|
|
if (It == Merged.end())
|
|
|
|
continue;
|
2019-05-09 22:22:07 +08:00
|
|
|
It->getSecond().References += Sym.second.size();
|
|
|
|
}
|
2018-11-06 18:55:21 +08:00
|
|
|
SymsStorage.reserve(Merged.size());
|
|
|
|
for (auto &Sym : Merged) {
|
|
|
|
SymsStorage.push_back(std::move(Sym.second));
|
|
|
|
AllSymbols.push_back(&SymsStorage.back());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DuplicateHandling::PickOne: {
|
|
|
|
llvm::DenseSet<SymbolID> AddedSymbols;
|
|
|
|
for (const auto &Slab : SymbolSlabs)
|
2019-05-09 22:22:07 +08:00
|
|
|
for (const auto &Sym : *Slab) {
|
|
|
|
assert(Sym.References == 0 &&
|
|
|
|
"Symbol with non-zero references sent to FileSymbols");
|
2018-11-06 18:55:21 +08:00
|
|
|
if (AddedSymbols.insert(Sym.ID).second)
|
|
|
|
AllSymbols.push_back(&Sym);
|
2019-05-09 22:22:07 +08:00
|
|
|
}
|
2018-11-06 18:55:21 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
[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
|
|
|
|
|
|
|
std::vector<Ref> RefsStorage; // Contiguous ranges for each SymbolID.
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::DenseMap<SymbolID, llvm::ArrayRef<Ref>> AllRefs;
|
[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
|
|
|
{
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::DenseMap<SymbolID, llvm::SmallVector<Ref, 4>> MergedRefs;
|
[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
|
|
|
size_t Count = 0;
|
|
|
|
for (const auto &RefSlab : RefSlabs)
|
|
|
|
for (const auto &Sym : *RefSlab) {
|
|
|
|
MergedRefs[Sym.first].append(Sym.second.begin(), Sym.second.end());
|
|
|
|
Count += Sym.second.size();
|
|
|
|
}
|
|
|
|
RefsStorage.reserve(Count);
|
|
|
|
AllRefs.reserve(MergedRefs.size());
|
|
|
|
for (auto &Sym : MergedRefs) {
|
|
|
|
auto &SymRefs = Sym.second;
|
|
|
|
// Sorting isn't required, but yields more stable results over rebuilds.
|
2018-10-07 22:49:41 +08:00
|
|
|
llvm::sort(SymRefs);
|
|
|
|
llvm::copy(SymRefs, back_inserter(RefsStorage));
|
[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
|
|
|
AllRefs.try_emplace(
|
|
|
|
Sym.first,
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::ArrayRef<Ref>(&RefsStorage[RefsStorage.size() - SymRefs.size()],
|
|
|
|
SymRefs.size()));
|
2018-09-01 03:53:37 +08:00
|
|
|
}
|
[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
|
|
|
}
|
2018-09-01 03:53:37 +08:00
|
|
|
|
2019-06-15 10:26:47 +08:00
|
|
|
std::vector<Relation> AllRelations;
|
|
|
|
for (const auto &RelationSlab : RelationSlabs) {
|
|
|
|
for (const auto &R : *RelationSlab)
|
|
|
|
AllRelations.push_back(R);
|
|
|
|
}
|
|
|
|
|
2018-11-06 18:55:21 +08:00
|
|
|
size_t StorageSize =
|
|
|
|
RefsStorage.size() * sizeof(Ref) + SymsStorage.size() * sizeof(Symbol);
|
2018-09-10 19:46:07 +08:00
|
|
|
for (const auto &Slab : SymbolSlabs)
|
|
|
|
StorageSize += Slab->bytes();
|
|
|
|
for (const auto &RefSlab : RefSlabs)
|
|
|
|
StorageSize += RefSlab->bytes();
|
2019-06-15 10:26:47 +08:00
|
|
|
for (const auto &RelationSlab : RelationSlabs)
|
|
|
|
StorageSize += RelationSlab->bytes();
|
2018-09-10 19:46:07 +08:00
|
|
|
|
[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
|
|
|
// Index must keep the slabs and contiguous ranges alive.
|
2018-10-16 16:53:52 +08:00
|
|
|
switch (Type) {
|
|
|
|
case IndexType::Light:
|
2019-08-15 07:52:23 +08:00
|
|
|
return std::make_unique<MemIndex>(
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
|
2019-06-15 10:26:47 +08:00
|
|
|
std::move(AllRelations),
|
2018-10-16 16:53:52 +08:00
|
|
|
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
|
2018-11-06 18:55:21 +08:00
|
|
|
std::move(RefsStorage), std::move(SymsStorage)),
|
2018-10-16 16:53:52 +08:00
|
|
|
StorageSize);
|
|
|
|
case IndexType::Heavy:
|
2019-08-15 07:52:23 +08:00
|
|
|
return std::make_unique<dex::Dex>(
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::make_pointee_range(AllSymbols), std::move(AllRefs),
|
2019-06-15 10:26:47 +08:00
|
|
|
std::move(AllRelations),
|
2018-10-16 16:53:52 +08:00
|
|
|
std::make_tuple(std::move(SymbolSlabs), std::move(RefSlabs),
|
2018-11-06 18:55:21 +08:00
|
|
|
std::move(RefsStorage), std::move(SymsStorage)),
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
StorageSize);
|
2018-10-16 16:53:52 +08:00
|
|
|
}
|
2018-10-20 21:18:49 +08:00
|
|
|
llvm_unreachable("Unknown clangd::IndexType");
|
2018-09-01 03:53:37 +08:00
|
|
|
}
|
|
|
|
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
FileIndex::FileIndex(bool UseDex)
|
2018-10-16 16:53:52 +08:00
|
|
|
: MergedIndex(&MainFileIndex, &PreambleIndex), UseDex(UseDex),
|
2019-08-15 07:52:23 +08:00
|
|
|
PreambleIndex(std::make_unique<MemIndex>()),
|
|
|
|
MainFileIndex(std::make_unique<MemIndex>()) {}
|
2018-09-18 18:30:44 +08:00
|
|
|
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
void FileIndex::updatePreamble(PathRef Path, llvm::StringRef Version,
|
|
|
|
ASTContext &AST,
|
2019-02-05 00:19:57 +08:00
|
|
|
std::shared_ptr<Preprocessor> PP,
|
|
|
|
const CanonicalIncludes &Includes) {
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
auto Slabs = indexHeaderSymbols(Version, AST, std::move(PP), Includes);
|
2019-05-09 22:22:07 +08:00
|
|
|
PreambleSymbols.update(
|
2019-08-15 07:52:23 +08:00
|
|
|
Path, std::make_unique<SymbolSlab>(std::move(std::get<0>(Slabs))),
|
|
|
|
std::make_unique<RefSlab>(),
|
|
|
|
std::make_unique<RelationSlab>(std::move(std::get<2>(Slabs))),
|
2019-06-15 10:26:47 +08:00
|
|
|
/*CountReferences=*/false);
|
2018-11-06 18:55:21 +08:00
|
|
|
PreambleIndex.reset(
|
|
|
|
PreambleSymbols.buildIndex(UseDex ? IndexType::Heavy : IndexType::Light,
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
DuplicateHandling::PickOne));
|
2018-09-18 18:30:44 +08:00
|
|
|
}
|
|
|
|
|
2018-09-18 21:35:16 +08:00
|
|
|
void FileIndex::updateMain(PathRef Path, ParsedAST &AST) {
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
auto Contents = indexMainDecls(AST);
|
2018-09-18 18:30:44 +08:00
|
|
|
MainFileSymbols.update(
|
2019-08-15 07:52:23 +08:00
|
|
|
Path, std::make_unique<SymbolSlab>(std::move(std::get<0>(Contents))),
|
|
|
|
std::make_unique<RefSlab>(std::move(std::get<1>(Contents))),
|
|
|
|
std::make_unique<RelationSlab>(std::move(std::get<2>(Contents))),
|
2019-05-09 22:22:07 +08:00
|
|
|
/*CountReferences=*/true);
|
[clangd] Cleanup: stop passing around list of supported URI schemes.
Summary:
Instead of passing around a list of supported URI schemes in clangd, we
expose an interface to convert a path to URI using any compatible scheme
that has been registered. It favors customized schemes and falls
back to "file" when no other scheme works.
Changes in this patch are:
- URI::create(AbsPath, URISchemes) -> URI::create(AbsPath). The new API finds a
compatible scheme from the registry.
- Remove URISchemes option everywhere (ClangdServer, SymbolCollecter, FileIndex etc).
- Unit tests will use "unittest" by default.
- Move "test" scheme from ClangdLSPServer to ClangdMain.cpp, and only
register the test scheme when lit-test or enable-lit-scheme is set.
(The new flag is added to make lit protocol.test work; I wonder if there
is alternative here.)
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D54800
llvm-svn: 347467
2018-11-22 23:02:05 +08:00
|
|
|
MainFileIndex.reset(
|
[clangd] Perform merge for main file symbols.
Summary:
Previously, we randomly pick one main file symbol in dynamic index, we
may loose the ideal symbol (with definition location) in the index.
It fixes the issue where sometimes we fail to go to the symbol definition, see:
1. call go-to-decl on Foo in Foo.cpp
2. jump to Foo.h, call go-to-def on Foo in Foo.h
we can't go back to Foo.cpp -- because we open Foo.cpp, Foo.h in clangd, both
files have Foo symbol (one with def&decl, one with decl only), we randomely
choose one.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63425
llvm-svn: 363568
2019-06-17 22:49:18 +08:00
|
|
|
MainFileSymbols.buildIndex(IndexType::Light, DuplicateHandling::Merge));
|
2018-08-24 17:12:54 +08:00
|
|
|
}
|
|
|
|
|
2017-12-14 22:50:58 +08:00
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|