void Mysql_shell::add_devapi_completions()

in src/mysqlsh/mysql_shell.cc [1966:2468]


void Mysql_shell::add_devapi_completions() {
  std::shared_ptr<shcore::completer::Object_registry> registry(
      completer_object_registry());

  // These rules allow performing context-aware auto-completion
  // They don't necessarily match 1:1 with real objects, they just
  // represent possible productions in the chaining DevAPI syntax

  // TODO(alfredo) add a meta-class system so that these can be determined
  // dynamically/automatically

  registry->add_completable_type("mysqlx", {{"getSession", "Session", true}});
  registry->add_completable_type("mysql",
                                 {{"getClassicSession", "ClassicSession", true},
                                  {"getSession", "ClassicSession", true}});

  registry->add_completable_type("Operation*", {{"execute", "Result", true}});
  registry->add_completable_type("Bind*", {{"bind", "Bind*", true},
                                           {"execute", "Result", true},
                                           {"help", "", true}});
  registry->add_completable_type("SqlBind*", {{"bind", "SqlBind*", true},
                                              {"execute", "SqlResult", true},
                                              {"help", "", true}});
  registry->add_completable_type("SqlOperation*",
                                 {{"bind", "SqlBind*", true},
                                  {"execute", "SqlResult", true},
                                  {"help", "", true}});

  registry->add_completable_type("Session",
                                 {{"uri", "", false},
                                  {"sshUri", "", false},
                                  {"defaultSchema", "Schema", true},
                                  {"currentSchema", "Schema", true},
                                  {"close", "", true},
                                  {"commit", "SqlResult", true},
                                  {"createSchema", "Schema", true},
                                  {"dropSchema", "", true},
                                  {"getCurrentSchema", "Schema", true},
                                  {"getDefaultSchema", "Schema", true},
                                  {"getSchema", "Schema", true},
                                  {"getSchemas", "", true},
                                  {"getSshUri", "", true},
                                  {"getUri", "", true},
                                  {"help", "", true},
                                  {"isOpen", "", true},
                                  {"quoteName", "", true},
                                  {"rollback", "SqlResult", true},
                                  {"runSql", "SqlResult", true},
                                  {"setCurrentSchema", "Schema", true},
                                  {"setFetchWarnings", "Result", true},
                                  {"sql", "SqlOperation*", true},
                                  {"startTransaction", "SqlResult", true},
                                  {"setSavepoint", "", true},
                                  {"releaseSavepoint", "", true},
                                  {"rollbackTo", "", true},
                                  {"_enableNotices", "", true},
                                  {"_fetchNotice", "", true},
                                  {"_getSocketFd", "", true}});

  registry->add_completable_type("Schema",
                                 {{"name", "name", false},
                                  {"session", "session", false},
                                  {"schema", "schema", false},
                                  {"createCollection", "Collection", true},
                                  {"dropCollection", "", true},
                                  {"existsInDatabase", "", true},
                                  {"getCollection", "Collection", true},
                                  {"getCollectionAsTable", "Table", true},
                                  {"getCollections", "list", true},
                                  {"getName", "string", true},
                                  {"getSchema", "Schema", true},
                                  {"getSession", "Session", true},
                                  {"getTable", "Table", true},
                                  {"getTables", "list", true},
                                  {"help", "string", true},
                                  {"modifyCollection", "", true}});

  registry->add_completable_type("Collection",
                                 {{"add", "CollectionAdd", true},
                                  {"addOrReplaceOne", "Result", true},
                                  {"modify", "CollectionModify", true},
                                  {"find", "CollectionFind", true},
                                  {"remove", "CollectionRemove", true},
                                  {"removeOne", "Result", true},
                                  {"replaceOne", "Result", true},
                                  {"createIndex", "SqlResult", true},
                                  {"dropIndex", "", true},
                                  {"existsInDatabase", "", true},
                                  {"session", "Session", false},
                                  {"schema", "Schema", false},
                                  {"getSchema", "Schema", true},
                                  {"getSession", "Session", true},
                                  {"getName", "", true},
                                  {"getOne", "", true},
                                  {"name", "", false},
                                  {"help", "", true},
                                  {"count", "", false}});

  registry->add_completable_type("CollectionFind",
                                 {{"fields", "CollectionFind*fields", true},
                                  {"groupBy", "CollectionFind*groupBy", true},
                                  {"sort", "CollectionFind*sort", true},
                                  {"limit", "CollectionFind*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("CollectionFind*fields",
                                 {{"groupBy", "CollectionFind*groupBy", true},
                                  {"sort", "CollectionFind*sort", true},
                                  {"limit", "CollectionFind*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});
  registry->add_completable_type(
      "CollectionFind*groupBy",
      {{"having", "CollectionFind*having", true},
       {"sort", "CollectionFind*sort", true},
       {"limit", "CollectionFind*limit", true},
       {"lockShared", "CollectionFind*lockShared", true},
       {"lockExclusive", "CollectionFind*lockShared", true},
       {"bind", "Bind*", true},
       {"execute", "DocResult", true},
       {"help", "", true}});
  registry->add_completable_type("CollectionFind*having",
                                 {{"sort", "CollectionFind*sort", true},
                                  {"limit", "CollectionFind*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("CollectionFind*sort",
                                 {{"limit", "CollectionFind*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});
  registry->add_completable_type(
      "CollectionFind*limit", {{"skip", "CollectionFind*skip_offset", true},
                               {"offset", "CollectionFind*skip_offset", true},
                               {"lockShared", "Bind*", true},
                               {"lockExclusive", "Bind*", true},
                               {"bind", "Bind*", true},
                               {"execute", "DocResult", true},
                               {"help", "", true}});
  registry->add_completable_type("CollectionFind*skip_offset",
                                 {{"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("CollectionFind*lockShared",
                                 {{"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("CollectionFind*lockExclusive",
                                 {{"bind", "Bind*", true},
                                  {"execute", "DocResult", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionAdd",
                                 {{"add", "CollectionAdd", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionRemove",
                                 {{"sort", "CollectionRemove*sort", true},
                                  {"limit", "CollectionRemove*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionRemove*sort",
                                 {{"limit", "CollectionRemove*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionRemove*limit",
                                 {{"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionModify",
                                 {{"set", "CollectionModify*", true},
                                  {"unset", "CollectionModify*", true},
                                  {"merge", "CollectionModify*", true},
                                  {"patch", "CollectionModify*", true},
                                  {"arrayInsert", "CollectionModify*", true},
                                  {"arrayAppend", "CollectionModify*", true},
                                  {"arrayDelete", "CollectionModify*", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionModify*",
                                 {{"set", "CollectionModify*", true},
                                  {"unset", "CollectionModify*", true},
                                  {"merge", "CollectionModify*", true},
                                  {"patch", "CollectionModify*", true},
                                  {"arrayInsert", "CollectionModify*", true},
                                  {"arrayAppend", "CollectionModify*", true},
                                  {"arrayDelete", "CollectionModify*", true},
                                  {"sort", "CollectionModify*sort", true},
                                  {"limit", "CollectionModify*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionModify*sort",
                                 {{"limit", "CollectionModify*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("CollectionModify*limit",
                                 {{"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  // Table

  registry->add_completable_type("Table", {{"select", "TableSelect", true},
                                           {"update", "TableUpdate", true},
                                           {"delete", "TableDelete", true},
                                           {"insert", "TableInsert", true},
                                           {"existsInDatabase", "", true},
                                           {"session", "Session", false},
                                           {"schema", "Schema", false},
                                           {"getSchema", "Schema", true},
                                           {"getSession", "Session", true},
                                           {"getName", "", true},
                                           {"isView", "", true},
                                           {"name", "", false},
                                           {"help", "", true},
                                           {"count", "", false}});

  registry->add_completable_type(
      "TableSelect", {{"where", "TableSelect*where", true},
                      {"groupBy", "TableSelect*groupBy", true},
                      {"orderBy", "TableSelect*sort", true},
                      {"limit", "TableSelect*limit", true},
                      {"lockShared", "TableSelect*lockShared", true},
                      {"lockExclusive", "TableSelect*lockExclusive", true},
                      {"bind", "Bind*", true},
                      {"execute", "RowResult", true},
                      {"help", "", true}});
  registry->add_completable_type("TableSelect*where",
                                 {{"groupBy", "TableSelect*groupBy", true},
                                  {"orderBy", "TableSelect*sort", true},
                                  {"limit", "TableSelect*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*groupBy",
                                 {{"having", "TableSelect*having", true},
                                  {"orderBy", "TableSelect*sort", true},
                                  {"limit", "TableSelect*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*having",
                                 {{"orderBy", "TableSelect*sort", true},
                                  {"limit", "TableSelect*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*sort",
                                 {{"limit", "TableSelect*limit", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*limit",
                                 {{"offset", "TableSelect*skip", true},
                                  {"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*skip",
                                 {{"lockShared", "Bind*", true},
                                  {"lockExclusive", "Bind*", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*lockShared",
                                 {{"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});
  registry->add_completable_type("TableSelect*lockExclusive",
                                 {{"bind", "Bind*", true},
                                  {"execute", "RowResult", true},
                                  {"help", "", true}});

  registry->add_completable_type(
      "TableInsert",
      {{"values", "TableInsert*values", true}, {"help", "", true}});

  registry->add_completable_type("TableInsert*values",
                                 {{"values", "TableInsert", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableDelete",
                                 {{"where", "TableDelete*where", true},
                                  {"orderBy", "TableDelete*sort", true},
                                  {"limit", "TableDelete*limit", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableDelete*where",
                                 {{"orderBy", "TableDelete*sort", true},
                                  {"limit", "TableDelete*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableDelete*sort",
                                 {{"limit", "TableDelete*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableDelete*limit",
                                 {{"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type(
      "TableUpdate", {{"set", "TableUpdate*set", true}, {"help", "", true}});

  registry->add_completable_type("TableUpdate*set",
                                 {{"set", "TableUpdate*", true},
                                  {"where", "TableUpdate*where", true},
                                  {"orderBy", "TableUpdate*sort", true},
                                  {"limit", "TableUpdate*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableUpdate*where",
                                 {{"orderBy", "TableUpdate*sort", true},
                                  {"limit", "TableUpdate*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableUpdate*sort",
                                 {{"limit", "TableUpdate*limit", true},
                                  {"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  registry->add_completable_type("TableUpdate*limit",
                                 {{"bind", "Bind*", true},
                                  {"execute", "Result", true},
                                  {"help", "", true}});

  // Results

  registry->add_completable_type("DocResult",
                                 {{"affectedItemsCount", "", false},
                                  {"fetchOne", "", true},
                                  {"fetchAll", "", true},
                                  {"help", "", true},
                                  {"executionTime", "", false},
                                  {"warningCount", "", false},
                                  {"warnings", "", false},
                                  {"warningsCount", "", false},
                                  {"getAffectedItemsCount", "", false},
                                  {"getExecutionTime", "", true},
                                  {"getWarningCount", "", true},
                                  {"getWarnings", "", true},
                                  {"getWarningsCount", "", true}});

  registry->add_completable_type("RowResult",
                                 {{"affectedItemsCount", "", false},
                                  {"fetchOne", "Row", true},
                                  {"fetchOneObject", "", true},
                                  {"fetchAll", "Row", true},
                                  {"help", "", true},
                                  {"columns", "", false},
                                  {"columnCount", "", false},
                                  {"columnNames", "", false},
                                  {"getAffectedItemsCount", "", false},
                                  {"getColumns", "", true},
                                  {"getColumnCount", "", true},
                                  {"getColumnNames", "", true},
                                  {"executionTime", "", false},
                                  {"warningCount", "", false},
                                  {"warnings", "", false},
                                  {"warningsCount", "", false},
                                  {"getExecutionTime", "", true},
                                  {"getWarningCount", "", true},
                                  {"getWarnings", "", true},
                                  {"getWarningsCount", "", true}});

  registry->add_completable_type("Result",
                                 {{"affectedItemsCount", "", false},
                                  {"executionTime", "", false},
                                  {"warningCount", "", false},
                                  {"warnings", "", false},
                                  {"warningsCount", "", false},
                                  {"affectedItemCount", "", false},
                                  {"autoIncrementValue", "", false},
                                  {"getAffectedItemsCount", "", false},
                                  {"generatedIds", "", false},
                                  {"getAffectedItemCount", "", true},
                                  {"getAutoIncrementValue", "", true},
                                  {"getExecutionTime", "", true},
                                  {"getGeneratedIds", "", true},
                                  {"getWarningCount", "", true},
                                  {"getWarnings", "", true},
                                  {"getWarningsCount", "", true},
                                  {"help", "", true}});

  registry->add_completable_type("SqlResult",
                                 {{"affectedItemsCount", "", false},
                                  {"executionTime", "", true},
                                  {"warningCount", "", true},
                                  {"warnings", "", true},
                                  {"warningsCount", "", true},
                                  {"columnCount", "", true},
                                  {"columns", "", true},
                                  {"columnNames", "", true},
                                  {"autoIncrementValue", "", false},
                                  {"affectedRowCount", "", false},
                                  {"fetchAll", "", true},
                                  {"fetchOne", "", true},
                                  {"fetchOneObject", "", true},
                                  {"getAffectedItemsCount", "", false},
                                  {"getAffectedRowCount", "", true},
                                  {"getAutoIncrementValue", "", true},
                                  {"getColumnCount", "", true},
                                  {"getColumnNames", "", true},
                                  {"getColumns", "", true},
                                  {"getExecutionTime", "", true},
                                  {"getWarningCount", "", true},
                                  {"getWarnings", "", true},
                                  {"getWarningsCount", "", true},
                                  {"hasData", "", true},
                                  {"help", "", true},
                                  {"nextDataSet", "", true},
                                  {"nextResult", "", true}});

  // ===
  registry->add_completable_type("ClassicSession",
                                 {{"close", "", true},
                                  {"commit", "ClassicResult", true},
                                  {"getUri", "", true},
                                  {"getSshUri", "", true},
                                  {"help", "", true},
                                  {"isOpen", "", true},
                                  {"rollback", "ClassicResult", true},
                                  {"runSql", "ClassicResult", true},
                                  {"query", "ClassicResult", true},
                                  {"startTransaction", "ClassicResult", true},
                                  {"uri", "", false},
                                  {"sshUri", "", false},
                                  {"_getSocketFd", "", true}});

  registry->add_completable_type("ClassicResult",
                                 {{"executionTime", "", true},
                                  {"warningCount", "", true},
                                  {"warningsCount", "", true},
                                  {"warnings", "", true},
                                  {"columnCount", "", true},
                                  {"columns", "", true},
                                  {"columnNames", "", true},
                                  {"autoIncrementValue", "", false},
                                  {"affectedItemsCount", "", true},
                                  {"affectedRowCount", "", true},
                                  {"fetchAll", "", true},
                                  {"fetchOne", "", true},
                                  {"fetchOneObject", "", true},
                                  {"getAffectedItemsCount", "", true},
                                  {"getAffectedRowCount", "", true},
                                  {"getAutoIncrementValue", "", true},
                                  {"getColumnCount", "", true},
                                  {"getColumnNames", "", true},
                                  {"getColumns", "", true},
                                  {"getExecutionTime", "", true},
                                  {"getWarningCount", "", true},
                                  {"getWarningsCount", "", true},
                                  {"getWarnings", "", true},
                                  {"getInfo", "", true},
                                  {"info", "", false},
                                  {"hasData", "", true},
                                  {"help", "", true},
                                  {"nextDataSet", "", true},
                                  {"nextResult", "", true}});
}