Skip to content

Commit

Permalink
Fix auto-completion suggestions for "icinga2 console"
Browse files Browse the repository at this point in the history
refs #12408
  • Loading branch information
gunnarbeutner committed Aug 12, 2016
1 parent 729a125 commit b74014f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
19 changes: 13 additions & 6 deletions lib/base/scriptframe.cpp
Expand Up @@ -26,6 +26,19 @@ using namespace icinga;
boost::thread_specific_ptr<std::stack<ScriptFrame *> > ScriptFrame::m_ScriptFrames;
Array::Ptr ScriptFrame::m_Imports;

INITIALIZE_ONCE_WITH_PRIORITY(&ScriptFrame::StaticInitialize, 50);

void ScriptFrame::StaticInitialize(void)
{
Dictionary::Ptr systemNS = new Dictionary();
ScriptGlobal::Set("System", systemNS);
AddImport(systemNS);

Dictionary::Ptr deprecatedNS = new Dictionary();
ScriptGlobal::Set("Deprecated", deprecatedNS);
AddImport(deprecatedNS);
}

ScriptFrame::ScriptFrame(void)
: Locals(new Dictionary()), Self(ScriptGlobal::GetGlobals()), Sandboxed(false), Depth(0)
{
Expand Down Expand Up @@ -109,12 +122,6 @@ void ScriptFrame::PushFrame(ScriptFrame *frame)

Array::Ptr ScriptFrame::GetImports(void)
{
if (!m_Imports) {
m_Imports = new Array();
m_Imports->Add(ScriptGlobal::Get("System"));
m_Imports->Add(ScriptGlobal::Get("Deprecated"));
}

return m_Imports;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/base/scriptframe.hpp
Expand Up @@ -40,6 +40,8 @@ struct I2_BASE_API ScriptFrame
ScriptFrame(const Value& self);
~ScriptFrame(void);

static void StaticInitialize(void);

void IncreaseStackDepth(void);
void DecreaseStackDepth(void);

Expand Down
14 changes: 7 additions & 7 deletions lib/remote/consolehandler.cpp
Expand Up @@ -215,7 +215,7 @@ static void AddSuggestion(std::vector<String>& matches, const String& word, cons
matches.push_back(suggestion);
}

static void AddSuggestions(std::vector<String>& matches, const String& word, const String& pword, bool withPrototype, const Value& value)
static void AddSuggestions(std::vector<String>& matches, const String& word, const String& pword, bool withFields, const Value& value)
{
String prefix;

Expand All @@ -231,15 +231,15 @@ static void AddSuggestions(std::vector<String>& matches, const String& word, con
}
}

Type::Ptr type = value.GetReflectionType();
if (withFields) {
Type::Ptr type = value.GetReflectionType();

for (int i = 0; i < type->GetFieldCount(); i++) {
Field field = type->GetFieldInfo(i);
for (int i = 0; i < type->GetFieldCount(); i++) {
Field field = type->GetFieldInfo(i);

AddSuggestion(matches, word, prefix + field.Name);
}
AddSuggestion(matches, word, prefix + field.Name);
}

if (withPrototype) {
while (type) {
Object::Ptr prototype = type->GetPrototype();
Dictionary::Ptr dict = dynamic_pointer_cast<Dictionary>(prototype);
Expand Down

0 comments on commit b74014f

Please sign in to comment.