File indexing completed on 2023-05-30 09:03:16
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2011 Filipe Saraiva <filipe@kde.org> 0004 */ 0005 0006 #include "scilabcompletionobject.h" 0007 0008 #include <QDebug> 0009 0010 #include "scilabsession.h" 0011 #include "scilabkeywords.h" 0012 0013 ScilabCompletionObject::ScilabCompletionObject(const QString& command, int index, ScilabSession* session) : Cantor::CompletionObject(session) 0014 { 0015 setLine(command, index); 0016 } 0017 0018 void ScilabCompletionObject::fetchCompletions() 0019 { 0020 // A more elegant approach would be to use Scilab's completion() function, 0021 // similarly to how fetching is done in OctaveCompletionObject. 0022 // Unfortunately its interactive behavior is not handled well by cantor. 0023 QStringList allCompletions; 0024 0025 allCompletions << ScilabKeywords::instance()->variables(); 0026 allCompletions << ScilabKeywords::instance()->functions(); 0027 allCompletions << ScilabKeywords::instance()->keywords(); 0028 0029 setCompletions(allCompletions); 0030 0031 emit fetchingDone(); 0032 } 0033 0034 void ScilabCompletionObject::fetchIdentifierType() 0035 { 0036 // Scilab's typeof function could be used here, but as long as these lists 0037 // are used just looking up the name is easier. 0038 0039 if (std::binary_search(ScilabKeywords::instance()->functions().begin(), ScilabKeywords::instance()->functions().end(), 0040 identifier())) 0041 emit fetchingTypeDone(FunctionType); 0042 else if (std::binary_search(ScilabKeywords::instance()->keywords().begin(),ScilabKeywords::instance()->keywords().end(), 0043 identifier())) 0044 emit fetchingTypeDone(KeywordType); 0045 else 0046 emit fetchingTypeDone(VariableType); 0047 } 0048 0049 bool ScilabCompletionObject::mayIdentifierContain(QChar c) const 0050 { 0051 return c.isLetter() || c.isDigit() || c == QLatin1Char('_') || c == QLatin1Char('%') || c == QLatin1Char('$'); 0052 } 0053 0054 bool ScilabCompletionObject::mayIdentifierBeginWith(QChar c) const 0055 { 0056 return c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('%') || c == QLatin1Char('$'); 0057 }