diff options
author | vitya-smirnov <[email protected]> | 2025-06-23 14:56:28 +0300 |
---|---|---|
committer | vitya-smirnov <[email protected]> | 2025-06-23 15:43:07 +0300 |
commit | 8174698515f702eddb4e32490cd10cd65d0bc936 (patch) | |
tree | 2fe32c6880723cc129d1e13e9cf86632ed130aed /yql/essentials/sql/v1/complete/sql_complete.cpp | |
parent | 0133b00bb26b7f9040d1ba71da735b68e4e2a2c0 (diff) |
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
Diffstat (limited to 'yql/essentials/sql/v1/complete/sql_complete.cpp')
-rw-r--r-- | yql/essentials/sql/v1/complete/sql_complete.cpp | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/yql/essentials/sql/v1/complete/sql_complete.cpp b/yql/essentials/sql/v1/complete/sql_complete.cpp index 187756c6975..8b732bd3913 100644 --- a/yql/essentials/sql/v1/complete/sql_complete.cpp +++ b/yql/essentials/sql/v1/complete/sql_complete.cpp @@ -209,7 +209,18 @@ namespace NSQLComplete { if constexpr (std::is_base_of_v<TKeyword, T>) { TVector<TString>& seq = context.Keywords[name.Content]; seq.insert(std::begin(seq), name.Content); - return {ECandidateKind::Keyword, FormatKeywords(seq)}; + + TCandidate candidate = { + .Kind = ECandidateKind::Keyword, + .Content = FormatKeywords(seq), + }; + + if (candidate.Content.EndsWith('(')) { + candidate.Content += ')'; + candidate.CursorShift = 1; + } + + return candidate; } if constexpr (std::is_base_of_v<TPragmaName, T>) { @@ -217,22 +228,37 @@ namespace NSQLComplete { } if constexpr (std::is_base_of_v<TTypeName, T>) { + TCandidate candidate = { + .Kind = ECandidateKind::TypeName, + .Content = std::move(name.Indentifier), + }; + switch (name.Kind) { case TTypeName::EKind::Simple: { } break; case TTypeName::EKind::Container: { - name.Indentifier += "<"; + candidate.Content += "<>"; + candidate.CursorShift = 1; } break; case TTypeName::EKind::Parameterized: { - name.Indentifier += "("; + candidate.Content += "()"; + candidate.CursorShift = 1; } break; } - return {ECandidateKind::TypeName, std::move(name.Indentifier)}; + + return candidate; } if constexpr (std::is_base_of_v<TFunctionName, T>) { - name.Indentifier += "("; - return {ECandidateKind::FunctionName, std::move(name.Indentifier)}; + TCandidate candidate = { + .Kind = ECandidateKind::FunctionName, + .Content = std::move(name.Indentifier), + }; + + candidate.Content += "()"; + candidate.CursorShift = 1; + + return candidate; } if constexpr (std::is_base_of_v<THintName, T>) { @@ -240,11 +266,23 @@ namespace NSQLComplete { } if constexpr (std::is_base_of_v<TFolderName, T>) { - name.Indentifier.append('/'); + TCandidate candidate = { + .Kind = ECandidateKind::FolderName, + .Content = std::move(name.Indentifier), + }; + if (!context.IsQuoted.AtLhs) { - name.Indentifier.prepend('`'); + candidate.Content.prepend('`'); + } + + candidate.Content.append('/'); + + if (!context.IsQuoted.AtRhs) { + candidate.Content.append('`'); + candidate.CursorShift = 1; } - return {ECandidateKind::FolderName, std::move(name.Indentifier)}; + + return candidate; } if constexpr (std::is_base_of_v<TTableName, T>) { @@ -396,5 +434,9 @@ void Out<NSQLComplete::ECandidateKind>(IOutputStream& out, NSQLComplete::ECandid template <> void Out<NSQLComplete::TCandidate>(IOutputStream& out, const NSQLComplete::TCandidate& value) { - out << "{" << value.Kind << ", \"" << value.Content << "\"}"; + out << "{" << value.Kind << ", \"" << value.Content << "\""; + if (value.CursorShift != 0) { + out << ", " << value.CursorShift; + } + out << "}"; } |