[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
//===-- FindSymbolsTests.cpp -------------------------*- C++ -*------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Annotations.h"
|
|
|
|
#include "ClangdServer.h"
|
|
|
|
#include "FindSymbols.h"
|
|
|
|
#include "SyncAPI.h"
|
|
|
|
#include "TestFS.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ::testing::AllOf;
|
|
|
|
using ::testing::AnyOf;
|
|
|
|
using ::testing::ElementsAre;
|
|
|
|
using ::testing::IsEmpty;
|
|
|
|
using ::testing::UnorderedElementsAre;
|
|
|
|
|
|
|
|
class IgnoreDiagnostics : public DiagnosticsConsumer {
|
|
|
|
void onDiagnosticsReady(PathRef File,
|
|
|
|
std::vector<Diag> Diagnostics) override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// GMock helpers for matching SymbolInfos items.
|
2018-06-27 00:57:44 +08:00
|
|
|
MATCHER_P(QName, Name, "") {
|
|
|
|
if (arg.containerName.empty())
|
|
|
|
return arg.name == Name;
|
|
|
|
return (arg.containerName + "::" + arg.name) == Name;
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
}
|
|
|
|
MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
|
|
|
|
|
|
|
|
ClangdServer::Options optsForTests() {
|
|
|
|
auto ServerOpts = ClangdServer::optsForTest();
|
|
|
|
ServerOpts.BuildDynamicSymbolIndex = true;
|
2018-06-19 17:33:53 +08:00
|
|
|
ServerOpts.URISchemes = {"unittest", "file"};
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
return ServerOpts;
|
|
|
|
}
|
|
|
|
|
|
|
|
class WorkspaceSymbolsTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
WorkspaceSymbolsTest()
|
2018-06-19 17:33:53 +08:00
|
|
|
: Server(CDB, FSProvider, DiagConsumer, optsForTests()) {
|
|
|
|
// Make sure the test root directory is created.
|
|
|
|
FSProvider.Files[testPath("unused")] = "";
|
|
|
|
Server.setRootPath(testRoot());
|
|
|
|
}
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MockFSProvider FSProvider;
|
|
|
|
MockCompilationDatabase CDB;
|
|
|
|
IgnoreDiagnostics DiagConsumer;
|
|
|
|
ClangdServer Server;
|
2018-04-25 01:57:53 +08:00
|
|
|
int Limit = 0;
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
|
|
|
|
std::vector<SymbolInformation> getSymbols(StringRef Query) {
|
|
|
|
EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
|
|
|
|
auto SymbolInfos = runWorkspaceSymbols(Server, Query, Limit);
|
|
|
|
EXPECT_TRUE(bool(SymbolInfos)) << "workspaceSymbols returned an error";
|
|
|
|
return *SymbolInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addFile(StringRef FileName, StringRef Contents) {
|
|
|
|
auto Path = testPath(FileName);
|
|
|
|
FSProvider.Files[Path] = Contents;
|
|
|
|
Server.addDocument(Path, Contents);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, NoMacro) {
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#define MACRO X
|
|
|
|
)cpp");
|
|
|
|
|
|
|
|
// Macros are not in the index.
|
|
|
|
EXPECT_THAT(getSymbols("macro"), IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, NoLocals) {
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
void test(int FirstParam, int SecondParam) {
|
|
|
|
struct LocalClass {};
|
|
|
|
int local_var;
|
|
|
|
})cpp");
|
|
|
|
EXPECT_THAT(getSymbols("l"), IsEmpty());
|
|
|
|
EXPECT_THAT(getSymbols("p"), IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, Globals) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
int global_var;
|
|
|
|
|
|
|
|
int global_func();
|
|
|
|
|
|
|
|
struct GlobalStruct {};)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
|
|
|
EXPECT_THAT(getSymbols("global"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("GlobalStruct"), WithKind(SymbolKind::Struct)),
|
|
|
|
AllOf(QName("global_func"), WithKind(SymbolKind::Function)),
|
|
|
|
AllOf(QName("global_var"), WithKind(SymbolKind::Variable))));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, Unnamed) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
struct {
|
|
|
|
int InUnnamed;
|
|
|
|
} UnnamedStruct;)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
|
|
|
EXPECT_THAT(getSymbols("UnnamedStruct"),
|
2018-06-27 00:57:44 +08:00
|
|
|
ElementsAre(AllOf(QName("UnnamedStruct"),
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
WithKind(SymbolKind::Variable))));
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("InUnnamed"),
|
|
|
|
ElementsAre(AllOf(QName("(anonymous struct)::InUnnamed"),
|
|
|
|
WithKind(SymbolKind::Field))));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, InMainFile) {
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
int test() {
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
EXPECT_THAT(getSymbols("test"), IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, Namespaces) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
namespace ans1 {
|
|
|
|
int ai1;
|
|
|
|
namespace ans2 {
|
|
|
|
int ai2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("a"),
|
|
|
|
UnorderedElementsAre(QName("ans1"), QName("ans1::ai1"),
|
|
|
|
QName("ans1::ans2"),
|
|
|
|
QName("ans1::ans2::ai2")));
|
|
|
|
EXPECT_THAT(getSymbols("::"), ElementsAre(QName("ans1")));
|
|
|
|
EXPECT_THAT(getSymbols("::a"), ElementsAre(QName("ans1")));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
EXPECT_THAT(getSymbols("ans1::"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2")));
|
|
|
|
EXPECT_THAT(getSymbols("::ans1"), ElementsAre(QName("ans1")));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
EXPECT_THAT(getSymbols("::ans1::"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2")));
|
|
|
|
EXPECT_THAT(getSymbols("::ans1::ans2"), ElementsAre(QName("ans1::ans2")));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
EXPECT_THAT(getSymbols("::ans1::ans2::"),
|
2018-06-27 00:57:44 +08:00
|
|
|
ElementsAre(QName("ans1::ans2::ai2")));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, AnonymousNamespace) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
namespace {
|
|
|
|
void test() {}
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
|
|
|
EXPECT_THAT(getSymbols("test"), IsEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, MultiFile) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
int foo() {
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
addFile("foo2.h", R"cpp(
|
|
|
|
int foo2() {
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
#include "foo2.h"
|
|
|
|
)cpp");
|
|
|
|
EXPECT_THAT(getSymbols("foo"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(QName("foo"), QName("foo2")));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(WorkspaceSymbolsTest, GlobalNamespaceQueries) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
int foo() {
|
|
|
|
}
|
|
|
|
class Foo {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
namespace ns {
|
|
|
|
int foo2() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("::"),
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
|
|
|
|
AllOf(QName("foo"), WithKind(SymbolKind::Function)),
|
|
|
|
AllOf(QName("ns"), WithKind(SymbolKind::Namespace))));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
EXPECT_THAT(getSymbols(":"), IsEmpty());
|
|
|
|
EXPECT_THAT(getSymbols(""), IsEmpty());
|
|
|
|
}
|
|
|
|
|
[clangd] Add "member" symbols to the index
Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums
The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewers: ioeric, sammccall
Reviewed By: ioeric, sammccall
Subscribers: hokein, sammccall, jkorous, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44954
llvm-svn: 334017
2018-06-05 22:01:40 +08:00
|
|
|
TEST_F(WorkspaceSymbolsTest, Enums) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
enum {
|
|
|
|
Red
|
|
|
|
};
|
|
|
|
enum Color {
|
|
|
|
Green
|
|
|
|
};
|
|
|
|
enum class Color2 {
|
|
|
|
Yellow
|
|
|
|
};
|
|
|
|
namespace ns {
|
|
|
|
enum {
|
|
|
|
Black
|
|
|
|
};
|
|
|
|
enum Color3 {
|
|
|
|
Blue
|
|
|
|
};
|
|
|
|
enum class Color4 {
|
|
|
|
White
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("Red"), ElementsAre(QName("Red")));
|
|
|
|
EXPECT_THAT(getSymbols("::Red"), ElementsAre(QName("Red")));
|
|
|
|
EXPECT_THAT(getSymbols("Green"), ElementsAre(QName("Green")));
|
|
|
|
EXPECT_THAT(getSymbols("Green"), ElementsAre(QName("Green")));
|
|
|
|
EXPECT_THAT(getSymbols("Color2::Yellow"),
|
|
|
|
ElementsAre(QName("Color2::Yellow")));
|
|
|
|
EXPECT_THAT(getSymbols("Yellow"), ElementsAre(QName("Color2::Yellow")));
|
[clangd] Add "member" symbols to the index
Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums
The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewers: ioeric, sammccall
Reviewed By: ioeric, sammccall
Subscribers: hokein, sammccall, jkorous, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44954
llvm-svn: 334017
2018-06-05 22:01:40 +08:00
|
|
|
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("ns::Black"), ElementsAre(QName("ns::Black")));
|
|
|
|
EXPECT_THAT(getSymbols("ns::Blue"), ElementsAre(QName("ns::Blue")));
|
|
|
|
EXPECT_THAT(getSymbols("ns::Color4::White"),
|
|
|
|
ElementsAre(QName("ns::Color4::White")));
|
[clangd] Add "member" symbols to the index
Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums
The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewers: ioeric, sammccall
Reviewed By: ioeric, sammccall
Subscribers: hokein, sammccall, jkorous, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44954
llvm-svn: 334017
2018-06-05 22:01:40 +08:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:55:59 +08:00
|
|
|
TEST_F(WorkspaceSymbolsTest, Ranking) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
namespace ns{}
|
|
|
|
function func();
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("::"), ElementsAre(QName("func"), QName("ns")));
|
2018-06-07 14:55:59 +08:00
|
|
|
}
|
|
|
|
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
TEST_F(WorkspaceSymbolsTest, WithLimit) {
|
|
|
|
addFile("foo.h", R"cpp(
|
|
|
|
int foo;
|
|
|
|
int foo2;
|
|
|
|
)cpp");
|
|
|
|
addFile("foo.cpp", R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
)cpp");
|
2018-06-07 14:55:59 +08:00
|
|
|
// Foo is higher ranked because of exact name match.
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
EXPECT_THAT(getSymbols("foo"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("foo"), WithKind(SymbolKind::Variable)),
|
|
|
|
AllOf(QName("foo2"), WithKind(SymbolKind::Variable))));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
|
|
|
|
Limit = 1;
|
2018-06-27 00:57:44 +08:00
|
|
|
EXPECT_THAT(getSymbols("foo"), ElementsAre(QName("foo")));
|
[clangd] Implementation of workspace/symbol request
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
2018-04-24 04:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|