[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 15:42:10 +00:00
|
|
|
//===-- SymbolCollectorTests.cpp -------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-01-31 12:56:51 +00:00
|
|
|
#include "Annotations.h"
|
2018-01-29 22:28:08 +00:00
|
|
|
#include "TestFS.h"
|
2018-06-21 12:12:26 +00:00
|
|
|
#include "TestTU.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 15:42:10 +00:00
|
|
|
#include "index/SymbolCollector.h"
|
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/FileSystemOptions.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
2017-12-13 12:53:16 +00:00
|
|
|
#include "clang/Index/IndexingAction.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 15:42:10 +00:00
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2018-10-10 13:27:25 +00:00
|
|
|
#include "llvm/Support/VirtualFileSystem.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 15:42:10 +00:00
|
|
|
#include "gmock/gmock.h"
|
2017-12-13 12:53:16 +00:00
|
|
|
#include "gtest/gtest.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 15:42:10 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2018-10-20 15:30:37 +00:00
|
|
|
using namespace llvm;
|
2018-08-31 12:54:13 +00:00
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
namespace {
|
|
|
|
|
[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 14:39:56 +00:00
|
|
|
using testing::_;
|
2018-01-09 17:32:00 +00:00
|
|
|
using testing::AllOf;
|
[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 14:39:56 +00:00
|
|
|
using testing::Contains;
|
[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 15:42:10 +00:00
|
|
|
using testing::Eq;
|
|
|
|
using testing::Field;
|
2018-08-31 12:54:13 +00:00
|
|
|
using testing::IsEmpty;
|
2018-01-09 17:32:00 +00:00
|
|
|
using testing::Not;
|
[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 14:39:56 +00:00
|
|
|
using testing::Pair;
|
2017-12-13 12:53:16 +00:00
|
|
|
using testing::UnorderedElementsAre;
|
2018-01-09 10:44:09 +00:00
|
|
|
using testing::UnorderedElementsAreArray;
|
[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 15:42:10 +00:00
|
|
|
|
|
|
|
// GMock helpers for matching Symbol.
|
2018-06-22 16:11:35 +00:00
|
|
|
MATCHER_P(Labeled, Label, "") {
|
|
|
|
return (arg.Name + arg.Signature).str() == Label;
|
|
|
|
}
|
2018-08-31 13:55:01 +00:00
|
|
|
MATCHER_P(ReturnType, D, "") { return arg.ReturnType == D; }
|
|
|
|
MATCHER_P(Doc, D, "") { return arg.Documentation == D; }
|
2018-01-09 17:32:00 +00:00
|
|
|
MATCHER_P(Snippet, S, "") {
|
2018-06-22 16:11:35 +00:00
|
|
|
return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
|
2018-01-09 17:32:00 +00:00
|
|
|
}
|
2018-01-19 22:18:21 +00:00
|
|
|
MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
|
2018-11-14 11:55:45 +00:00
|
|
|
MATCHER_P(DeclURI, P, "") {
|
|
|
|
return StringRef(arg.CanonicalDeclaration.FileURI) == P;
|
|
|
|
}
|
|
|
|
MATCHER_P(DefURI, P, "") { return StringRef(arg.Definition.FileURI) == P; }
|
[clangd] Support multiple #include headers in one symbol.
Summary:
Currently, a symbol can have only one #include header attached, which
might not work well if the symbol can be imported via different #includes depending
on where it's used. This patch stores multiple #include headers (with # references)
for each symbol, so that CodeCompletion can decide which include to insert.
In this patch, code completion simply picks the most popular include as the default inserted header. We also return all possible includes and their edits in the `CodeCompletion` results.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: mgrang, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51291
llvm-svn: 341304
2018-09-03 10:18:21 +00:00
|
|
|
MATCHER_P(IncludeHeader, P, "") {
|
|
|
|
return (arg.IncludeHeaders.size() == 1) &&
|
|
|
|
(arg.IncludeHeaders.begin()->IncludeHeader == P);
|
|
|
|
}
|
2019-01-03 13:28:05 +00:00
|
|
|
MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
|
[clangd] Support multiple #include headers in one symbol.
Summary:
Currently, a symbol can have only one #include header attached, which
might not work well if the symbol can be imported via different #includes depending
on where it's used. This patch stores multiple #include headers (with # references)
for each symbol, so that CodeCompletion can decide which include to insert.
In this patch, code completion simply picks the most popular include as the default inserted header. We also return all possible includes and their edits in the `CodeCompletion` results.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: mgrang, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51291
llvm-svn: 341304
2018-09-03 10:18:21 +00:00
|
|
|
return (arg.IncludeHeader == IncludeHeader) && (arg.References == References);
|
|
|
|
}
|
2018-04-13 08:30:39 +00:00
|
|
|
MATCHER_P(DeclRange, Pos, "") {
|
[clangd] Encode Line/Column as a 32-bits integer.
Summary:
This would buy us more memory. Using a 32-bits integer is enough for
most human-readable source code (up to 4M lines and 4K columns).
Previsouly, we used 8 bytes for a position, now 4 bytes, it would save
us 8 bytes for each Ref and each Symbol instance.
For LLVM-project binary index file, we save ~13% memory.
| Before | After |
| 412MB | 355MB |
Reviewers: sammccall
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53363
llvm-svn: 344735
2018-10-18 10:43:50 +00:00
|
|
|
return std::make_tuple(arg.CanonicalDeclaration.Start.line(),
|
|
|
|
arg.CanonicalDeclaration.Start.column(),
|
|
|
|
arg.CanonicalDeclaration.End.line(),
|
|
|
|
arg.CanonicalDeclaration.End.column()) ==
|
|
|
|
std::make_tuple(Pos.start.line, Pos.start.character, Pos.end.line,
|
|
|
|
Pos.end.character);
|
2018-04-13 08:30:39 +00:00
|
|
|
}
|
|
|
|
MATCHER_P(DefRange, Pos, "") {
|
[clangd] Encode Line/Column as a 32-bits integer.
Summary:
This would buy us more memory. Using a 32-bits integer is enough for
most human-readable source code (up to 4M lines and 4K columns).
Previsouly, we used 8 bytes for a position, now 4 bytes, it would save
us 8 bytes for each Ref and each Symbol instance.
For LLVM-project binary index file, we save ~13% memory.
| Before | After |
| 412MB | 355MB |
Reviewers: sammccall
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53363
llvm-svn: 344735
2018-10-18 10:43:50 +00:00
|
|
|
return std::make_tuple(
|
|
|
|
arg.Definition.Start.line(), arg.Definition.Start.column(),
|
|
|
|
arg.Definition.End.line(), arg.Definition.End.column()) ==
|
|
|
|
std::make_tuple(Pos.start.line, Pos.start.character, Pos.end.line,
|
|
|
|
Pos.end.character);
|
2018-02-09 14:42:01 +00: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 14:39:56 +00:00
|
|
|
MATCHER_P(RefCount, R, "") { return int(arg.References) == R; }
|
[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 14:01:40 +00:00
|
|
|
MATCHER_P(ForCodeCompletion, IsIndexedForCodeCompletion, "") {
|
2018-09-06 18:52:26 +00:00
|
|
|
return static_cast<bool>(arg.Flags & Symbol::IndexedForCodeCompletion) ==
|
|
|
|
IsIndexedForCodeCompletion;
|
[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 14:01:40 +00:00
|
|
|
}
|
2018-09-06 18:52:26 +00:00
|
|
|
MATCHER(Deprecated, "") { return arg.Flags & Symbol::Deprecated; }
|
2018-10-18 12:23:05 +00:00
|
|
|
MATCHER(ImplementationDetail, "") {
|
|
|
|
return arg.Flags & Symbol::ImplementationDetail;
|
|
|
|
}
|
[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 14:39:56 +00:00
|
|
|
MATCHER(RefRange, "") {
|
|
|
|
const Ref &Pos = testing::get<0>(arg);
|
2018-08-31 12:54:13 +00:00
|
|
|
const Range &Range = testing::get<1>(arg);
|
[clangd] Encode Line/Column as a 32-bits integer.
Summary:
This would buy us more memory. Using a 32-bits integer is enough for
most human-readable source code (up to 4M lines and 4K columns).
Previsouly, we used 8 bytes for a position, now 4 bytes, it would save
us 8 bytes for each Ref and each Symbol instance.
For LLVM-project binary index file, we save ~13% memory.
| Before | After |
| 412MB | 355MB |
Reviewers: sammccall
Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D53363
llvm-svn: 344735
2018-10-18 10:43:50 +00:00
|
|
|
return std::make_tuple(Pos.Location.Start.line(), Pos.Location.Start.column(),
|
|
|
|
Pos.Location.End.line(), Pos.Location.End.column()) ==
|
|
|
|
std::make_tuple(Range.start.line, Range.start.character,
|
|
|
|
Range.end.line, Range.end.character);
|
2018-08-31 12:54:13 +00: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 14:39:56 +00:00
|
|
|
testing::Matcher<const std::vector<Ref> &>
|
2018-08-31 12:54:13 +00:00
|
|
|
HaveRanges(const std::vector<Range> Ranges) {
|
[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 14:39:56 +00:00
|
|
|
return testing::UnorderedPointwise(RefRange(), Ranges);
|
2018-08-31 12:54:13 +00:00
|
|
|
}
|
2018-06-21 12:12:26 +00:00
|
|
|
|
|
|
|
class ShouldCollectSymbolTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
void build(StringRef HeaderCode, StringRef Code = "") {
|
|
|
|
File.HeaderFilename = HeaderName;
|
|
|
|
File.Filename = FileName;
|
|
|
|
File.HeaderCode = HeaderCode;
|
|
|
|
File.Code = Code;
|
|
|
|
AST = File.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
// build() must have been called.
|
|
|
|
bool shouldCollect(StringRef Name, bool Qualified = true) {
|
|
|
|
assert(AST.hasValue());
|
|
|
|
return SymbolCollector::shouldCollectSymbol(
|
2018-11-09 12:56:49 +00:00
|
|
|
Qualified ? findDecl(*AST, Name) : findUnqualifiedDecl(*AST, Name),
|
2018-06-21 12:12:26 +00:00
|
|
|
AST->getASTContext(), SymbolCollector::Options());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string HeaderName = "f.h";
|
|
|
|
std::string FileName = "f.cpp";
|
|
|
|
TestTU File;
|
2019-01-03 13:28:05 +00:00
|
|
|
Optional<ParsedAST> AST; // Initialized after build.
|
2018-06-21 12:12:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ShouldCollectSymbolTest, ShouldCollectSymbol) {
|
|
|
|
build(R"(
|
|
|
|
namespace nx {
|
2018-11-09 12:56:49 +00:00
|
|
|
class X{};
|
|
|
|
auto f() { int Local; } // auto ensures function body is parsed.
|
2018-12-21 09:32:49 +00:00
|
|
|
struct { int x; } var;
|
2018-06-21 12:12:26 +00:00
|
|
|
namespace { class InAnonymous {}; }
|
|
|
|
}
|
|
|
|
)",
|
|
|
|
"class InMain {};");
|
|
|
|
auto AST = File.build();
|
|
|
|
EXPECT_TRUE(shouldCollect("nx"));
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::X"));
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::f"));
|
|
|
|
|
|
|
|
EXPECT_FALSE(shouldCollect("InMain"));
|
|
|
|
EXPECT_FALSE(shouldCollect("Local", /*Qualified=*/false));
|
|
|
|
EXPECT_FALSE(shouldCollect("InAnonymous", /*Qualified=*/false));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ShouldCollectSymbolTest, NoPrivateProtoSymbol) {
|
|
|
|
HeaderName = "f.proto.h";
|
|
|
|
build(
|
|
|
|
R"(// Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
|
|
namespace nx {
|
|
|
|
class Top_Level {};
|
|
|
|
class TopLevel {};
|
|
|
|
enum Kind {
|
|
|
|
KIND_OK,
|
|
|
|
Kind_Not_Ok,
|
|
|
|
};
|
|
|
|
})");
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::TopLevel"));
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::Kind::KIND_OK"));
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::Kind"));
|
|
|
|
|
|
|
|
EXPECT_FALSE(shouldCollect("nx::Top_Level"));
|
|
|
|
EXPECT_FALSE(shouldCollect("nx::Kind::Kind_Not_Ok"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ShouldCollectSymbolTest, DoubleCheckProtoHeaderComment) {
|
|
|
|
HeaderName = "f.proto.h";
|
|
|
|
build(R"(
|
|
|
|
namespace nx {
|
|
|
|
class Top_Level {};
|
|
|
|
enum Kind {
|
|
|
|
Kind_Fine
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)");
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::Top_Level"));
|
|
|
|
EXPECT_TRUE(shouldCollect("nx::Kind_Fine"));
|
|
|
|
}
|
|
|
|
|
[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 15:42:10 +00:00
|
|
|
class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
|
2017-12-13 12:53:16 +00:00
|
|
|
public:
|
2018-02-16 14:15:55 +00:00
|
|
|
SymbolIndexActionFactory(SymbolCollector::Options COpts,
|
|
|
|
CommentHandler *PragmaHandler)
|
|
|
|
: COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
|
[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 15:42:10 +00:00
|
|
|
|
2018-02-27 15:54:41 +00:00
|
|
|
clang::FrontendAction *create() override {
|
2018-02-16 14:15:55 +00:00
|
|
|
class WrappedIndexAction : public WrapperFrontendAction {
|
|
|
|
public:
|
|
|
|
WrappedIndexAction(std::shared_ptr<SymbolCollector> C,
|
|
|
|
const index::IndexingOptions &Opts,
|
|
|
|
CommentHandler *PragmaHandler)
|
|
|
|
: WrapperFrontendAction(
|
|
|
|
index::createIndexingAction(C, Opts, nullptr)),
|
|
|
|
PragmaHandler(PragmaHandler) {}
|
|
|
|
|
|
|
|
std::unique_ptr<ASTConsumer>
|
|
|
|
CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
|
|
|
|
if (PragmaHandler)
|
|
|
|
CI.getPreprocessor().addCommentHandler(PragmaHandler);
|
|
|
|
return WrapperFrontendAction::CreateASTConsumer(CI, InFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
index::IndexingOptions IndexOpts;
|
|
|
|
CommentHandler *PragmaHandler;
|
|
|
|
};
|
[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 15:42:10 +00:00
|
|
|
index::IndexingOptions IndexOpts;
|
|
|
|
IndexOpts.SystemSymbolFilter =
|
|
|
|
index::IndexingOptions::SystemSymbolFilterKind::All;
|
|
|
|
IndexOpts.IndexFunctionLocals = false;
|
2018-01-10 14:57:58 +00:00
|
|
|
Collector = std::make_shared<SymbolCollector>(COpts);
|
2018-02-27 15:54:41 +00:00
|
|
|
return new WrappedIndexAction(Collector, std::move(IndexOpts),
|
|
|
|
PragmaHandler);
|
[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 15:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<SymbolCollector> Collector;
|
2018-01-10 14:57:58 +00:00
|
|
|
SymbolCollector::Options COpts;
|
2018-02-16 14:15:55 +00:00
|
|
|
CommentHandler *PragmaHandler;
|
[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 15:42:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SymbolCollectorTest : public ::testing::Test {
|
|
|
|
public:
|
2018-02-06 16:10:35 +00:00
|
|
|
SymbolCollectorTest()
|
2018-10-20 15:30:37 +00:00
|
|
|
: InMemoryFileSystem(new vfs::InMemoryFileSystem),
|
2018-02-16 14:15:55 +00:00
|
|
|
TestHeaderName(testPath("symbol.h")),
|
2018-02-16 09:41:43 +00:00
|
|
|
TestFileName(testPath("symbol.cc")) {
|
[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 15:02:05 +00:00
|
|
|
TestHeaderURI = URI::create(TestHeaderName).toString();
|
|
|
|
TestFileURI = URI::create(TestFileName).toString();
|
2018-02-06 16:10:35 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 09:50:35 +00:00
|
|
|
bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode,
|
|
|
|
const std::vector<std::string> &ExtraArgs = {}) {
|
2018-10-20 15:30:37 +00:00
|
|
|
IntrusiveRefCntPtr<FileManager> Files(
|
[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 15:42:10 +00:00
|
|
|
new FileManager(FileSystemOptions(), InMemoryFileSystem));
|
|
|
|
|
2018-02-16 14:15:55 +00:00
|
|
|
auto Factory = llvm::make_unique<SymbolIndexActionFactory>(
|
|
|
|
CollectorOpts, PragmaHandler.get());
|
[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 15:42:10 +00:00
|
|
|
|
2018-05-24 14:40:24 +00:00
|
|
|
std::vector<std::string> Args = {
|
[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 14:01:40 +00:00
|
|
|
"symbol_collector", "-fsyntax-only", "-xc++",
|
|
|
|
"-std=c++11", "-include", TestHeaderName};
|
2018-02-06 09:50:35 +00:00
|
|
|
Args.insert(Args.end(), ExtraArgs.begin(), ExtraArgs.end());
|
[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 14:01:40 +00:00
|
|
|
// This allows to override the "-xc++" with something else, i.e.
|
|
|
|
// -xobjective-c++.
|
|
|
|
Args.push_back(TestFileName);
|
|
|
|
|
[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 15:42:10 +00:00
|
|
|
tooling::ToolInvocation Invocation(
|
2019-01-03 13:28:05 +00:00
|
|
|
Args, Factory->create(), Files.get(),
|
[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 15:42:10 +00:00
|
|
|
std::make_shared<PCHContainerOperations>());
|
|
|
|
|
2018-01-31 12:56:51 +00:00
|
|
|
InMemoryFileSystem->addFile(TestHeaderName, 0,
|
2018-10-20 15:30:37 +00:00
|
|
|
MemoryBuffer::getMemBuffer(HeaderCode));
|
2018-01-31 12:56:51 +00:00
|
|
|
InMemoryFileSystem->addFile(TestFileName, 0,
|
2018-10-20 15:30:37 +00:00
|
|
|
MemoryBuffer::getMemBuffer(MainCode));
|
[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 15:42:10 +00:00
|
|
|
Invocation.run();
|
|
|
|
Symbols = Factory->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 14:39:56 +00:00
|
|
|
Refs = Factory->Collector->takeRefs();
|
[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 15:42:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-10-20 15:30:37 +00:00
|
|
|
IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem;
|
2018-02-06 16:10:35 +00:00
|
|
|
std::string TestHeaderName;
|
|
|
|
std::string TestHeaderURI;
|
|
|
|
std::string TestFileName;
|
|
|
|
std::string TestFileURI;
|
[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 15:42:10 +00:00
|
|
|
SymbolSlab 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 14:39:56 +00:00
|
|
|
RefSlab Refs;
|
2018-01-10 14:57:58 +00:00
|
|
|
SymbolCollector::Options CollectorOpts;
|
2018-02-16 14:15:55 +00:00
|
|
|
std::unique_ptr<CommentHandler> PragmaHandler;
|
[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 15:42:10 +00:00
|
|
|
};
|
|
|
|
|
2018-01-10 14:57:58 +00:00
|
|
|
TEST_F(SymbolCollectorTest, CollectSymbols) {
|
[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 15:42:10 +00:00
|
|
|
const std::string Header = R"(
|
|
|
|
class Foo {
|
[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 14:01:40 +00:00
|
|
|
Foo() {}
|
|
|
|
Foo(int a) {}
|
[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 15:42:10 +00:00
|
|
|
void f();
|
[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 14:01:40 +00:00
|
|
|
friend void f1();
|
|
|
|
friend class Friend;
|
|
|
|
Foo& operator=(const Foo&);
|
|
|
|
~Foo();
|
|
|
|
class Nested {
|
|
|
|
void f();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
class Friend {
|
[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 15:42:10 +00:00
|
|
|
};
|
[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 14:01:40 +00: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 15:42:10 +00:00
|
|
|
void f1();
|
|
|
|
inline void f2() {}
|
2018-01-09 10:44:09 +00:00
|
|
|
static const int KInt = 2;
|
|
|
|
const char* kStr = "123";
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00: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 15:42:10 +00:00
|
|
|
namespace {
|
|
|
|
void ff() {} // ignore
|
|
|
|
}
|
2018-01-09 10:44:09 +00: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 15:42:10 +00:00
|
|
|
void f1() {}
|
2018-01-09 10:44:09 +00:00
|
|
|
|
|
|
|
namespace foo {
|
|
|
|
// Type alias
|
|
|
|
typedef int int32;
|
|
|
|
using int32_t = int32;
|
|
|
|
|
|
|
|
// Variable
|
|
|
|
int v1;
|
|
|
|
|
|
|
|
// Namespace
|
|
|
|
namespace bar {
|
|
|
|
int v2;
|
|
|
|
}
|
|
|
|
// Namespace alias
|
|
|
|
namespace baz = bar;
|
|
|
|
|
|
|
|
// FIXME: using declaration is not supported as the IndexAction will ignore
|
|
|
|
// implicit declarations (the implicit using shadow declaration) by default,
|
|
|
|
// and there is no way to customize this behavior at the moment.
|
|
|
|
using bar::v2;
|
|
|
|
} // namespace foo
|
[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 15:42:10 +00:00
|
|
|
)";
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00:00
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
2018-01-09 10:44:09 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAreArray(
|
[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 14:01:40 +00:00
|
|
|
{AllOf(QName("Foo"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("Foo::Foo"), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("Foo::Foo"), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("Foo::f"), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("Foo::~Foo"), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("Foo::operator="), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("Foo::Nested"), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("Foo::Nested::f"), ForCodeCompletion(false)),
|
|
|
|
|
|
|
|
AllOf(QName("Friend"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("f1"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("f2"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("KInt"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("kStr"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo::bar"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo::int32"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo::int32_t"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo::v1"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo::bar::v2"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("foo::baz"), ForCodeCompletion(true))}));
|
2018-01-29 15:13:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 13:25:29 +00:00
|
|
|
TEST_F(SymbolCollectorTest, Template) {
|
|
|
|
Annotations Header(R"(
|
|
|
|
// Template is indexed, specialization and instantiation is not.
|
[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 14:01:40 +00:00
|
|
|
template <class T> struct [[Tmpl]] {T $xdecl[[x]] = 0;};
|
2018-03-09 13:25:29 +00:00
|
|
|
template <> struct Tmpl<int> {};
|
|
|
|
extern template struct Tmpl<float>;
|
|
|
|
template struct Tmpl<double>;
|
|
|
|
)");
|
|
|
|
runSymbolCollector(Header.code(), /*Main=*/"");
|
[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 14:01:40 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAreArray(
|
|
|
|
{AllOf(QName("Tmpl"), DeclRange(Header.range())),
|
|
|
|
AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")))}));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, ObjCSymbols) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
@interface Person
|
|
|
|
- (void)someMethodName:(void*)name1 lastName:(void*)lName;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Person
|
|
|
|
- (void)someMethodName:(void*)name1 lastName:(void*)lName{
|
|
|
|
int foo;
|
|
|
|
^(int param){ int bar; };
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface Person (MyCategory)
|
|
|
|
- (void)someMethodName2:(void*)name2;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Person (MyCategory)
|
|
|
|
- (void)someMethodName2:(void*)name2 {
|
|
|
|
int foo2;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@protocol MyProtocol
|
|
|
|
- (void)someMethodName3:(void*)name3;
|
|
|
|
@end
|
|
|
|
)";
|
[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 15:02:05 +00:00
|
|
|
TestFileName = testPath("test.m");
|
[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 14:01:40 +00:00
|
|
|
runSymbolCollector(Header, /*Main=*/"", {"-fblocks", "-xobjective-c++"});
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
QName("Person"), QName("Person::someMethodName:lastName:"),
|
|
|
|
QName("MyCategory"), QName("Person::someMethodName2:"),
|
|
|
|
QName("MyProtocol"), QName("MyProtocol::someMethodName3:")));
|
2018-03-09 13:25:29 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 14:42:01 +00:00
|
|
|
TEST_F(SymbolCollectorTest, Locations) {
|
|
|
|
Annotations Header(R"cpp(
|
|
|
|
// Declared in header, defined in main.
|
2018-02-13 09:53:50 +00:00
|
|
|
extern int $xdecl[[X]];
|
|
|
|
class $clsdecl[[Cls]];
|
|
|
|
void $printdecl[[print]]();
|
2018-02-09 14:42:01 +00:00
|
|
|
|
|
|
|
// Declared in header, defined nowhere.
|
2018-02-13 09:53:50 +00:00
|
|
|
extern int $zdecl[[Z]];
|
2018-04-13 08:30:39 +00:00
|
|
|
|
|
|
|
void $foodecl[[fo\
|
|
|
|
o]]();
|
2018-02-09 14:42:01 +00:00
|
|
|
)cpp");
|
|
|
|
Annotations Main(R"cpp(
|
2018-02-13 09:53:50 +00:00
|
|
|
int $xdef[[X]] = 42;
|
|
|
|
class $clsdef[[Cls]] {};
|
|
|
|
void $printdef[[print]]() {}
|
2018-02-09 14:42:01 +00:00
|
|
|
|
|
|
|
// Declared/defined in main only.
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00:00
|
|
|
int Y;
|
2018-02-09 14:42:01 +00:00
|
|
|
)cpp");
|
|
|
|
runSymbolCollector(Header.code(), Main.code());
|
2019-01-03 13:28:05 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("X"), DeclRange(Header.range("xdecl")),
|
|
|
|
DefRange(Main.range("xdef"))),
|
|
|
|
AllOf(QName("Cls"), DeclRange(Header.range("clsdecl")),
|
|
|
|
DefRange(Main.range("clsdef"))),
|
|
|
|
AllOf(QName("print"), DeclRange(Header.range("printdecl")),
|
|
|
|
DefRange(Main.range("printdef"))),
|
|
|
|
AllOf(QName("Z"), DeclRange(Header.range("zdecl"))),
|
|
|
|
AllOf(QName("foo"), DeclRange(Header.range("foodecl")))));
|
2018-02-09 14:42:01 +00: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 14:39:56 +00:00
|
|
|
TEST_F(SymbolCollectorTest, Refs) {
|
2018-08-31 12:54:13 +00:00
|
|
|
Annotations Header(R"(
|
|
|
|
class $foo[[Foo]] {
|
|
|
|
public:
|
|
|
|
$foo[[Foo]]() {}
|
|
|
|
$foo[[Foo]](int);
|
|
|
|
};
|
|
|
|
class $bar[[Bar]];
|
|
|
|
void $func[[func]]();
|
2018-11-07 14:59:24 +00:00
|
|
|
|
|
|
|
namespace $ns[[NS]] {} // namespace ref is ignored
|
2018-08-31 12:54:13 +00:00
|
|
|
)");
|
|
|
|
Annotations Main(R"(
|
|
|
|
class $bar[[Bar]] {};
|
|
|
|
|
|
|
|
void $func[[func]]();
|
|
|
|
|
|
|
|
void fff() {
|
|
|
|
$foo[[Foo]] foo;
|
|
|
|
$bar[[Bar]] bar;
|
|
|
|
$func[[func]]();
|
|
|
|
int abc = 0;
|
|
|
|
$foo[[Foo]] foo2 = abc;
|
|
|
|
}
|
|
|
|
)");
|
|
|
|
Annotations SymbolsOnlyInMainCode(R"(
|
|
|
|
int a;
|
|
|
|
void b() {}
|
|
|
|
static const int c = 0;
|
|
|
|
class d {};
|
|
|
|
)");
|
[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 14:39:56 +00:00
|
|
|
CollectorOpts.RefFilter = RefKind::All;
|
2018-08-31 12:54:13 +00:00
|
|
|
runSymbolCollector(Header.code(),
|
|
|
|
(Main.code() + SymbolsOnlyInMainCode.code()).str());
|
|
|
|
auto HeaderSymbols = TestTU::withHeaderCode(Header.code()).headerSymbols();
|
|
|
|
|
[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 14:39:56 +00:00
|
|
|
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
|
|
|
|
HaveRanges(Main.ranges("foo")))));
|
|
|
|
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Bar").ID,
|
|
|
|
HaveRanges(Main.ranges("bar")))));
|
|
|
|
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "func").ID,
|
|
|
|
HaveRanges(Main.ranges("func")))));
|
2018-11-07 14:59:24 +00:00
|
|
|
EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _))));
|
[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 14:39:56 +00:00
|
|
|
// Symbols *only* in the main file (a, b, c) had no refs collected.
|
2018-08-31 12:54:13 +00:00
|
|
|
auto MainSymbols =
|
|
|
|
TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();
|
[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 14:39:56 +00:00
|
|
|
EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "a").ID, _))));
|
|
|
|
EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "b").ID, _))));
|
|
|
|
EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(MainSymbols, "c").ID, _))));
|
2018-08-31 12:54:13 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 08:38:36 +00:00
|
|
|
TEST_F(SymbolCollectorTest, RefsInHeaders) {
|
|
|
|
CollectorOpts.RefFilter = RefKind::All;
|
|
|
|
CollectorOpts.RefsInHeaders = true;
|
|
|
|
Annotations Header(R"(
|
|
|
|
class [[Foo]] {};
|
|
|
|
)");
|
|
|
|
runSymbolCollector(Header.code(), "");
|
|
|
|
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Foo").ID,
|
|
|
|
HaveRanges(Header.ranges()))));
|
|
|
|
}
|
|
|
|
|
2018-03-12 14:49:09 +00:00
|
|
|
TEST_F(SymbolCollectorTest, References) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
class W;
|
|
|
|
class X {};
|
|
|
|
class Y;
|
|
|
|
class Z {}; // not used anywhere
|
|
|
|
Y* y = nullptr; // used in header doesn't count
|
2018-04-09 14:28:52 +00:00
|
|
|
#define GLOBAL_Z(name) Z name;
|
2018-03-12 14:49:09 +00:00
|
|
|
)";
|
|
|
|
const std::string Main = R"(
|
|
|
|
W* w = nullptr;
|
|
|
|
W* w2 = nullptr; // only one usage counts
|
|
|
|
X x();
|
|
|
|
class V;
|
|
|
|
V* v = nullptr; // Used, but not eligible for indexing.
|
|
|
|
class Y{}; // definition doesn't count as a reference
|
2018-04-09 14:28:52 +00:00
|
|
|
GLOBAL_Z(z); // Not a reference to Z, we don't spell the type.
|
2018-03-12 14:49:09 +00:00
|
|
|
)";
|
|
|
|
CollectorOpts.CountReferences = true;
|
|
|
|
runSymbolCollector(Header, Main);
|
|
|
|
EXPECT_THAT(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 14:39:56 +00:00
|
|
|
UnorderedElementsAre(AllOf(QName("W"), RefCount(1)),
|
|
|
|
AllOf(QName("X"), RefCount(1)),
|
|
|
|
AllOf(QName("Y"), RefCount(0)),
|
|
|
|
AllOf(QName("Z"), RefCount(0)), QName("y")));
|
2018-03-12 14:49:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 15:13:29 +00:00
|
|
|
TEST_F(SymbolCollectorTest, SymbolRelativeNoFallback) {
|
|
|
|
runSymbolCollector("class Foo {};", /*Main=*/"");
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
|
2018-01-29 15:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, SymbolRelativeWithFallback) {
|
2018-02-06 16:10:35 +00:00
|
|
|
TestHeaderName = "x.h";
|
|
|
|
TestFileName = "x.cpp";
|
[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 15:02:05 +00:00
|
|
|
TestHeaderURI = URI::create(testPath(TestHeaderName)).toString();
|
2018-02-16 09:41:43 +00:00
|
|
|
CollectorOpts.FallbackDir = testRoot();
|
2018-01-29 15:13:29 +00:00
|
|
|
runSymbolCollector("class Foo {};", /*Main=*/"");
|
2019-01-03 13:28:05 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
|
2018-02-06 16:10:35 +00: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 15:02:05 +00:00
|
|
|
TEST_F(SymbolCollectorTest, UnittestURIScheme) {
|
2018-02-06 16:10:35 +00:00
|
|
|
// Use test URI scheme from URITests.cpp
|
2018-06-15 08:55:00 +00:00
|
|
|
TestHeaderName = testPath("x.h");
|
|
|
|
TestFileName = testPath("x.cpp");
|
2018-02-06 16:10:35 +00:00
|
|
|
runSymbolCollector("class Foo {};", /*Main=*/"");
|
2018-06-15 08:55:00 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), DeclURI("unittest:///x.h"))));
|
2018-02-06 16:10:35 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 09:35:55 +00:00
|
|
|
TEST_F(SymbolCollectorTest, IncludeEnums) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
enum {
|
|
|
|
Red
|
|
|
|
};
|
|
|
|
enum Color {
|
|
|
|
Green
|
|
|
|
};
|
|
|
|
enum class Color2 {
|
[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 14:01:40 +00:00
|
|
|
Yellow
|
2018-01-19 09:35:55 +00:00
|
|
|
};
|
|
|
|
namespace ns {
|
|
|
|
enum {
|
|
|
|
Black
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
[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 14:01:40 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("Red"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("Color"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("Green"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("Color2"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("Color2::Yellow"), ForCodeCompletion(false)),
|
|
|
|
AllOf(QName("ns"), ForCodeCompletion(true)),
|
|
|
|
AllOf(QName("ns::Black"), ForCodeCompletion(true))));
|
2018-01-19 09:35:55 +00:00
|
|
|
}
|
|
|
|
|
[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 14:01:40 +00:00
|
|
|
TEST_F(SymbolCollectorTest, NamelessSymbols) {
|
2018-01-19 09:35:55 +00:00
|
|
|
const std::string Header = R"(
|
|
|
|
struct {
|
|
|
|
int a;
|
|
|
|
} Foo;
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
[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 14:01:40 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"),
|
|
|
|
QName("(anonymous struct)::a")));
|
2018-01-19 09:35:55 +00: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 15:02:05 +00:00
|
|
|
TEST_F(SymbolCollectorTest, SymbolFormedFromRegisteredSchemeFromMacro) {
|
2018-01-31 12:56:51 +00:00
|
|
|
|
|
|
|
Annotations Header(R"(
|
|
|
|
#define FF(name) \
|
|
|
|
class name##_Test {};
|
|
|
|
|
2018-02-13 09:53:50 +00:00
|
|
|
$expansion[[FF]](abc);
|
2018-01-31 12:56:51 +00:00
|
|
|
|
|
|
|
#define FF2() \
|
2018-02-13 09:53:50 +00:00
|
|
|
class $spelling[[Test]] {};
|
2018-01-31 12:56:51 +00:00
|
|
|
|
|
|
|
FF2();
|
|
|
|
)");
|
|
|
|
|
|
|
|
runSymbolCollector(Header.code(), /*Main=*/"");
|
2019-01-03 13:28:05 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("abc_Test"), DeclRange(Header.range("expansion")),
|
|
|
|
DeclURI(TestHeaderURI)),
|
|
|
|
AllOf(QName("Test"), DeclRange(Header.range("spelling")),
|
|
|
|
DeclURI(TestHeaderURI))));
|
2018-01-31 12:56:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 11:57:15 +00:00
|
|
|
TEST_F(SymbolCollectorTest, SymbolFormedByCLI) {
|
|
|
|
Annotations Header(R"(
|
|
|
|
#ifdef NAME
|
|
|
|
class $expansion[[NAME]] {};
|
|
|
|
#endif
|
|
|
|
)");
|
|
|
|
runSymbolCollector(Header.code(), /*Main=*/"", /*ExtraArgs=*/{"-DNAME=name"});
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(
|
|
|
|
QName("name"), DeclRange(Header.range("expansion")),
|
|
|
|
DeclURI(TestHeaderURI))));
|
|
|
|
}
|
|
|
|
|
2018-01-10 14:57:58 +00:00
|
|
|
TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
class Foo {};
|
|
|
|
void f1();
|
|
|
|
inline void f2() {}
|
|
|
|
)";
|
|
|
|
const std::string Main = R"(
|
|
|
|
namespace {
|
|
|
|
void ff() {} // ignore
|
|
|
|
}
|
|
|
|
void main_f() {} // ignore
|
|
|
|
void f1() {}
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, Main);
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(QName("Foo"), QName("f1"), QName("f2")));
|
|
|
|
}
|
|
|
|
|
[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 14:01:40 +00:00
|
|
|
TEST_F(SymbolCollectorTest, ClassMembers) {
|
2018-01-10 14:57:58 +00:00
|
|
|
const std::string Header = R"(
|
|
|
|
class Foo {
|
|
|
|
void f() {}
|
|
|
|
void g();
|
|
|
|
static void sf() {}
|
|
|
|
static void ssf();
|
|
|
|
static int x;
|
|
|
|
};
|
|
|
|
)";
|
2018-01-09 17:32:00 +00:00
|
|
|
const std::string Main = R"(
|
2018-01-10 14:57:58 +00:00
|
|
|
void Foo::g() {}
|
|
|
|
void Foo::ssf() {}
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, Main);
|
[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 14:01:40 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(QName("Foo"), QName("Foo::f"),
|
|
|
|
QName("Foo::g"), QName("Foo::sf"),
|
|
|
|
QName("Foo::ssf"), QName("Foo::x")));
|
2018-01-10 14:57:58 +00:00
|
|
|
}
|
|
|
|
|
2018-02-02 10:31:42 +00:00
|
|
|
TEST_F(SymbolCollectorTest, Scopes) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
namespace na {
|
|
|
|
class Foo {};
|
|
|
|
namespace nb {
|
|
|
|
class Bar {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(QName("na"), QName("na::nb"),
|
|
|
|
QName("na::Foo"), QName("na::nb::Bar")));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, ExternC) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
extern "C" { class Foo {}; }
|
|
|
|
namespace na {
|
|
|
|
extern "C" { class Bar {}; }
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
2018-02-02 17:01:36 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(QName("na"), QName("Foo"),
|
|
|
|
QName("na::Bar")));
|
2018-02-02 10:31:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, SkipInlineNamespace) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
namespace na {
|
|
|
|
inline namespace nb {
|
|
|
|
class Foo {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace na {
|
|
|
|
// This is still inlined.
|
|
|
|
namespace nb {
|
|
|
|
class Bar {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(QName("na"), QName("na::nb"),
|
|
|
|
QName("na::Foo"), QName("na::Bar")));
|
|
|
|
}
|
|
|
|
|
2018-01-10 14:57:58 +00:00
|
|
|
TEST_F(SymbolCollectorTest, SymbolWithDocumentation) {
|
|
|
|
const std::string Header = R"(
|
2018-01-09 17:32:00 +00:00
|
|
|
namespace nx {
|
|
|
|
/// Foo comment.
|
|
|
|
int ff(int x, double y) { return 0; }
|
|
|
|
}
|
|
|
|
)";
|
2018-01-10 14:57:58 +00:00
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
2018-05-16 12:32:44 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
QName("nx"), AllOf(QName("nx::ff"), Labeled("ff(int x, double y)"),
|
2018-06-22 16:11:35 +00:00
|
|
|
ReturnType("int"), Doc("Foo comment."))));
|
2018-01-09 17:32:00 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 16:11:35 +00:00
|
|
|
TEST_F(SymbolCollectorTest, Snippet) {
|
2018-01-10 14:57:58 +00:00
|
|
|
const std::string Header = R"(
|
2018-01-09 17:32:00 +00:00
|
|
|
namespace nx {
|
|
|
|
void f() {}
|
|
|
|
int ff(int x, double y) { return 0; }
|
|
|
|
}
|
|
|
|
)";
|
2018-01-10 14:57:58 +00:00
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
2018-06-22 16:11:35 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
QName("nx"),
|
|
|
|
AllOf(QName("nx::f"), Labeled("f()"), Snippet("f()")),
|
|
|
|
AllOf(QName("nx::ff"), Labeled("ff(int x, double y)"),
|
|
|
|
Snippet("ff(${1:int x}, ${2:double y})"))));
|
2018-01-09 17:32:00 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 14:15:55 +00:00
|
|
|
TEST_F(SymbolCollectorTest, IncludeHeaderSameAsFileURI) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
runSymbolCollector("class Foo {};", /*Main=*/"");
|
[clangd] Support multiple #include headers in one symbol.
Summary:
Currently, a symbol can have only one #include header attached, which
might not work well if the symbol can be imported via different #includes depending
on where it's used. This patch stores multiple #include headers (with # references)
for each symbol, so that CodeCompletion can decide which include to insert.
In this patch, code completion simply picks the most popular include as the default inserted header. We also return all possible includes and their edits in the `CodeCompletion` results.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: mgrang, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D51291
llvm-svn: 341304
2018-09-03 10:18:21 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), DeclURI(TestHeaderURI))));
|
|
|
|
EXPECT_THAT(Symbols.begin()->IncludeHeaders,
|
|
|
|
UnorderedElementsAre(IncludeHeaderWithRef(TestHeaderURI, 1u)));
|
2018-02-16 14:15:55 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 13:14:03 +00:00
|
|
|
#ifndef _WIN32
|
2018-02-16 14:15:55 +00:00
|
|
|
TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
addSystemHeadersMapping(&Includes);
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
// bits/basic_string.h$ should be mapped to <string>
|
|
|
|
TestHeaderName = "/nasty/bits/basic_string.h";
|
|
|
|
TestFileName = "/nasty/bits/basic_string.cpp";
|
[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 15:02:05 +00:00
|
|
|
TestHeaderURI = URI::create(TestHeaderName).toString();
|
2018-02-16 14:15:55 +00:00
|
|
|
runSymbolCollector("class string {};", /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("string"),
|
|
|
|
DeclURI(TestHeaderURI),
|
|
|
|
IncludeHeader("<string>"))));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-01 18:06:40 +00:00
|
|
|
TEST_F(SymbolCollectorTest, STLiosfwd) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
addSystemHeadersMapping(&Includes);
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
// Symbols from <iosfwd> should be mapped individually.
|
|
|
|
TestHeaderName = testPath("iosfwd");
|
|
|
|
TestFileName = testPath("iosfwd.cpp");
|
|
|
|
std::string Header = R"(
|
|
|
|
namespace std {
|
|
|
|
class no_map {};
|
|
|
|
class ios {};
|
|
|
|
class ostream {};
|
|
|
|
class filebuf {};
|
|
|
|
} // namespace std
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
QName("std"),
|
|
|
|
AllOf(QName("std::no_map"), IncludeHeader("<iosfwd>")),
|
|
|
|
AllOf(QName("std::ios"), IncludeHeader("<ios>")),
|
|
|
|
AllOf(QName("std::ostream"), IncludeHeader("<ostream>")),
|
|
|
|
AllOf(QName("std::filebuf"), IncludeHeader("<fstream>"))));
|
|
|
|
}
|
|
|
|
|
2018-02-16 14:15:55 +00:00
|
|
|
TEST_F(SymbolCollectorTest, IWYUPragma) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
PragmaHandler = collectIWYUHeaderMaps(&Includes);
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
const std::string Header = R"(
|
|
|
|
// IWYU pragma: private, include the/good/header.h
|
|
|
|
class Foo {};
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), DeclURI(TestHeaderURI),
|
|
|
|
IncludeHeader("\"the/good/header.h\""))));
|
|
|
|
}
|
|
|
|
|
2018-05-22 08:33:30 +00:00
|
|
|
TEST_F(SymbolCollectorTest, IWYUPragmaWithDoubleQuotes) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
PragmaHandler = collectIWYUHeaderMaps(&Includes);
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
const std::string Header = R"(
|
|
|
|
// IWYU pragma: private, include "the/good/header.h"
|
|
|
|
class Foo {};
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), DeclURI(TestHeaderURI),
|
|
|
|
IncludeHeader("\"the/good/header.h\""))));
|
|
|
|
}
|
|
|
|
|
2018-05-24 14:40:24 +00:00
|
|
|
TEST_F(SymbolCollectorTest, SkipIncFileWhenCanonicalizeHeaders) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
Includes.addMapping(TestHeaderName, "<canonical>");
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
auto IncFile = testPath("test.inc");
|
[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 15:02:05 +00:00
|
|
|
auto IncURI = URI::create(IncFile).toString();
|
2018-05-24 14:40:24 +00:00
|
|
|
InMemoryFileSystem->addFile(IncFile, 0,
|
2018-10-20 15:30:37 +00:00
|
|
|
MemoryBuffer::getMemBuffer("class X {};"));
|
2018-05-24 14:40:24 +00:00
|
|
|
runSymbolCollector("#include \"test.inc\"\nclass Y {};", /*Main=*/"",
|
|
|
|
/*ExtraArgs=*/{"-I", testRoot()});
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
|
|
|
|
IncludeHeader("<canonical>")),
|
|
|
|
AllOf(QName("Y"), DeclURI(TestHeaderURI),
|
|
|
|
IncludeHeader("<canonical>"))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, MainFileIsHeaderWhenSkipIncFile) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
TestFileName = testPath("main.h");
|
[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 15:02:05 +00:00
|
|
|
TestFileURI = URI::create(TestFileName).toString();
|
2018-05-24 14:40:24 +00:00
|
|
|
auto IncFile = testPath("test.inc");
|
[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 15:02:05 +00:00
|
|
|
auto IncURI = URI::create(IncFile).toString();
|
2018-05-24 14:40:24 +00:00
|
|
|
InMemoryFileSystem->addFile(IncFile, 0,
|
2018-10-20 15:30:37 +00:00
|
|
|
MemoryBuffer::getMemBuffer("class X {};"));
|
2018-05-24 14:40:24 +00:00
|
|
|
runSymbolCollector("", /*Main=*/"#include \"test.inc\"",
|
|
|
|
/*ExtraArgs=*/{"-I", testRoot()});
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
|
|
|
|
IncludeHeader(TestFileURI))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, MainFileIsHeaderWithoutExtensionWhenSkipIncFile) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
TestFileName = testPath("no_ext_main");
|
[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 15:02:05 +00:00
|
|
|
TestFileURI = URI::create(TestFileName).toString();
|
2018-05-24 14:40:24 +00:00
|
|
|
auto IncFile = testPath("test.inc");
|
[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 15:02:05 +00:00
|
|
|
auto IncURI = URI::create(IncFile).toString();
|
2018-05-24 14:40:24 +00:00
|
|
|
InMemoryFileSystem->addFile(IncFile, 0,
|
2018-10-20 15:30:37 +00:00
|
|
|
MemoryBuffer::getMemBuffer("class X {};"));
|
2018-05-24 14:40:24 +00:00
|
|
|
runSymbolCollector("", /*Main=*/"#include \"test.inc\"",
|
|
|
|
/*ExtraArgs=*/{"-I", testRoot()});
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
|
|
|
|
IncludeHeader(TestFileURI))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, FallbackToIncFileWhenIncludingFileIsCC) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
CanonicalIncludes Includes;
|
|
|
|
CollectorOpts.Includes = &Includes;
|
|
|
|
auto IncFile = testPath("test.inc");
|
[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 15:02:05 +00:00
|
|
|
auto IncURI = URI::create(IncFile).toString();
|
2018-05-24 14:40:24 +00:00
|
|
|
InMemoryFileSystem->addFile(IncFile, 0,
|
2018-10-20 15:30:37 +00:00
|
|
|
MemoryBuffer::getMemBuffer("class X {};"));
|
2018-05-24 14:40:24 +00:00
|
|
|
runSymbolCollector("", /*Main=*/"#include \"test.inc\"",
|
|
|
|
/*ExtraArgs=*/{"-I", testRoot()});
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), DeclURI(IncURI),
|
|
|
|
IncludeHeader(IncURI))));
|
|
|
|
}
|
|
|
|
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00:00
|
|
|
TEST_F(SymbolCollectorTest, AvoidUsingFwdDeclsAsCanonicalDecls) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
Annotations Header(R"(
|
|
|
|
// Forward declarations of TagDecls.
|
|
|
|
class C;
|
|
|
|
struct S;
|
|
|
|
union U;
|
|
|
|
|
|
|
|
// Canonical declarations.
|
|
|
|
class $cdecl[[C]] {};
|
|
|
|
struct $sdecl[[S]] {};
|
[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 14:01:40 +00:00
|
|
|
union $udecl[[U]] {int $xdecl[[x]]; bool $ydecl[[y]];};
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00:00
|
|
|
)");
|
|
|
|
runSymbolCollector(Header.code(), /*Main=*/"");
|
[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 14:01:40 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("C"), DeclURI(TestHeaderURI),
|
|
|
|
DeclRange(Header.range("cdecl")), IncludeHeader(TestHeaderURI),
|
|
|
|
DefURI(TestHeaderURI), DefRange(Header.range("cdecl"))),
|
|
|
|
AllOf(QName("S"), DeclURI(TestHeaderURI),
|
|
|
|
DeclRange(Header.range("sdecl")), IncludeHeader(TestHeaderURI),
|
|
|
|
DefURI(TestHeaderURI), DefRange(Header.range("sdecl"))),
|
|
|
|
AllOf(QName("U"), DeclURI(TestHeaderURI),
|
|
|
|
DeclRange(Header.range("udecl")), IncludeHeader(TestHeaderURI),
|
|
|
|
DefURI(TestHeaderURI), DefRange(Header.range("udecl"))),
|
|
|
|
AllOf(QName("U::x"), DeclURI(TestHeaderURI),
|
|
|
|
DeclRange(Header.range("xdecl")), DefURI(TestHeaderURI),
|
|
|
|
DefRange(Header.range("xdecl"))),
|
|
|
|
AllOf(QName("U::y"), DeclURI(TestHeaderURI),
|
|
|
|
DeclRange(Header.range("ydecl")), DefURI(TestHeaderURI),
|
|
|
|
DefRange(Header.range("ydecl")))));
|
[clangd] Prefer the definition of a TagDecl (e.g. class) as CanonicalDeclaration.
Summary:
Currently, we pick the first declaration of a symbol in a TU, which is considered
canonical in the clangIndex, as the canonical declaration in clangd. This causes
forward declarations that might appear in a random header to be used as a
canonical declaration, which is not desirable for features like go-to-declaration
or include insertion.
For example, for class X, we would consider the forward declaration in fwd.h to
be the canonical declaration, while the preferred canonical declaration should
be the actual definition in x.h.
```
// fwd.h
class X; // forward decl
// x.h
class X {};
```
This patch fixes the issue by making symbol collector favor the actual definition of
a TagDecl (i.e. class/struct/enum/union) found in a header file over the first seen
declarations in a TU. Other symbol types like functions are not handled because
using the first seen declarations as canonical declarations is usually a good
heuristic for them.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits
Differential Revision: https://reviews.llvm.org/D43823
llvm-svn: 326313
2018-02-28 09:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, ClassForwardDeclarationIsCanonical) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
runSymbolCollector(/*Header=*/"class X;", /*Main=*/"class X {};");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(
|
|
|
|
QName("X"), DeclURI(TestHeaderURI),
|
|
|
|
IncludeHeader(TestHeaderURI), DefURI(TestFileURI))));
|
|
|
|
}
|
|
|
|
|
2018-04-30 11:40:02 +00:00
|
|
|
TEST_F(SymbolCollectorTest, UTF16Character) {
|
|
|
|
// ö is 2-bytes.
|
|
|
|
Annotations Header(/*Header=*/"class [[pörk]] {};");
|
|
|
|
runSymbolCollector(Header.code(), /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("pörk"), DeclRange(Header.range()))));
|
|
|
|
}
|
|
|
|
|
2018-06-04 11:31:55 +00:00
|
|
|
TEST_F(SymbolCollectorTest, DoNotIndexSymbolsInFriendDecl) {
|
|
|
|
Annotations Header(R"(
|
|
|
|
namespace nx {
|
|
|
|
class $z[[Z]] {};
|
|
|
|
class X {
|
|
|
|
friend class Y;
|
|
|
|
friend class Z;
|
|
|
|
friend void foo();
|
|
|
|
friend void $bar[[bar]]() {}
|
|
|
|
};
|
|
|
|
class $y[[Y]] {};
|
|
|
|
void $foo[[foo]]();
|
|
|
|
}
|
|
|
|
)");
|
|
|
|
runSymbolCollector(Header.code(), /*Main=*/"");
|
|
|
|
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
QName("nx"), QName("nx::X"),
|
|
|
|
AllOf(QName("nx::Y"), DeclRange(Header.range("y"))),
|
|
|
|
AllOf(QName("nx::Z"), DeclRange(Header.range("z"))),
|
|
|
|
AllOf(QName("nx::foo"), DeclRange(Header.range("foo"))),
|
|
|
|
AllOf(QName("nx::bar"), DeclRange(Header.range("bar")))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SymbolCollectorTest, ReferencesInFriendDecl) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
class X;
|
|
|
|
class Y;
|
|
|
|
)";
|
|
|
|
const std::string Main = R"(
|
|
|
|
class C {
|
|
|
|
friend ::X;
|
|
|
|
friend class Y;
|
|
|
|
};
|
|
|
|
)";
|
|
|
|
CollectorOpts.CountReferences = true;
|
|
|
|
runSymbolCollector(Header, Main);
|
[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 14:39:56 +00:00
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("X"), RefCount(1)),
|
|
|
|
AllOf(QName("Y"), RefCount(1))));
|
2018-06-04 11:31:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-05 06:20:41 +00:00
|
|
|
TEST_F(SymbolCollectorTest, Origin) {
|
|
|
|
CollectorOpts.Origin = SymbolOrigin::Static;
|
|
|
|
runSymbolCollector("class Foo {};", /*Main=*/"");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
Field(&Symbol::Origin, SymbolOrigin::Static)));
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:31:07 +00:00
|
|
|
TEST_F(SymbolCollectorTest, CollectMacros) {
|
|
|
|
CollectorOpts.CollectIncludePath = true;
|
|
|
|
Annotations Header(R"(
|
|
|
|
#define X 1
|
|
|
|
#define $mac[[MAC]](x) int x
|
|
|
|
#define $used[[USED]](y) float y;
|
|
|
|
|
|
|
|
MAC(p);
|
|
|
|
)");
|
|
|
|
const std::string Main = R"(
|
|
|
|
#define MAIN 1 // not indexed
|
|
|
|
USED(t);
|
|
|
|
)";
|
|
|
|
CollectorOpts.CountReferences = true;
|
|
|
|
CollectorOpts.CollectMacro = true;
|
|
|
|
runSymbolCollector(Header.code(), Main);
|
[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 14:39:56 +00:00
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(QName("p"),
|
|
|
|
AllOf(QName("X"), DeclURI(TestHeaderURI),
|
|
|
|
IncludeHeader(TestHeaderURI)),
|
|
|
|
AllOf(Labeled("MAC(x)"), RefCount(0),
|
|
|
|
DeclRange(Header.range("mac"))),
|
|
|
|
AllOf(Labeled("USED(y)"), RefCount(1),
|
|
|
|
DeclRange(Header.range("used")))));
|
2018-07-09 15:31:07 +00:00
|
|
|
}
|
|
|
|
|
2018-09-06 18:52:26 +00:00
|
|
|
TEST_F(SymbolCollectorTest, DeprecatedSymbols) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
void TestClangc() __attribute__((deprecated("", "")));
|
|
|
|
void TestClangd();
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /**/ "");
|
|
|
|
EXPECT_THAT(Symbols, UnorderedElementsAre(
|
|
|
|
AllOf(QName("TestClangc"), Deprecated()),
|
|
|
|
AllOf(QName("TestClangd"), Not(Deprecated()))));
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:23:05 +00:00
|
|
|
TEST_F(SymbolCollectorTest, ImplementationDetail) {
|
|
|
|
const std::string Header = R"(
|
|
|
|
#define DECL_NAME(x, y) x##_##y##_Decl
|
|
|
|
#define DECL(x, y) class DECL_NAME(x, y) {};
|
|
|
|
DECL(X, Y); // X_Y_Decl
|
|
|
|
|
|
|
|
class Public {};
|
|
|
|
)";
|
|
|
|
runSymbolCollector(Header, /**/ "");
|
|
|
|
EXPECT_THAT(Symbols,
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("X_Y_Decl"), ImplementationDetail()),
|
|
|
|
AllOf(QName("Public"), Not(ImplementationDetail()))));
|
|
|
|
}
|
|
|
|
|
[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 15:42:10 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|