[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++ -*------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
[clangd] 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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "Annotations.h"
|
|
|
|
#include "ClangdServer.h"
|
|
|
|
#include "FindSymbols.h"
|
|
|
|
#include "SyncAPI.h"
|
|
|
|
#include "TestFS.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
#include "TestTU.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
[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
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ::testing::AllOf;
|
|
|
|
using ::testing::ElementsAre;
|
2018-07-06 03:35:01 +08:00
|
|
|
using ::testing::ElementsAreArray;
|
2018-11-23 23:21:19 +08:00
|
|
|
using ::testing::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
|
|
|
using ::testing::IsEmpty;
|
|
|
|
using ::testing::UnorderedElementsAre;
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2018-11-23 23:21:19 +08:00
|
|
|
MATCHER_P(WithName, N, "") { return arg.name == N; }
|
[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; }
|
2021-02-18 23:34:06 +08:00
|
|
|
MATCHER_P(WithDetail, Detail, "") { return arg.detail == Detail; }
|
2020-07-13 21:02:47 +08:00
|
|
|
MATCHER_P(SymRange, Range, "") { return arg.range == Range; }
|
[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
|
|
|
|
2018-11-23 23:21:19 +08:00
|
|
|
// GMock helpers for matching DocumentSymbol.
|
|
|
|
MATCHER_P(SymNameRange, Range, "") { return arg.selectionRange == Range; }
|
|
|
|
template <class... ChildMatchers>
|
2019-05-06 18:08:47 +08:00
|
|
|
::testing::Matcher<DocumentSymbol> Children(ChildMatchers... ChildrenM) {
|
2018-11-23 23:21:19 +08:00
|
|
|
return Field(&DocumentSymbol::children, ElementsAre(ChildrenM...));
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
std::vector<SymbolInformation> getSymbols(TestTU &TU, llvm::StringRef Query,
|
|
|
|
int Limit = 0) {
|
|
|
|
auto SymbolInfos = getWorkspaceSymbols(Query, Limit, TU.index().get(),
|
|
|
|
testPath(TU.Filename));
|
|
|
|
EXPECT_TRUE(bool(SymbolInfos)) << "workspaceSymbols returned an error";
|
|
|
|
return *SymbolInfos;
|
[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
|
|
|
}
|
|
|
|
|
2021-01-14 16:35:38 +08:00
|
|
|
TEST(WorkspaceSymbols, Macros) {
|
2020-07-01 18:16:54 +08:00
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2019-01-28 22:11:49 +08:00
|
|
|
#define MACRO X
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2019-01-28 22:11:49 +08:00
|
|
|
|
|
|
|
// LSP's SymbolKind doesn't have a "Macro" kind, and
|
|
|
|
// indexSymbolKindToSymbolKind() currently maps macros
|
|
|
|
// to SymbolKind::String.
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "macro"),
|
2019-01-28 22:11:49 +08:00
|
|
|
ElementsAre(AllOf(QName("MACRO"), WithKind(SymbolKind::String))));
|
[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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, NoLocals) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
void test(int FirstParam, int SecondParam) {
|
|
|
|
struct LocalClass {};
|
|
|
|
int local_var;
|
2020-07-01 18:16:54 +08:00
|
|
|
})cpp";
|
2021-01-16 00:19:53 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "l"), ElementsAre(QName("LocalClass")));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "p"), IsEmpty());
|
[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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, Globals) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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
|
|
|
int global_var;
|
|
|
|
|
|
|
|
int global_func();
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
struct GlobalStruct {};)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, Unnamed) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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
|
|
|
struct {
|
|
|
|
int InUnnamed;
|
2020-07-01 18:16:54 +08:00
|
|
|
} UnnamedStruct;)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "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))));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "InUnnamed"),
|
2018-06-27 00:57:44 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, InMainFile) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2019-01-14 18:01:17 +08:00
|
|
|
int test() {}
|
2020-07-01 18:16:54 +08:00
|
|
|
static void test2() {}
|
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "test"),
|
|
|
|
ElementsAre(QName("test"), QName("test2")));
|
[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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, Namespaces) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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 ans1 {
|
|
|
|
int ai1;
|
2020-10-05 17:52:58 +08:00
|
|
|
namespace ans2 {
|
|
|
|
int ai2;
|
|
|
|
namespace ans3 {
|
|
|
|
int ai3;
|
|
|
|
}
|
|
|
|
}
|
[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
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "a"),
|
2020-10-05 17:52:58 +08:00
|
|
|
UnorderedElementsAre(
|
|
|
|
QName("ans1"), QName("ans1::ai1"), QName("ans1::ans2"),
|
|
|
|
QName("ans1::ans2::ai2"), QName("ans1::ans2::ans3"),
|
|
|
|
QName("ans1::ans2::ans3::ai3")));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "::"), ElementsAre(QName("ans1")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "::a"), ElementsAre(QName("ans1")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "ans1::"),
|
2020-10-05 17:52:58 +08:00
|
|
|
UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2"),
|
|
|
|
QName("ans1::ans2::ai2"),
|
|
|
|
QName("ans1::ans2::ans3"),
|
|
|
|
QName("ans1::ans2::ans3::ai3")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "ans2::"),
|
|
|
|
UnorderedElementsAre(QName("ans1::ans2::ai2"),
|
|
|
|
QName("ans1::ans2::ans3"),
|
|
|
|
QName("ans1::ans2::ans3::ai3")));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "::ans1"), ElementsAre(QName("ans1")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "::ans1::"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2")));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "::ans1::ans2"), ElementsAre(QName("ans1::ans2")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "::ans1::ans2::"),
|
2020-10-05 17:52:58 +08:00
|
|
|
ElementsAre(QName("ans1::ans2::ai2"), QName("ans1::ans2::ans3")));
|
|
|
|
|
|
|
|
// Ensure sub-sequence matching works.
|
|
|
|
EXPECT_THAT(getSymbols(TU, "ans1::ans3::ai"),
|
|
|
|
UnorderedElementsAre(QName("ans1::ans2::ans3::ai3")));
|
[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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, AnonymousNamespace) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
[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 {
|
|
|
|
void test() {}
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "test"), ElementsAre(QName("test")));
|
[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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, MultiFile) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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
|
|
|
int foo() {
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.AdditionalFiles["foo2.h"] = R"cpp(
|
[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
|
|
|
int foo2() {
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
|
|
|
#include "foo2.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, GlobalNamespaceQueries) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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
|
|
|
int foo() {
|
|
|
|
}
|
|
|
|
class Foo {
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
namespace ns {
|
|
|
|
int foo2() {
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "::"),
|
2018-06-27 00:57:44 +08:00
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
|
|
|
|
AllOf(QName("foo"), WithKind(SymbolKind::Function)),
|
|
|
|
AllOf(QName("ns"), WithKind(SymbolKind::Namespace))));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, ":"), IsEmpty());
|
2021-03-02 23:43:21 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, ""),
|
|
|
|
UnorderedElementsAre(QName("foo"), QName("Foo"), QName("Foo::a"),
|
|
|
|
QName("ns"), QName("ns::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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, Enums) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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
|
|
|
enum {
|
|
|
|
Red
|
|
|
|
};
|
|
|
|
enum Color {
|
|
|
|
Green
|
|
|
|
};
|
|
|
|
enum class Color2 {
|
|
|
|
Yellow
|
|
|
|
};
|
|
|
|
namespace ns {
|
|
|
|
enum {
|
|
|
|
Black
|
|
|
|
};
|
|
|
|
enum Color3 {
|
|
|
|
Blue
|
|
|
|
};
|
|
|
|
enum class Color4 {
|
|
|
|
White
|
|
|
|
};
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "Red"), ElementsAre(QName("Red")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "::Red"), ElementsAre(QName("Red")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "Green"), ElementsAre(QName("Green")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "Green"), ElementsAre(QName("Green")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "Color2::Yellow"),
|
2018-06-27 00:57:44 +08:00
|
|
|
ElementsAre(QName("Color2::Yellow")));
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "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
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "ns::Black"), ElementsAre(QName("ns::Black")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "ns::Blue"), ElementsAre(QName("ns::Blue")));
|
|
|
|
EXPECT_THAT(getSymbols(TU, "ns::Color4::White"),
|
2018-06-27 00:57:44 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, Ranking) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
2018-06-07 14:55:59 +08:00
|
|
|
namespace ns{}
|
2018-12-19 22:51:07 +08:00
|
|
|
void func();
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
2018-06-07 14:55:59 +08:00
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "::"), ElementsAre(QName("func"), QName("ns")));
|
2018-06-07 14:55:59 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 17:52:58 +08:00
|
|
|
TEST(WorkspaceSymbols, RankingPartialNamespace) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
|
|
|
namespace ns1 {
|
|
|
|
namespace ns2 { struct Foo {}; }
|
|
|
|
}
|
|
|
|
namespace ns2 { struct FooB {}; })cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU, "ns2::f"),
|
|
|
|
ElementsAre(QName("ns2::FooB"), QName("ns1::ns2::Foo")));
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, WithLimit) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
[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
|
|
|
int foo;
|
|
|
|
int foo2;
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
[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
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2018-06-07 14:55:59 +08:00
|
|
|
// Foo is higher ranked because of exact name match.
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "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
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU, "foo", 1), 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
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(WorkspaceSymbols, TempSpecs) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.ExtraArgs = {"-xc++"};
|
|
|
|
TU.Code = R"cpp(
|
2019-04-12 18:09:37 +08:00
|
|
|
template <typename T, typename U, int X = 5> class Foo {};
|
|
|
|
template <typename T> class Foo<int, T> {};
|
|
|
|
template <> class Foo<bool, int> {};
|
|
|
|
template <> class Foo<bool, int, 3> {};
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2019-04-12 18:09:37 +08:00
|
|
|
// Foo is higher ranked because of exact name match.
|
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU, "Foo"),
|
2019-04-12 18:09:37 +08:00
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
|
|
|
|
AllOf(QName("Foo<int, T>"), WithKind(SymbolKind::Class)),
|
|
|
|
AllOf(QName("Foo<bool, int>"), WithKind(SymbolKind::Class)),
|
|
|
|
AllOf(QName("Foo<bool, int, 3>"), WithKind(SymbolKind::Class))));
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
std::vector<DocumentSymbol> getSymbols(ParsedAST AST) {
|
|
|
|
auto SymbolInfos = getDocumentSymbols(AST);
|
|
|
|
EXPECT_TRUE(bool(SymbolInfos)) << "documentSymbols returned an error";
|
|
|
|
return *SymbolInfos;
|
|
|
|
}
|
2018-07-06 03:35:01 +08:00
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, BasicSymbols) {
|
|
|
|
TestTU TU;
|
2018-07-06 03:35:01 +08:00
|
|
|
Annotations Main(R"(
|
|
|
|
class Foo;
|
|
|
|
class Foo {
|
|
|
|
Foo() {}
|
|
|
|
Foo(int a) {}
|
|
|
|
void $decl[[f]]();
|
|
|
|
friend void f1();
|
|
|
|
friend class Friend;
|
|
|
|
Foo& operator=(const Foo&);
|
|
|
|
~Foo();
|
|
|
|
class Nested {
|
|
|
|
void f();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
class Friend {
|
|
|
|
};
|
|
|
|
|
|
|
|
void f1();
|
|
|
|
inline void f2() {}
|
|
|
|
static const int KInt = 2;
|
|
|
|
const char* kStr = "123";
|
|
|
|
|
|
|
|
void f1() {}
|
|
|
|
|
|
|
|
namespace foo {
|
|
|
|
// Type alias
|
|
|
|
typedef int int32;
|
|
|
|
using int32_t = int32;
|
|
|
|
|
|
|
|
// Variable
|
|
|
|
int v1;
|
|
|
|
|
|
|
|
// Namespace
|
|
|
|
namespace bar {
|
|
|
|
int v2;
|
|
|
|
}
|
|
|
|
// Namespace alias
|
|
|
|
namespace baz = bar;
|
|
|
|
|
|
|
|
using bar::v2;
|
|
|
|
} // namespace foo
|
|
|
|
)");
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TU.Code = Main.code().str();
|
2018-11-23 23:21:19 +08:00
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU.build()),
|
2018-11-23 23:21:19 +08:00
|
|
|
ElementsAreArray(
|
2021-02-18 23:34:06 +08:00
|
|
|
{AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("class"), Children()),
|
2018-11-23 23:21:19 +08:00
|
|
|
AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("class"),
|
|
|
|
Children(
|
|
|
|
AllOf(WithName("Foo"), WithKind(SymbolKind::Constructor),
|
|
|
|
WithDetail("()"), Children()),
|
|
|
|
AllOf(WithName("Foo"), WithKind(SymbolKind::Constructor),
|
|
|
|
WithDetail("(int)"), Children()),
|
|
|
|
AllOf(WithName("f"), WithKind(SymbolKind::Method),
|
|
|
|
WithDetail("void ()"), Children()),
|
|
|
|
AllOf(WithName("operator="), WithKind(SymbolKind::Method),
|
|
|
|
WithDetail("Foo &(const Foo &)"), Children()),
|
|
|
|
AllOf(WithName("~Foo"), WithKind(SymbolKind::Constructor),
|
|
|
|
WithDetail(""), Children()),
|
|
|
|
AllOf(WithName("Nested"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("class"),
|
|
|
|
Children(AllOf(
|
|
|
|
WithName("f"), WithKind(SymbolKind::Method),
|
|
|
|
WithDetail("void ()"), Children()))))),
|
|
|
|
AllOf(WithName("Friend"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("class"), Children()),
|
|
|
|
AllOf(WithName("f1"), WithKind(SymbolKind::Function),
|
|
|
|
WithDetail("void ()"), Children()),
|
|
|
|
AllOf(WithName("f2"), WithKind(SymbolKind::Function),
|
|
|
|
WithDetail("void ()"), Children()),
|
|
|
|
AllOf(WithName("KInt"), WithKind(SymbolKind::Variable),
|
|
|
|
WithDetail("const int"), Children()),
|
|
|
|
AllOf(WithName("kStr"), WithKind(SymbolKind::Variable),
|
|
|
|
WithDetail("const char *"), Children()),
|
|
|
|
AllOf(WithName("f1"), WithKind(SymbolKind::Function),
|
|
|
|
WithDetail("void ()"), Children()),
|
2019-08-14 20:51:04 +08:00
|
|
|
AllOf(
|
2021-02-18 23:34:06 +08:00
|
|
|
WithName("foo"), WithKind(SymbolKind::Namespace), WithDetail(""),
|
|
|
|
Children(AllOf(WithName("int32"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("type alias"), Children()),
|
|
|
|
AllOf(WithName("int32_t"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("type alias"), Children()),
|
|
|
|
AllOf(WithName("v1"), WithKind(SymbolKind::Variable),
|
|
|
|
WithDetail("int"), Children()),
|
|
|
|
AllOf(WithName("bar"), WithKind(SymbolKind::Namespace),
|
|
|
|
WithDetail(""),
|
|
|
|
Children(AllOf(WithName("v2"),
|
|
|
|
WithKind(SymbolKind::Variable),
|
|
|
|
WithDetail("int"), Children()))),
|
|
|
|
AllOf(WithName("baz"), WithKind(SymbolKind::Namespace),
|
|
|
|
WithDetail(""), Children()),
|
|
|
|
AllOf(WithName("v2"), WithKind(SymbolKind::Namespace),
|
|
|
|
WithDetail(""))))}));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, DeclarationDefinition) {
|
|
|
|
TestTU TU;
|
2018-07-06 03:35:01 +08:00
|
|
|
Annotations Main(R"(
|
|
|
|
class Foo {
|
|
|
|
void $decl[[f]]();
|
|
|
|
};
|
|
|
|
void Foo::$def[[f]]() {
|
|
|
|
}
|
|
|
|
)");
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TU.Code = Main.code().str();
|
2019-08-14 20:51:04 +08:00
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU.build()),
|
2019-08-14 20:51:04 +08:00
|
|
|
ElementsAre(
|
|
|
|
AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("class"),
|
2019-08-14 20:51:04 +08:00
|
|
|
Children(AllOf(WithName("f"), WithKind(SymbolKind::Method),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("void ()"),
|
2019-08-14 20:51:04 +08:00
|
|
|
SymNameRange(Main.range("decl"))))),
|
|
|
|
AllOf(WithName("Foo::f"), WithKind(SymbolKind::Method),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("void ()"), SymNameRange(Main.range("def")))));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, Concepts) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.ExtraArgs = {"-std=c++20"};
|
|
|
|
TU.Code = "template <typename T> concept C = requires(T t) { t.foo(); };";
|
2020-01-21 02:02:48 +08:00
|
|
|
|
2021-02-18 23:34:06 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
|
|
|
ElementsAre(AllOf(WithName("C"), WithDetail("concept"))));
|
2020-01-21 02:02:48 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, ExternSymbol) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["foo.h"] = R"cpp(
|
2018-12-21 17:32:49 +08:00
|
|
|
extern int var;
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
2018-07-06 03:35:01 +08:00
|
|
|
#include "foo.h"
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2018-07-06 03:35:01 +08:00
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()), IsEmpty());
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-08-03 17:34:14 +08:00
|
|
|
TEST(DocumentSymbols, ExternContext) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
|
|
|
extern "C" {
|
|
|
|
void foo();
|
|
|
|
class Foo {};
|
|
|
|
}
|
|
|
|
namespace ns {
|
|
|
|
extern "C" {
|
|
|
|
void bar();
|
|
|
|
class Bar {};
|
|
|
|
}
|
|
|
|
})cpp";
|
|
|
|
|
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
|
|
|
ElementsAre(WithName("foo"), WithName("Foo"),
|
|
|
|
AllOf(WithName("ns"),
|
|
|
|
Children(WithName("bar"), WithName("Bar")))));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DocumentSymbols, ExportContext) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.ExtraArgs = {"-std=c++20"};
|
|
|
|
TU.Code = R"cpp(
|
|
|
|
export module test;
|
|
|
|
export {
|
|
|
|
void foo();
|
|
|
|
class Foo {};
|
|
|
|
})cpp";
|
|
|
|
|
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
|
|
|
ElementsAre(WithName("foo"), WithName("Foo")));
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, NoLocals) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2018-07-06 03:35:01 +08:00
|
|
|
void test(int FirstParam, int SecondParam) {
|
|
|
|
struct LocalClass {};
|
|
|
|
int local_var;
|
2020-07-01 18:16:54 +08:00
|
|
|
})cpp";
|
|
|
|
EXPECT_THAT(getSymbols(TU.build()), ElementsAre(WithName("test")));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, Unnamed) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2018-07-06 03:35:01 +08:00
|
|
|
struct {
|
|
|
|
int InUnnamed;
|
|
|
|
} UnnamedStruct;
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2018-07-06 03:35:01 +08:00
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU.build()),
|
2021-02-18 23:34:06 +08:00
|
|
|
ElementsAre(AllOf(WithName("(anonymous struct)"),
|
|
|
|
WithKind(SymbolKind::Struct), WithDetail("struct"),
|
|
|
|
Children(AllOf(WithName("InUnnamed"),
|
|
|
|
WithKind(SymbolKind::Field),
|
|
|
|
WithDetail("int"), Children()))),
|
|
|
|
AllOf(WithName("UnnamedStruct"),
|
|
|
|
WithKind(SymbolKind::Variable),
|
2021-02-23 01:58:26 +08:00
|
|
|
WithDetail("struct (unnamed)"), Children())));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, InHeaderFile) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.AdditionalFiles["bar.h"] = R"cpp(
|
2018-07-06 03:35:01 +08:00
|
|
|
int foo() {
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
|
|
|
TU.Code = R"cpp(
|
2021-01-15 15:47:28 +08:00
|
|
|
int i; // declaration to finish preamble
|
2018-07-06 03:35:01 +08:00
|
|
|
#include "bar.h"
|
|
|
|
int test() {
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2021-01-15 15:47:28 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
|
|
|
ElementsAre(WithName("i"), WithName("test")));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, Template) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"(
|
2018-07-06 03:35:01 +08:00
|
|
|
template <class T> struct Tmpl {T x = 0;};
|
2018-11-23 23:21:19 +08:00
|
|
|
template <> struct Tmpl<int> {
|
|
|
|
int y = 0;
|
|
|
|
};
|
2018-07-06 03:35:01 +08:00
|
|
|
extern template struct Tmpl<float>;
|
|
|
|
template struct Tmpl<double>;
|
2018-11-23 23:21:19 +08:00
|
|
|
|
|
|
|
template <class T, class U, class Z = float>
|
|
|
|
int funcTmpl(U a);
|
|
|
|
template <>
|
|
|
|
int funcTmpl<int>(double a);
|
|
|
|
|
|
|
|
template <class T, class U = double>
|
|
|
|
int varTmpl = T();
|
|
|
|
template <>
|
|
|
|
double varTmpl<int> = 10.0;
|
2020-07-01 18:16:54 +08:00
|
|
|
)";
|
2018-11-23 23:21:19 +08:00
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU.build()),
|
2018-11-23 23:21:19 +08:00
|
|
|
ElementsAre(
|
|
|
|
AllOf(WithName("Tmpl"), WithKind(SymbolKind::Struct),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("template struct"),
|
|
|
|
Children(AllOf(WithName("x"), WithKind(SymbolKind::Field),
|
|
|
|
WithDetail("T")))),
|
2018-11-23 23:21:19 +08:00
|
|
|
AllOf(WithName("Tmpl<int>"), WithKind(SymbolKind::Struct),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("struct"),
|
|
|
|
Children(AllOf(WithName("y"), WithDetail("int")))),
|
2018-11-23 23:21:19 +08:00
|
|
|
AllOf(WithName("Tmpl<float>"), WithKind(SymbolKind::Struct),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("struct"), Children()),
|
2018-11-23 23:21:19 +08:00
|
|
|
AllOf(WithName("Tmpl<double>"), WithKind(SymbolKind::Struct),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("struct"), Children()),
|
|
|
|
AllOf(WithName("funcTmpl"), WithDetail("template int (U)"),
|
|
|
|
Children()),
|
|
|
|
AllOf(WithName("funcTmpl<int>"), WithDetail("int (double)"),
|
2018-11-23 23:21:19 +08:00
|
|
|
Children()),
|
2021-02-18 23:34:06 +08:00
|
|
|
AllOf(WithName("varTmpl"), WithDetail("template int"), Children()),
|
|
|
|
AllOf(WithName("varTmpl<int>"), WithDetail("double"), Children())));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, Namespaces) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2018-07-06 03:35:01 +08:00
|
|
|
namespace ans1 {
|
|
|
|
int ai1;
|
|
|
|
namespace ans2 {
|
|
|
|
int ai2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace {
|
|
|
|
void test() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace na {
|
|
|
|
inline namespace nb {
|
|
|
|
class Foo {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
namespace na {
|
|
|
|
// This is still inlined.
|
|
|
|
namespace nb {
|
|
|
|
class Bar {};
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2018-07-06 03:35:01 +08:00
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU.build()),
|
2019-05-06 18:08:47 +08:00
|
|
|
ElementsAreArray<::testing::Matcher<DocumentSymbol>>(
|
2018-11-23 23:21:19 +08:00
|
|
|
{AllOf(WithName("ans1"),
|
|
|
|
Children(AllOf(WithName("ai1"), Children()),
|
|
|
|
AllOf(WithName("ans2"), Children(WithName("ai2"))))),
|
|
|
|
AllOf(WithName("(anonymous namespace)"), Children(WithName("test"))),
|
|
|
|
AllOf(WithName("na"),
|
|
|
|
Children(AllOf(WithName("nb"), Children(WithName("Foo"))))),
|
|
|
|
AllOf(WithName("na"),
|
|
|
|
Children(AllOf(WithName("nb"), Children(WithName("Bar")))))}));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, Enums) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"(
|
2018-07-06 03:35:01 +08:00
|
|
|
enum {
|
|
|
|
Red
|
|
|
|
};
|
|
|
|
enum Color {
|
|
|
|
Green
|
|
|
|
};
|
|
|
|
enum class Color2 {
|
|
|
|
Yellow
|
|
|
|
};
|
|
|
|
namespace ns {
|
|
|
|
enum {
|
|
|
|
Black
|
|
|
|
};
|
|
|
|
}
|
2020-07-01 18:16:54 +08:00
|
|
|
)";
|
2018-11-23 23:21:19 +08:00
|
|
|
EXPECT_THAT(
|
2020-07-01 18:16:54 +08:00
|
|
|
getSymbols(TU.build()),
|
2018-11-23 23:21:19 +08:00
|
|
|
ElementsAre(
|
2021-02-23 01:58:26 +08:00
|
|
|
AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
|
|
|
|
Children(AllOf(WithName("Red"), WithDetail("(unnamed)")))),
|
2021-02-18 23:34:06 +08:00
|
|
|
AllOf(WithName("Color"), WithDetail("enum"),
|
|
|
|
Children(AllOf(WithName("Green"), WithDetail("Color")))),
|
|
|
|
AllOf(WithName("Color2"), WithDetail("enum"),
|
|
|
|
Children(AllOf(WithName("Yellow"), WithDetail("Color2")))),
|
|
|
|
AllOf(WithName("ns"),
|
|
|
|
Children(AllOf(WithName("(anonymous enum)"), WithDetail("enum"),
|
|
|
|
Children(AllOf(WithName("Black"),
|
2021-02-23 01:58:26 +08:00
|
|
|
WithDetail("(unnamed)"))))))));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2021-02-26 16:11:48 +08:00
|
|
|
TEST(DocumentSymbols, Macro) {
|
|
|
|
struct Test {
|
|
|
|
const char *Code;
|
|
|
|
testing::Matcher<DocumentSymbol> Matcher;
|
|
|
|
} Tests[] = {
|
|
|
|
{
|
|
|
|
R"cpp(
|
|
|
|
// Basic macro that generates symbols.
|
|
|
|
#define DEFINE_FLAG(X) bool FLAGS_##X; bool FLAGS_no##X
|
|
|
|
DEFINE_FLAG(pretty);
|
|
|
|
)cpp",
|
|
|
|
AllOf(WithName("DEFINE_FLAG"), WithDetail("(pretty)"),
|
|
|
|
Children(WithName("FLAGS_pretty"), WithName("FLAGS_nopretty"))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
R"cpp(
|
|
|
|
// Hierarchy is determined by primary (name) location.
|
|
|
|
#define ID(X) X
|
|
|
|
namespace ID(ns) { int ID(y); }
|
|
|
|
)cpp",
|
|
|
|
AllOf(WithName("ID"), WithDetail("(ns)"),
|
|
|
|
Children(AllOf(WithName("ns"),
|
|
|
|
Children(AllOf(WithName("ID"), WithDetail("(y)"),
|
|
|
|
Children(WithName("y"))))))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
R"cpp(
|
|
|
|
// More typical example where macro only generates part of a decl.
|
|
|
|
#define TEST(A, B) class A##_##B { void go(); }; void A##_##B::go()
|
|
|
|
TEST(DocumentSymbols, Macro) { }
|
|
|
|
)cpp",
|
|
|
|
AllOf(WithName("TEST"), WithDetail("(DocumentSymbols, Macro)"),
|
|
|
|
Children(AllOf(WithName("DocumentSymbols_Macro"),
|
|
|
|
Children(WithName("go"))),
|
|
|
|
WithName("DocumentSymbols_Macro::go"))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
R"cpp(
|
|
|
|
// Nested macros.
|
|
|
|
#define NAMESPACE(NS, BODY) namespace NS { BODY }
|
|
|
|
NAMESPACE(a, NAMESPACE(b, int x;))
|
|
|
|
)cpp",
|
|
|
|
AllOf(
|
|
|
|
WithName("NAMESPACE"), WithDetail("(a, NAMESPACE(b, int x;))"),
|
|
|
|
Children(AllOf(
|
|
|
|
WithName("a"),
|
|
|
|
Children(AllOf(WithName("NAMESPACE"),
|
|
|
|
// FIXME: nested expansions not in TokenBuffer
|
|
|
|
WithDetail(""),
|
|
|
|
Children(AllOf(WithName("b"),
|
|
|
|
Children(WithName("x"))))))))),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
R"cpp(
|
|
|
|
// Macro invoked from body is not exposed.
|
|
|
|
#define INNER(X) int X
|
|
|
|
#define OUTER(X) INNER(X)
|
|
|
|
OUTER(foo);
|
|
|
|
)cpp",
|
|
|
|
AllOf(WithName("OUTER"), WithDetail("(foo)"),
|
|
|
|
Children(WithName("foo"))),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
for (const Test &T : Tests) {
|
|
|
|
auto TU = TestTU::withCode(T.Code);
|
|
|
|
EXPECT_THAT(getSymbols(TU.build()), ElementsAre(T.Matcher)) << T.Code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DocumentSymbols, RangeFromMacro) {
|
2020-07-01 18:16:54 +08:00
|
|
|
TestTU TU;
|
2018-07-06 03:35:01 +08:00
|
|
|
Annotations Main(R"(
|
|
|
|
#define FF(name) \
|
|
|
|
class name##_Test {};
|
|
|
|
|
2020-09-22 14:30:21 +08:00
|
|
|
$expansion1[[FF]](abc);
|
2018-07-06 03:35:01 +08:00
|
|
|
|
|
|
|
#define FF2() \
|
2021-02-26 16:11:48 +08:00
|
|
|
class Test {}
|
2018-07-06 03:35:01 +08:00
|
|
|
|
2021-02-26 16:11:48 +08:00
|
|
|
$expansion2parens[[$expansion2[[FF2]]()]];
|
2020-09-22 14:30:21 +08:00
|
|
|
|
|
|
|
#define FF3() \
|
|
|
|
void waldo()
|
|
|
|
|
|
|
|
$fullDef[[FF3() {
|
|
|
|
int var = 42;
|
|
|
|
}]]
|
2018-07-06 03:35:01 +08:00
|
|
|
)");
|
2020-07-01 18:16:54 +08:00
|
|
|
TU.Code = Main.code().str();
|
2021-02-26 16:11:48 +08:00
|
|
|
EXPECT_THAT(
|
|
|
|
getSymbols(TU.build()),
|
|
|
|
ElementsAre(
|
|
|
|
AllOf(WithName("FF"), WithDetail("(abc)"),
|
|
|
|
Children(AllOf(WithName("abc_Test"), WithDetail("class"),
|
|
|
|
SymNameRange(Main.range("expansion1"))))),
|
|
|
|
AllOf(WithName("FF2"), WithDetail("()"),
|
|
|
|
SymNameRange(Main.range("expansion2")),
|
|
|
|
SymRange(Main.range("expansion2parens")),
|
|
|
|
Children(AllOf(WithName("Test"), WithDetail("class"),
|
|
|
|
SymNameRange(Main.range("expansion2"))))),
|
|
|
|
AllOf(WithName("FF3"), WithDetail("()"),
|
|
|
|
SymRange(Main.range("fullDef")),
|
|
|
|
Children(AllOf(WithName("waldo"), WithDetail("void ()"),
|
|
|
|
SymRange(Main.range("fullDef")))))));
|
2018-11-23 23:21:19 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, FuncTemplates) {
|
|
|
|
TestTU TU;
|
2018-11-23 23:21:19 +08:00
|
|
|
Annotations Source(R"cpp(
|
|
|
|
template <class T>
|
|
|
|
T foo() {}
|
|
|
|
|
|
|
|
auto x = foo<int>();
|
2020-07-01 18:16:54 +08:00
|
|
|
auto y = foo<double>();
|
2018-11-23 23:21:19 +08:00
|
|
|
)cpp");
|
2020-07-01 18:16:54 +08:00
|
|
|
TU.Code = Source.code().str();
|
2018-11-23 23:21:19 +08:00
|
|
|
// Make sure we only see the template declaration, not instantiations.
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
2021-02-18 23:34:06 +08:00
|
|
|
ElementsAre(AllOf(WithName("foo"), WithDetail("template T ()")),
|
|
|
|
AllOf(WithName("x"), WithDetail("int")),
|
|
|
|
AllOf(WithName("y"), WithDetail("double"))));
|
2018-11-23 23:21:19 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, UsingDirectives) {
|
|
|
|
TestTU TU;
|
2018-11-23 23:21:19 +08:00
|
|
|
Annotations Source(R"cpp(
|
|
|
|
namespace ns {
|
|
|
|
int foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace ns_alias = ns;
|
|
|
|
|
|
|
|
using namespace ::ns; // check we don't loose qualifiers.
|
|
|
|
using namespace ns_alias; // and namespace aliases.
|
|
|
|
)cpp");
|
2020-07-01 18:16:54 +08:00
|
|
|
TU.Code = Source.code().str();
|
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
2018-11-23 23:21:19 +08:00
|
|
|
ElementsAre(WithName("ns"), WithName("ns_alias"),
|
|
|
|
WithName("using namespace ::ns"),
|
|
|
|
WithName("using namespace ns_alias")));
|
2018-07-06 03:35:01 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, TempSpecs) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2019-04-12 18:09:37 +08:00
|
|
|
template <typename T, typename U, int X = 5> class Foo {};
|
|
|
|
template <typename T> class Foo<int, T> {};
|
|
|
|
template <> class Foo<bool, int> {};
|
|
|
|
template <> class Foo<bool, int, 3> {};
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2019-04-12 18:09:37 +08:00
|
|
|
// Foo is higher ranked because of exact name match.
|
2021-02-18 23:34:06 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(WithName("Foo"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("template class")),
|
|
|
|
AllOf(WithName("Foo<int, T>"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("template class")),
|
|
|
|
AllOf(WithName("Foo<bool, int>"), WithKind(SymbolKind::Class),
|
|
|
|
WithDetail("class")),
|
|
|
|
AllOf(WithName("Foo<bool, int, 3>"),
|
|
|
|
WithKind(SymbolKind::Class), WithDetail("class"))));
|
2019-04-12 18:09:37 +08:00
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, Qualifiers) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2019-08-14 20:51:04 +08:00
|
|
|
namespace foo { namespace bar {
|
|
|
|
struct Cls;
|
|
|
|
|
|
|
|
int func1();
|
|
|
|
int func2();
|
|
|
|
int func3();
|
|
|
|
int func4();
|
|
|
|
}}
|
|
|
|
|
|
|
|
struct foo::bar::Cls { };
|
|
|
|
|
|
|
|
int foo::bar::func1() { return 10; }
|
|
|
|
int ::foo::bar::func2() { return 20; }
|
|
|
|
|
|
|
|
using namespace foo;
|
|
|
|
int bar::func3() { return 30; }
|
|
|
|
|
|
|
|
namespace alias = foo::bar;
|
|
|
|
int ::alias::func4() { return 40; }
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2019-08-14 20:51:04 +08:00
|
|
|
|
|
|
|
// All the qualifiers should be preserved exactly as written.
|
2020-07-01 18:16:54 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
2019-08-14 20:51:04 +08:00
|
|
|
UnorderedElementsAre(
|
|
|
|
WithName("foo"), WithName("foo::bar::Cls"),
|
|
|
|
WithName("foo::bar::func1"), WithName("::foo::bar::func2"),
|
|
|
|
WithName("using namespace foo"), WithName("bar::func3"),
|
|
|
|
WithName("alias"), WithName("::alias::func4")));
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
TEST(DocumentSymbols, QualifiersWithTemplateArgs) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"cpp(
|
2019-08-14 20:51:04 +08:00
|
|
|
template <typename T, typename U = double> class Foo;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class Foo<int, double> {
|
|
|
|
int method1();
|
|
|
|
int method2();
|
|
|
|
int method3();
|
|
|
|
};
|
|
|
|
|
|
|
|
using int_type = int;
|
|
|
|
|
|
|
|
// Typedefs should be preserved!
|
|
|
|
int Foo<int_type, double>::method1() { return 10; }
|
|
|
|
|
|
|
|
// Default arguments should not be shown!
|
|
|
|
int Foo<int>::method2() { return 20; }
|
|
|
|
|
|
|
|
using Foo_type = Foo<int>;
|
|
|
|
// If the whole type is aliased, this should be preserved too!
|
|
|
|
int Foo_type::method3() { return 30; }
|
2020-07-01 18:16:54 +08:00
|
|
|
)cpp";
|
2021-02-18 23:34:06 +08:00
|
|
|
EXPECT_THAT(getSymbols(TU.build()),
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(WithName("Foo"), WithDetail("template class")),
|
|
|
|
AllOf(WithName("Foo<int, double>"), WithDetail("class")),
|
|
|
|
AllOf(WithName("int_type"), WithDetail("type alias")),
|
|
|
|
AllOf(WithName("Foo<int_type, double>::method1"),
|
|
|
|
WithDetail("int ()")),
|
|
|
|
AllOf(WithName("Foo<int>::method2"), WithDetail("int ()")),
|
|
|
|
AllOf(WithName("Foo_type"), WithDetail("type alias")),
|
|
|
|
AllOf(WithName("Foo_type::method3"), WithDetail("int ()"))));
|
2019-08-14 20:51:04 +08:00
|
|
|
}
|
|
|
|
|
2020-07-13 21:02:47 +08:00
|
|
|
TEST(DocumentSymbolsTest, Ranges) {
|
|
|
|
TestTU TU;
|
|
|
|
Annotations Main(R"(
|
|
|
|
$foo[[int foo(bool Argument) {
|
|
|
|
return 42;
|
|
|
|
}]]
|
|
|
|
|
|
|
|
$variable[[char GLOBAL_VARIABLE]];
|
|
|
|
|
|
|
|
$ns[[namespace ns {
|
|
|
|
$bar[[class Bar {
|
|
|
|
public:
|
|
|
|
$ctor[[Bar() {}]]
|
|
|
|
$dtor[[~Bar()]];
|
|
|
|
|
|
|
|
private:
|
|
|
|
$field[[unsigned Baz]];
|
|
|
|
|
|
|
|
$getbaz[[unsigned getBaz() { return Baz; }]]
|
|
|
|
}]];
|
|
|
|
}]] // namespace ns
|
|
|
|
|
|
|
|
$forwardclass[[class ForwardClassDecl]];
|
|
|
|
|
|
|
|
$struct[[struct StructDefinition {
|
|
|
|
$structfield[[int *Pointer = nullptr]];
|
|
|
|
}]];
|
|
|
|
$forwardstruct[[struct StructDeclaration]];
|
|
|
|
|
|
|
|
$forwardfunc[[void forwardFunctionDecl(int Something)]];
|
|
|
|
)");
|
|
|
|
TU.Code = Main.code().str();
|
|
|
|
EXPECT_THAT(
|
|
|
|
getSymbols(TU.build()),
|
|
|
|
UnorderedElementsAre(
|
|
|
|
AllOf(WithName("foo"), WithKind(SymbolKind::Function),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("int (bool)"), SymRange(Main.range("foo"))),
|
2020-07-13 21:02:47 +08:00
|
|
|
AllOf(WithName("GLOBAL_VARIABLE"), WithKind(SymbolKind::Variable),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("char"), SymRange(Main.range("variable"))),
|
2020-07-13 21:02:47 +08:00
|
|
|
AllOf(
|
|
|
|
WithName("ns"), WithKind(SymbolKind::Namespace),
|
|
|
|
SymRange(Main.range("ns")),
|
|
|
|
Children(AllOf(
|
|
|
|
WithName("Bar"), WithKind(SymbolKind::Class),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("class"), SymRange(Main.range("bar")),
|
2020-07-13 21:02:47 +08:00
|
|
|
Children(
|
|
|
|
AllOf(WithName("Bar"), WithKind(SymbolKind::Constructor),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("()"), SymRange(Main.range("ctor"))),
|
2020-07-13 21:02:47 +08:00
|
|
|
AllOf(WithName("~Bar"), WithKind(SymbolKind::Constructor),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail(""), SymRange(Main.range("dtor"))),
|
2020-07-13 21:02:47 +08:00
|
|
|
AllOf(WithName("Baz"), WithKind(SymbolKind::Field),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("unsigned int"),
|
2020-07-13 21:02:47 +08:00
|
|
|
SymRange(Main.range("field"))),
|
|
|
|
AllOf(WithName("getBaz"), WithKind(SymbolKind::Method),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("unsigned int ()"),
|
2020-07-13 21:02:47 +08:00
|
|
|
SymRange(Main.range("getbaz"))))))),
|
|
|
|
AllOf(WithName("ForwardClassDecl"), WithKind(SymbolKind::Class),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("class"), SymRange(Main.range("forwardclass"))),
|
2020-07-13 21:02:47 +08:00
|
|
|
AllOf(WithName("StructDefinition"), WithKind(SymbolKind::Struct),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("struct"), SymRange(Main.range("struct")),
|
2020-07-13 21:02:47 +08:00
|
|
|
Children(AllOf(WithName("Pointer"), WithKind(SymbolKind::Field),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("int *"),
|
2020-07-13 21:02:47 +08:00
|
|
|
SymRange(Main.range("structfield"))))),
|
|
|
|
AllOf(WithName("StructDeclaration"), WithKind(SymbolKind::Struct),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("struct"), SymRange(Main.range("forwardstruct"))),
|
2020-07-13 21:02:47 +08:00
|
|
|
AllOf(WithName("forwardFunctionDecl"), WithKind(SymbolKind::Function),
|
2021-02-18 23:34:06 +08:00
|
|
|
WithDetail("void (int)"),
|
2020-07-13 21:02:47 +08:00
|
|
|
SymRange(Main.range("forwardfunc")))));
|
|
|
|
}
|
|
|
|
|
2021-02-18 23:34:06 +08:00
|
|
|
TEST(DocumentSymbolsTest, DependentType) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.Code = R"(
|
|
|
|
template <typename T> auto plus(T x, T y) -> decltype(x + y) { return x + y; }
|
|
|
|
|
|
|
|
template <typename Key, typename Value> class Pair {};
|
|
|
|
|
|
|
|
template <typename Key, typename Value>
|
|
|
|
struct Context : public Pair<Key, Value> {
|
|
|
|
using Pair<Key, Value>::Pair;
|
|
|
|
};
|
|
|
|
)";
|
|
|
|
EXPECT_THAT(
|
|
|
|
getSymbols(TU.build()),
|
|
|
|
ElementsAre(
|
|
|
|
AllOf(WithName("plus"),
|
|
|
|
WithDetail("template auto (T, T) -> decltype(x + y)")),
|
|
|
|
AllOf(WithName("Pair"), WithDetail("template class")),
|
|
|
|
AllOf(WithName("Context"), WithDetail("template struct"),
|
|
|
|
Children(AllOf(
|
|
|
|
WithName("Pair<type-parameter-0-0, type-parameter-0-1>"),
|
|
|
|
WithDetail("<dependent type>"))))));
|
|
|
|
}
|
|
|
|
|
2021-02-13 00:52:43 +08:00
|
|
|
TEST(DocumentSymbolsTest, ObjCCategoriesAndClassExtensions) {
|
|
|
|
TestTU TU;
|
|
|
|
TU.ExtraArgs = {"-xobjective-c++", "-Wno-objc-root-class"};
|
|
|
|
Annotations Main(R"cpp(
|
|
|
|
$Cat[[@interface Cat
|
|
|
|
+ (id)sharedCat;
|
|
|
|
@end]]
|
|
|
|
$SneakyCat[[@interface Cat (Sneaky)
|
|
|
|
- (id)sneak:(id)behavior;
|
|
|
|
@end]]
|
|
|
|
|
|
|
|
$MeowCat[[@interface Cat ()
|
|
|
|
- (void)meow;
|
|
|
|
@end]]
|
|
|
|
$PurCat[[@interface Cat ()
|
|
|
|
- (void)pur;
|
|
|
|
@end]]
|
|
|
|
)cpp");
|
|
|
|
TU.Code = Main.code().str();
|
|
|
|
EXPECT_THAT(
|
|
|
|
getSymbols(TU.build()),
|
|
|
|
ElementsAre(
|
|
|
|
AllOf(WithName("Cat"), SymRange(Main.range("Cat")),
|
|
|
|
Children(AllOf(WithName("+sharedCat"),
|
|
|
|
WithKind(SymbolKind::Method)))),
|
|
|
|
AllOf(WithName("Cat(Sneaky)"), SymRange(Main.range("SneakyCat")),
|
|
|
|
Children(
|
|
|
|
AllOf(WithName("-sneak:"), WithKind(SymbolKind::Method)))),
|
|
|
|
AllOf(
|
|
|
|
WithName("Cat()"), SymRange(Main.range("MeowCat")),
|
|
|
|
Children(AllOf(WithName("-meow"), WithKind(SymbolKind::Method)))),
|
|
|
|
AllOf(WithName("Cat()"), SymRange(Main.range("PurCat")),
|
|
|
|
Children(
|
|
|
|
AllOf(WithName("-pur"), WithKind(SymbolKind::Method))))));
|
|
|
|
}
|
|
|
|
|
2020-07-01 18:16:54 +08:00
|
|
|
} // 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
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|