aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/syntax
diff options
context:
space:
mode:
authorvityaman <vityaman.dev@yandex.ru>2025-05-12 20:47:40 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-05-12 21:00:51 +0300
commitb336ad5ec16dd1f541c55b7944fc9e6b5bba57a2 (patch)
tree4c08e2292888f6ad429ea645b38c0cb1cdb37f2e /yql/essentials/sql/v1/complete/syntax
parentc057c2354db18cf0f616100db4b8e39b146d06eb (diff)
downloadydb-b336ad5ec16dd1f541c55b7944fc9e6b5bba57a2.tar.gz
YQL-19747: Fix caret token position
Outcomes: 1. Need to think more deeply about library interfaces. If you think that an interface is redundant, think again, because author knows a usecase that you do not imagine. 2. If you are lazy now to implement something robustly, think twice because the day will come and this code will fire. The problem was that on input ``` ... cluster.`/yql/t#` ``` C3 receives only a prefix ``` ... cluster.`/yql/t ``` and a token stream produced was incorrect and therefore completions too. --- - Related to `YQL-19747` - Related to https://github.com/ytsaurus/ytsaurus/pull/1257 - Related to https://github.com/ydb-platform/ydb/issues/9056 --- Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1271 commit_hash:8bf5f2683c9e41963003da923f255f63b898aac5
Diffstat (limited to 'yql/essentials/sql/v1/complete/syntax')
-rw-r--r--yql/essentials/sql/v1/complete/syntax/local.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/yql/essentials/sql/v1/complete/syntax/local.cpp b/yql/essentials/sql/v1/complete/syntax/local.cpp
index 549208d4cab..c20b67d2042 100644
--- a/yql/essentials/sql/v1/complete/syntax/local.cpp
+++ b/yql/essentials/sql/v1/complete/syntax/local.cpp
@@ -68,7 +68,7 @@ namespace NSQLComplete {
return {};
}
- TC3Candidates candidates = C3_.Complete(statement);
+ TC3Candidates candidates = C3Complete(statement, context);
TLocalSyntaxContext result;
@@ -118,6 +118,23 @@ namespace NSQLComplete {
return GetC3PreferredRules();
}
+ TC3Candidates C3Complete(TCompletionInput statement, const TCursorTokenContext& context) {
+ auto enclosing = context.Enclosing();
+
+ size_t caretTokenIndex = context.Cursor.NextTokenIndex;
+ if (enclosing.Defined()) {
+ caretTokenIndex = enclosing->Index;
+ }
+
+ TStringBuf text = statement.Text;
+ if (enclosing.Defined() && enclosing->Base->Name == "NOT_EQUALS2") {
+ text = statement.Text.Head(statement.CursorPosition);
+ caretTokenIndex += 1;
+ }
+
+ return C3_.Complete(text, caretTokenIndex);
+ }
+
TLocalSyntaxContext::TKeywords SiftedKeywords(const TC3Candidates& candidates) const {
const auto& vocabulary = Grammar_->GetVocabulary();
const auto& keywordTokens = Grammar_->GetKeywordTokens();