File indexing completed on 2024-10-06 09:24:50
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2014 Lucas Hermann Negri <lucashnegri@gmail.com> 0004 */ 0005 0006 #include "luacompletionobject.h" 0007 0008 #include <QStringList> 0009 0010 #include "luasession.h" 0011 #include "luahelper.h" 0012 #include "luakeywords.h" 0013 0014 LuaCompletionObject::LuaCompletionObject(const QString& command, int index, LuaSession* session) 0015 : Cantor::CompletionObject(session) 0016 { 0017 if (session->status() != Cantor::Session::Disable) 0018 m_L = session->getState(); 0019 else 0020 m_L = nullptr; 0021 setLine(command, index); 0022 } 0023 0024 void LuaCompletionObject::fetchCompletions() 0025 { 0026 if (session()->status() != Cantor::Session::Done) 0027 { 0028 QStringList allCompletions; 0029 0030 allCompletions << LuaKeywords::instance()->keywords(); 0031 allCompletions << LuaKeywords::instance()->functions(); 0032 allCompletions << LuaKeywords::instance()->variables(); 0033 0034 setCompletions(allCompletions); 0035 emit fetchingDone(); 0036 } 0037 else 0038 { 0039 QString name = command(); 0040 int idx = name.lastIndexOf(QLatin1String("=")); 0041 0042 // gets "table.next" from the expression "varname = table.next" 0043 if(idx >= 0) 0044 name = name.mid(idx+1).trimmed(); 0045 0046 setCompletions( luahelper_completion(m_L, name) ); 0047 emit fetchingDone(); 0048 } 0049 } 0050 0051 bool LuaCompletionObject::mayIdentifierContain(QChar c) const 0052 { 0053 return c.isLetter() || c.isDigit() || c == QLatin1Char('_') || c == QLatin1Char('.') || c == QLatin1Char(':'); 0054 } 0055 0056 bool LuaCompletionObject::mayIdentifierBeginWith(QChar c) const 0057 { 0058 return c.isLetter() || c == QLatin1Char('_'); 0059 }