File indexing completed on 2024-04-14 14:47:35
0001 /* 0002 SPDX-FileCopyrightText: 2006-2008 Hamish Rodda <rodda@kde.org> 0003 SPDX-FileCopyrightText: 2007-2008 David Nolden <david.nolden.kdevelop@art-master.de> 0004 SPDX-FileCopyrightText: 2008 Niko Sams <niko.sams@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "model.h" 0010 0011 #include <QIcon> 0012 #include <QMetaType> 0013 #include <QTextFormat> 0014 #include <QBrush> 0015 #include <QDir> 0016 #include <ktexteditor/view.h> 0017 #include <ktexteditor/document.h> 0018 0019 #include <language/duchain/declaration.h> 0020 #include <language/duchain/ducontext.h> 0021 #include <language/duchain/duchain.h> 0022 #include <language/duchain/parsingenvironment.h> 0023 #include <editorintegrator.h> 0024 #include <language/duchain/duchainlock.h> 0025 #include <language/duchain/duchainbase.h> 0026 #include <language/duchain/topducontext.h> 0027 #include <language/duchain/duchainutils.h> 0028 0029 #include "../duchain/declarations/classmethoddeclaration.h" 0030 0031 #include "context.h" 0032 #include "worker.h" 0033 #include "completiondebug.h" 0034 0035 using namespace KTextEditor; 0036 using namespace KDevelop; 0037 0038 namespace Php 0039 { 0040 0041 CodeCompletionModel::CodeCompletionModel(QObject * parent) 0042 : KDevelop::CodeCompletionModel(parent) 0043 { 0044 } 0045 0046 KDevelop::CodeCompletionWorker* CodeCompletionModel::createCompletionWorker() 0047 { 0048 return new CodeCompletionWorker(this); 0049 } 0050 0051 CodeCompletionModel::~CodeCompletionModel() 0052 { 0053 } 0054 0055 Range CodeCompletionModel::completionRange(View* view, const Cursor &position) 0056 { 0057 Range range = KDevelop::CodeCompletionModel::completionRange(view, position); 0058 if (range.start().column() > 0) { 0059 KTextEditor::Range preRange(Cursor(range.start().line(), range.start().column() - 1), 0060 Cursor(range.start().line(), range.start().column())); 0061 qCDebug(COMPLETION) << preRange << view->document()->text(preRange); 0062 const QString contents = view->document()->text(preRange); 0063 if ( contents == QLatin1String("$") ) { 0064 range.expandToRange(preRange); 0065 qCDebug(COMPLETION) << "using custom completion range" << range; 0066 } 0067 } 0068 return range; 0069 } 0070 0071 bool CodeCompletionModel::shouldAbortCompletion(View* view, const Range &range, const QString ¤tCompletion) 0072 { 0073 if(view->cursorPosition() < range.start() || view->cursorPosition() > range.end()) 0074 return true; //Always abort when the completion-range has been left 0075 //Do not abort completions when the text has been empty already before and a newline has been entered 0076 0077 static const QRegExp allowedText("^\\$?(\\w*)"); 0078 return !allowedText.exactMatch(currentCompletion); 0079 } 0080 0081 } 0082 0083 #include "moc_model.cpp"