File indexing completed on 2024-05-05 16:42:29
0001 /* 0002 SPDX-FileCopyrightText: 2007 Piyush verma <piyush.verma@gmail.com> 0003 SPDX-FileCopyrightText: 2011-2012 Sven Brauch <svenbrauch@googlemail.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "pythoneditorintegrator.h" 0009 #include <ktexteditor/document.h> 0010 0011 #include <language/editor/documentrange.h> 0012 0013 #include "ast.h" 0014 0015 using namespace KTextEditor; 0016 0017 namespace Python 0018 { 0019 0020 PythonEditorIntegrator::PythonEditorIntegrator(ParseSession* session) : 0021 m_session(session), m_indentInformationCache(new FileIndentInformation(session->contents())) 0022 { 0023 0024 } 0025 0026 PythonEditorIntegrator::~PythonEditorIntegrator() 0027 { 0028 delete m_indentInformationCache; 0029 m_indentInformationCache = nullptr; 0030 } 0031 0032 ParseSession* PythonEditorIntegrator::parseSession() const 0033 { 0034 Q_ASSERT(m_session); 0035 return m_session; 0036 } 0037 0038 CursorInRevision PythonEditorIntegrator::findPosition(const Ast* node , Edge edge) const 0039 { 0040 Q_ASSERT(node); 0041 if ( edge == BackEdge ) 0042 { 0043 // Apparently KTE expects a range to go until _after_ the last character that should be included 0044 // however the parser calculates endCol as the index _before_ the last included character, so adjust here 0045 return CursorInRevision( node->endLine, node->endCol+1 ); 0046 }else 0047 { 0048 return CursorInRevision( node->startLine, node->startCol ); 0049 } 0050 } 0051 0052 RangeInRevision PythonEditorIntegrator::findRange(const Ast * node, RangeEdge edge) const 0053 { 0054 Q_UNUSED( edge ); 0055 return RangeInRevision( findPosition( node, FrontEdge ), findPosition( node, BackEdge ) ); 0056 } 0057 0058 RangeInRevision PythonEditorIntegrator::findRange(const Python::Ast* from, const Python::Ast* to) const 0059 { 0060 return RangeInRevision( findPosition( from, FrontEdge ), findPosition( to, BackEdge ) ); 0061 } 0062 0063 }