blob: e2b48fa5ea7d107deb6f6ed7c2ac8a3a6f7a1bba (
plain) (
blame)
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
|
#include "yql_completer.h"
#include <yql/essentials/sql/v1/complete/sql_complete.h>
namespace NYdb::NConsoleClient {
class TYQLCompleter: public IYQLCompleter {
public:
using TPtr = THolder<IYQLCompleter>;
explicit TYQLCompleter(NSQLComplete::ISqlCompletionEngine::TPtr engine)
: Engine(std::move(engine))
{
}
TCompletions Apply(const std::string& prefix, int& /* contextLen */) override {
auto completion = Engine->Complete({
.Text = prefix,
.CursorPosition = prefix.length(),
});
replxx::Replxx::completions_t entries;
for (auto& candidate : completion.Candidates) {
candidate.Content += ' ';
entries.emplace_back(
std::move(candidate.Content),
ReplxxColorOf(candidate.Kind));
}
return entries;
}
private:
static replxx::Replxx::Color ReplxxColorOf(NSQLComplete::ECandidateKind /* kind */) {
return replxx::Replxx::Color::DEFAULT;
}
NSQLComplete::ISqlCompletionEngine::TPtr Engine;
};
IYQLCompleter::TPtr MakeYQLCompleter() {
return IYQLCompleter::TPtr(
new TYQLCompleter(NSQLComplete::MakeSqlCompletionEngine()));
}
} // namespace NYdb::NConsoleClient
|