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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#include "name_mapping.h"
#include <yql/essentials/sql/v1/complete/syntax/format.h>
namespace NSQLComplete {
TCandidate ToCandidate(TKeyword name, TLocalSyntaxContext& context) {
TVector<TString>& seq = context.Keywords[name.Content];
seq.insert(std::begin(seq), name.Content);
TCandidate candidate = {
.Kind = ECandidateKind::Keyword,
.Content = FormatKeywords(seq),
};
if (candidate.Content.EndsWith('(')) {
candidate.Content += ')';
candidate.CursorShift = 1;
}
return candidate;
}
TCandidate ToCandidate(TPragmaName name) {
return {ECandidateKind::PragmaName, std::move(name.Indentifier)};
}
TCandidate ToCandidate(TTypeName name) {
TCandidate candidate = {
.Kind = ECandidateKind::TypeName,
.Content = std::move(name.Indentifier),
};
switch (name.Kind) {
case TTypeName::EKind::Simple: {
} break;
case TTypeName::EKind::Container: {
candidate.Content += "<>";
candidate.CursorShift = 1;
} break;
case TTypeName::EKind::Parameterized: {
candidate.Content += "()";
candidate.CursorShift = 1;
} break;
}
return candidate;
}
TCandidate ToCandidate(TFunctionName name) {
TCandidate candidate = {
.Kind = ECandidateKind::FunctionName,
.Content = std::move(name.Indentifier),
};
candidate.Content += "()";
candidate.CursorShift = 1;
return candidate;
}
TCandidate ToCandidate(THintName name) {
return {ECandidateKind::HintName, std::move(name.Indentifier)};
}
TCandidate ToCandidate(TFolderName name, TLocalSyntaxContext& context) {
TCandidate candidate = {
.Kind = ECandidateKind::FolderName,
.Content = std::move(name.Indentifier),
};
if (!context.IsQuoted.AtLhs) {
candidate.Content.prepend('`');
}
candidate.Content.append('/');
if (!context.IsQuoted.AtRhs) {
candidate.Content.append('`');
candidate.CursorShift = 1;
}
return candidate;
}
TCandidate ToCandidate(TTableName name, TLocalSyntaxContext& context) {
if (!context.IsQuoted.AtLhs) {
name.Indentifier.prepend('`');
}
if (!context.IsQuoted.AtRhs) {
name.Indentifier.append('`');
}
return {ECandidateKind::TableName, std::move(name.Indentifier)};
}
TCandidate ToCandidate(TClusterName name) {
return {ECandidateKind::ClusterName, std::move(name.Indentifier)};
}
TCandidate ToCandidate(TColumnName name, TLocalSyntaxContext& context) {
if (context.Column->Table.empty() && !name.TableAlias.empty()) {
name.Indentifier.prepend('.');
name.Indentifier.prepend(name.TableAlias);
}
return {ECandidateKind::ColumnName, std::move(name.Indentifier)};
}
TCandidate ToCandidate(TBindingName name, TLocalSyntaxContext& context) {
if (!context.Binding) {
name.Indentifier.prepend('$');
}
return {ECandidateKind::BindingName, std::move(name.Indentifier)};
}
TCandidate ToCandidate(TUnknownName name) {
return {ECandidateKind::UnknownName, std::move(name.Content)};
}
TCandidate ToCandidate(TGenericName generic, TLocalSyntaxContext& context) {
return std::visit([&](auto&& name) -> TCandidate {
using T = std::decay_t<decltype(name)>;
constexpr bool IsContextSensitive =
std::is_same_v<T, TKeyword> ||
std::is_same_v<T, TFolderName> ||
std::is_same_v<T, TTableName> ||
std::is_same_v<T, TColumnName> ||
std::is_same_v<T, TBindingName>;
if constexpr (IsContextSensitive) {
return ToCandidate(std::move(name), context);
} else {
return ToCandidate(std::move(name));
}
}, std::move(generic));
}
TVector<TCandidate> ToCandidate(TVector<TGenericName> names, TLocalSyntaxContext context) {
TVector<TCandidate> candidates;
candidates.reserve(names.size());
for (auto& name : names) {
candidates.emplace_back(ToCandidate(std::move(name), context));
}
return candidates;
}
} // namespace NSQLComplete
|