Skip to content

Commit 8174698

Browse files
committed
YQL-19747: Set cursor shift at completion item
Set `TCandidate::Shift` for functions and generic types. So now brackets are balanced and UI should adopt it. YDB CLI is ready for the update and just cut off symbols after an expected cursor position. commit_hash:9efc1110869af7be618b841c6c132572b61046a1
1 parent 0133b00 commit 8174698

File tree

2 files changed

+158
-116
lines changed

2 files changed

+158
-116
lines changed

yql/essentials/sql/v1/complete/sql_complete.cpp

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,42 +209,80 @@ namespace NSQLComplete {
209209
if constexpr (std::is_base_of_v<TKeyword, T>) {
210210
TVector<TString>& seq = context.Keywords[name.Content];
211211
seq.insert(std::begin(seq), name.Content);
212-
return {ECandidateKind::Keyword, FormatKeywords(seq)};
212+
213+
TCandidate candidate = {
214+
.Kind = ECandidateKind::Keyword,
215+
.Content = FormatKeywords(seq),
216+
};
217+
218+
if (candidate.Content.EndsWith('(')) {
219+
candidate.Content += ')';
220+
candidate.CursorShift = 1;
221+
}
222+
223+
return candidate;
213224
}
214225

215226
if constexpr (std::is_base_of_v<TPragmaName, T>) {
216227
return {ECandidateKind::PragmaName, std::move(name.Indentifier)};
217228
}
218229

219230
if constexpr (std::is_base_of_v<TTypeName, T>) {
231+
TCandidate candidate = {
232+
.Kind = ECandidateKind::TypeName,
233+
.Content = std::move(name.Indentifier),
234+
};
235+
220236
switch (name.Kind) {
221237
case TTypeName::EKind::Simple: {
222238
} break;
223239
case TTypeName::EKind::Container: {
224-
name.Indentifier += "<";
240+
candidate.Content += "<>";
241+
candidate.CursorShift = 1;
225242
} break;
226243
case TTypeName::EKind::Parameterized: {
227-
name.Indentifier += "(";
244+
candidate.Content += "()";
245+
candidate.CursorShift = 1;
228246
} break;
229247
}
230-
return {ECandidateKind::TypeName, std::move(name.Indentifier)};
248+
249+
return candidate;
231250
}
232251

233252
if constexpr (std::is_base_of_v<TFunctionName, T>) {
234-
name.Indentifier += "(";
235-
return {ECandidateKind::FunctionName, std::move(name.Indentifier)};
253+
TCandidate candidate = {
254+
.Kind = ECandidateKind::FunctionName,
255+
.Content = std::move(name.Indentifier),
256+
};
257+
258+
candidate.Content += "()";
259+
candidate.CursorShift = 1;
260+
261+
return candidate;
236262
}
237263

238264
if constexpr (std::is_base_of_v<THintName, T>) {
239265
return {ECandidateKind::HintName, std::move(name.Indentifier)};
240266
}
241267

242268
if constexpr (std::is_base_of_v<TFolderName, T>) {
243-
name.Indentifier.append('/');
269+
TCandidate candidate = {
270+
.Kind = ECandidateKind::FolderName,
271+
.Content = std::move(name.Indentifier),
272+
};
273+
244274
if (!context.IsQuoted.AtLhs) {
245-
name.Indentifier.prepend('`');
275+
candidate.Content.prepend('`');
276+
}
277+
278+
candidate.Content.append('/');
279+
280+
if (!context.IsQuoted.AtRhs) {
281+
candidate.Content.append('`');
282+
candidate.CursorShift = 1;
246283
}
247-
return {ECandidateKind::FolderName, std::move(name.Indentifier)};
284+
285+
return candidate;
248286
}
249287

250288
if constexpr (std::is_base_of_v<TTableName, T>) {
@@ -396,5 +434,9 @@ void Out<NSQLComplete::ECandidateKind>(IOutputStream& out, NSQLComplete::ECandid
396434

397435
template <>
398436
void Out<NSQLComplete::TCandidate>(IOutputStream& out, const NSQLComplete::TCandidate& value) {
399-
out << "{" << value.Kind << ", \"" << value.Content << "\"}";
437+
out << "{" << value.Kind << ", \"" << value.Content << "\"";
438+
if (value.CursorShift != 0) {
439+
out << ", " << value.CursorShift;
440+
}
441+
out << "}";
400442
}

0 commit comments

Comments
 (0)