Fix auto-completion suggestions for "icinga2 console"

refs #12408
This commit is contained in:
Gunnar Beutner 2016-08-12 15:36:47 +02:00
parent 729a1259c0
commit b74014fa5e
3 changed files with 22 additions and 13 deletions

View File

@ -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)
{
@ -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;
}

View File

@ -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);

View File

@ -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;
@ -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);