diff options
author | vityaman <[email protected]> | 2025-04-08 16:11:56 +0300 |
---|---|---|
committer | robot-piglet <[email protected]> | 2025-04-08 16:26:47 +0300 |
commit | 2f90258cf6f1625ba0c99f6f37b6c9f336590534 (patch) | |
tree | 87891b9f23d6c25e134671a920553864a5331e7f /yql/essentials/sql/v1/complete/sql_complete.cpp | |
parent | 7077d90968fe79dfe126e92543d669259f02ef3a (diff) |
YQL-19747 Complete after PRAGMA and multi-token names
- [x] Complete after PRAGMA
- [x] Complete multi-token names correctly, for example, `yt.` returns only `DisableStrict`, not `yt.DisableStrict` and `DateTime::` returns `Split`, not `DateTime::Split`.
I tried to implement it using `CompletedToken` edition, but not all completion environments support candidates with various `contextLen` (`Replxx` does not). So I decided that completions should rewrite only the current token, not sequences. For example, on `DateTime::Spl` rewrite only `Spl`. It makes sense as multi-token names have some namespace separated by a punctuation, so used types only namespace and gets names inside of it.
---
Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1181
commit_hash:9d8967ac43b9348f6dbb53837d92a9dcc9b51f48
Diffstat (limited to 'yql/essentials/sql/v1/complete/sql_complete.cpp')
-rw-r--r-- | yql/essentials/sql/v1/complete/sql_complete.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/yql/essentials/sql/v1/complete/sql_complete.cpp b/yql/essentials/sql/v1/complete/sql_complete.cpp index ed3afa29df4..85fcf87afd1 100644 --- a/yql/essentials/sql/v1/complete/sql_complete.cpp +++ b/yql/essentials/sql/v1/complete/sql_complete.cpp @@ -35,10 +35,10 @@ namespace NSQLComplete { << " for input size " << input.Text.size(); } - auto prefix = input.Text.Head(input.CursorPosition); - auto completedToken = GetCompletedToken(prefix); + TLocalSyntaxContext context = SyntaxAnalysis->Analyze(input); - auto context = SyntaxAnalysis->Analyze(input); + TStringBuf prefix = input.Text.Head(input.CursorPosition); + TCompletedToken completedToken = GetCompletedToken(prefix); TVector<TCandidate> candidates; EnrichWithKeywords(candidates, std::move(context.Keywords), completedToken); @@ -85,12 +85,20 @@ namespace NSQLComplete { .Limit = Configuration.Limit - candidates.size(), }; + if (context.Pragma) { + TPragmaName::TConstraints constraints; + constraints.Namespace = context.Pragma->Namespace; + request.Constraints.Pragma = std::move(constraints); + } + if (context.IsTypeName) { - request.Constraints.TypeName = TTypeName::TConstraints(); + request.Constraints.Type = TTypeName::TConstraints(); } - if (context.IsFunctionName) { - request.Constraints.Function = TFunctionName::TConstraints(); + if (context.Function) { + TFunctionName::TConstraints constraints; + constraints.Namespace = context.Function->Namespace; + request.Constraints.Function = std::move(constraints); } if (request.IsEmpty()) { @@ -107,6 +115,9 @@ namespace NSQLComplete { for (auto& name : names) { candidates.emplace_back(std::visit([](auto&& name) -> TCandidate { using T = std::decay_t<decltype(name)>; + if constexpr (std::is_base_of_v<TPragmaName, T>) { + return {ECandidateKind::PragmaName, std::move(name.Indentifier)}; + } if constexpr (std::is_base_of_v<TTypeName, T>) { return {ECandidateKind::TypeName, std::move(name.Indentifier)}; } @@ -162,6 +173,9 @@ void Out<NSQLComplete::ECandidateKind>(IOutputStream& out, NSQLComplete::ECandid case NSQLComplete::ECandidateKind::Keyword: out << "Keyword"; break; + case NSQLComplete::ECandidateKind::PragmaName: + out << "PragmaName"; + break; case NSQLComplete::ECandidateKind::TypeName: out << "TypeName"; break; |