File indexing completed on 2023-05-30 09:03:09
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2009-2012 Alexander Rieder <alexanderrieder@gmail.com> 0004 */ 0005 0006 #include "maximacompletionobject.h" 0007 0008 #include <QDebug> 0009 0010 #include "maximasession.h" 0011 #include "maximakeywords.h" 0012 #include "maximavariablemodel.h" 0013 0014 MaximaCompletionObject::MaximaCompletionObject(const QString& command, int index,MaximaSession* session) : Cantor::CompletionObject(session) 0015 { 0016 qDebug() << "MaximaCompletionObject constructor"; 0017 setLine(command, index); 0018 } 0019 0020 void MaximaCompletionObject::fetchIdentifierType() 0021 { 0022 QStringList userVariableNames=session()->variableModel()->variableNames(); 0023 QStringList userFunctionNames=session()->variableModel()->functions(); 0024 if (std::binary_search(userVariableNames.begin(), userVariableNames.end(), identifier())) 0025 emit fetchingTypeDone(VariableType); 0026 else if (std::binary_search(userFunctionNames.begin(), userFunctionNames.end(), identifier())) 0027 emit fetchingTypeDone(FunctionType); 0028 else if (std::binary_search(MaximaKeywords::instance()->functions().begin(), 0029 MaximaKeywords::instance()->functions().end(), identifier())) 0030 emit fetchingTypeDone(FunctionType); 0031 else if (std::binary_search(MaximaKeywords::instance()->keywords().begin(), 0032 MaximaKeywords::instance()->keywords().end(), identifier())) 0033 emit fetchingTypeDone(KeywordType); 0034 else 0035 emit fetchingTypeDone(VariableType); 0036 } 0037 0038 void MaximaCompletionObject::fetchCompletions() 0039 { 0040 QStringList allCompletions; 0041 allCompletions<<MaximaKeywords::instance()->variables(); 0042 allCompletions<<MaximaKeywords::instance()->functions(); 0043 allCompletions<<MaximaKeywords::instance()->keywords(); 0044 allCompletions<<session()->variableModel()->variableNames(); 0045 allCompletions<<session()->variableModel()->functions(); 0046 0047 const QString prefix = command(); 0048 QStringList prefixCompletion; 0049 for (const QString& str : allCompletions) 0050 if (str.startsWith(prefix)) 0051 prefixCompletion << str; 0052 0053 setCompletions(prefixCompletion); 0054 0055 emit fetchingDone(); 0056 } 0057 0058 bool MaximaCompletionObject::mayIdentifierContain(QChar c) const 0059 { 0060 return c.isLetter() || c.isDigit() || c == QLatin1Char('_') || c == QLatin1Char('%'); 0061 } 0062 0063 bool MaximaCompletionObject::mayIdentifierBeginWith(QChar c) const 0064 { 0065 return c.isLetter() || c == QLatin1Char('_') || c == QLatin1Char('%'); 0066 }