-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathDefinition.cpp
More file actions
96 lines (76 loc) · 1.9 KB
/
Definition.cpp
File metadata and controls
96 lines (76 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "Test/Tester.h"
#include "Feature/Definition.h"
namespace clice::testing {
namespace {
suite<"Definition"> goto_definition = [] {
std::vector<feature::CompletionItem> items;
auto definition = [&](llvm::StringRef code) {
CompilationParams params;
auto annotation = AnnotatedSource::from(code);
params.arguments = {"clang++", "-std=c++20", "main.cpp"};
params.completion = {"main.cpp", annotation.offsets["pos"]};
params.add_remapped_file("main.cpp", annotation.content);
config::DefinitionOption options = {};
items = feature::definition(params, options);
};
using enum feature::CompletionItemKind;
test("Score") = [&] {
definition(R"cpp(
int foooo(int x);
int x = fo$(pos)
)cpp");
expect(that % items.size() == 1);
expect(items.front().label == "foooo");
expect(items.front().kind == Function);
};
test("Snippet") = [&] {
definition(R"cpp(
int x = tru$(pos)
)cpp");
};
test("Overload") = [&] {
definition(R"cpp(
int foooo(int x);
int foooo(int x, int y);
int x = fooo$(pos)
)cpp");
};
test("Unqualified") = [&] {
definition(R"cpp(
namespace A {
void fooooo();
}
void bar() {
fo$(pos)
}
)cpp");
/// EXPECT: "A::fooooo"
/// To implement this we need to search code completion result from index
/// or traverse AST to collect interesting names.
};
test("Functor") = [&] {
definition(R"cpp(
struct X {
void operator() () {}
};
void bar() {
X foo;
fo$(pos);
}
)cpp");
/// TODO:
/// complete lambda as it is a variable.
};
test("Lambda") = [&] {
definition(R"cpp(
void bar() {
auto foo = [](int x){ };
fo$(pos);
}
)cpp");
/// TODO:
/// complete lambda as it is a function.
};
};
} // namespace
} // namespace clice::testing