File indexing completed on 2024-05-12 04:37:44
0001 /* 0002 SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "codecompletioncontext.h" 0008 0009 #include <debug.h> 0010 0011 #include <util/pushvalue.h> 0012 #include <language/duchain/ducontext.h> 0013 0014 using namespace KDevelop; 0015 0016 using IntPusher = PushValue<int>; 0017 0018 ///Extracts the last line from the given string 0019 QString CodeCompletionContext::extractLastLine(const QString& str) 0020 { 0021 int prevLineEnd = str.lastIndexOf(QLatin1Char('\n')); 0022 if (prevLineEnd != -1) 0023 return str.mid(prevLineEnd + 1); 0024 else 0025 return str; 0026 } 0027 0028 int completionRecursionDepth = 0; 0029 0030 CodeCompletionContext::CodeCompletionContext(const DUContextPointer& context, const QString& text, 0031 const KDevelop::CursorInRevision& position, int depth) 0032 : m_text(text) 0033 , m_depth(depth) 0034 , m_valid(true) 0035 , m_position(position) 0036 , m_duContext(context) 0037 , m_parentContext(nullptr) 0038 { 0039 IntPusher(completionRecursionDepth, completionRecursionDepth + 1); 0040 0041 if (depth > 10) { 0042 qCWarning(LANGUAGE) << "too much recursion"; 0043 m_valid = false; 0044 return; 0045 } 0046 0047 if (completionRecursionDepth > 10) { 0048 qCWarning(LANGUAGE) << "too much recursion"; 0049 m_valid = false; 0050 return; 0051 } 0052 } 0053 0054 CodeCompletionContext::~CodeCompletionContext() 0055 { 0056 } 0057 0058 int CodeCompletionContext::depth() const 0059 { 0060 return m_depth; 0061 } 0062 0063 bool CodeCompletionContext::isValid() const 0064 { 0065 return m_valid; 0066 } 0067 0068 void KDevelop::CodeCompletionContext::setParentContext( 0069 QExplicitlySharedDataPointer<KDevelop::CodeCompletionContext> newParent) 0070 { 0071 m_parentContext = newParent; 0072 int newDepth = m_depth + 1; 0073 while (newParent) { 0074 newParent->m_depth = newDepth; 0075 ++newDepth; 0076 newParent = newParent->m_parentContext; 0077 } 0078 } 0079 0080 CodeCompletionContext* CodeCompletionContext::parentContext() 0081 { 0082 return m_parentContext.data(); 0083 } 0084 0085 QList<QExplicitlySharedDataPointer<KDevelop::CompletionTreeElement>> KDevelop::CodeCompletionContext::ungroupedElements() 0086 { 0087 return QList<QExplicitlySharedDataPointer<KDevelop::CompletionTreeElement>>(); 0088 } 0089 0090 KDevelop::DUContext* KDevelop::CodeCompletionContext::duContext() const 0091 { 0092 return m_duContext.data(); 0093 }