File indexing completed on 2024-05-05 16:41:32

0001 /*
0002     SPDX-FileCopyrightText: 2010-2011 Sven Brauch <svenbrauch@googlemail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "worker.h"
0008 #include "model.h"
0009 #include "context.h"
0010 #include <language/duchain/declaration.h>
0011 #include <KLocalizedString>
0012 #include "codehelpers.h"
0013 #include <KTextEditor/View>
0014 
0015 #include <QDebug>
0016 #include "codecompletiondebug.h"
0017 
0018 namespace Python {
0019 
0020 PythonCodeCompletionWorker::PythonCodeCompletionWorker(PythonCodeCompletionModel *parent, const QUrl& /*document*/)
0021     : KDevelop::CodeCompletionWorker(parent), parent(parent)
0022 {
0023 
0024 }
0025 
0026 
0027 
0028 KDevelop::CodeCompletionContext* PythonCodeCompletionWorker::createCompletionContext(const KDevelop::DUContextPointer& context,
0029                                                                                      const QString& contextText,
0030                                                                                      const QString& followingText,
0031                                                                                      const KDevelop::CursorInRevision& position) const
0032 {
0033     if ( !context ) {
0034         return nullptr;
0035     }
0036     PythonCodeCompletionContext* completionContext = new PythonCodeCompletionContext(
0037         context, contextText, followingText, position, 0, this
0038     );
0039     return completionContext;
0040 }
0041 
0042 void PythonCodeCompletionWorker::updateContextRange(KTextEditor::Range &contextRange, KTextEditor::View *view,
0043                                                     const KDevelop::DUContextPointer& context) const
0044 {
0045     if ( ! context ) {
0046         return;
0047     }
0048     if ( ! contextRange.start().isValid() ) {
0049         contextRange.setStart({0, 0});
0050     }
0051     if ( CodeHelpers::endsInside(view->document()->text(contextRange)) == CodeHelpers::String ) {
0052         qCDebug(KDEV_PYTHON_CODECOMPLETION) << "we're dealing with string completion. extend the range";
0053         contextRange = context->rangeInCurrentRevision();
0054     }
0055 }
0056 
0057 
0058 }
0059 
0060 #include "moc_worker.cpp"