MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / completion

Function completion

tools/shell/embedded_shell.cpp:256–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void completion(const char* buffer, linenoiseCompletions* lc) {
257 std::string buf = std::string(buffer);
258
259 // Command completion.
260 if (buf[0] == ':') {
261 for (auto& command : shellCommand.commandList) {
262 if (regex_search(command, std::regex("^" + buf))) {
263 linenoiseAddCompletion(lc, command);
264 }
265 }
266 return;
267 }
268
269 // Skip completion if inside a comment or quote
270 if (isInsideCommentOrQuote(buf)) {
271 return;
272 }
273
274 // RETURN *; completion for MATCH and CALL queries.
275 // Trigger when buffer ends with ')' or ') ' after a MATCH pattern or CALL function.
276 if (regex_search(buf, std::regex(R"(\)\s*$)"))) {
277 // Check for MATCH pattern: MATCH(var:Table) or MATCH (var:Table)
278 bool isMatchQuery =
279 regex_search(buf, std::regex(R"(^\s*MATCH\s*\()", std::regex_constants::icase));
280 // Check for CALL function: CALL func_name(...) or CALL func_name (...)
281 bool isCallFunction =
282 regex_search(buf, std::regex(R"(^\s*CALL\s+\w+\s*\()", std::regex_constants::icase));
283 if (isMatchQuery || isCallFunction) {
284 std::string suffix = buf.back() == ')' ? " RETURN *;" : "RETURN *;";
285 linenoiseAddCompletion(lc, (buf + suffix).c_str());
286 return;
287 }
288 }
289
290 // Node table name completion. Match patterns that include an open bracket `(` with no closing
291 // bracket `)`, and a colon `:` sometime after the open bracket.
292 if (regex_search(buf, std::regex("^[^]*\\([^\\)]*:[^\\)]*$"))) {
293 for (auto& node : nodeTableNames) {
294 addTableCompletion(buf, node, lc);
295 }
296 return;
297 }
298
299 // Rel table name completion. Matches patterns that
300 // include an open square bracket `[` with no closing
301 // bracket `]` and a colon `:` sometime after the open bracket.
302 if (regex_search(buf, std::regex("^[^]*\\[[^\\]]*:[^\\]]*$"))) {
303 for (auto& rel : relTableNames) {
304 addTableCompletion(buf, rel, lc);
305 }
306 return;
307 }
308
309 std::vector<std::string> tempTableNames;
310 std::vector<std::string> foundTableNames;
311 for (auto& node : nodeTableNames) {
312 std::regex nodeTableRegex("\\(([^:\\(]+):(" + node + ")\\)");
313 findTableVariableNames(buf, nodeTableRegex, tempTableNames, foundTableNames);

Callers

nothing calls this directly

Calls 9

linenoiseAddCompletionFunction · 0.85
isInsideCommentOrQuoteFunction · 0.85
addTableCompletionFunction · 0.85
findTableVariableNamesFunction · 0.85
keywordCompletionFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected