File indexing completed on 2024-04-21 04:35:53
0001 /* This file is part of KDevelop 0002 * 0003 * Copyright 2006 Hamish Rodda <rodda@kde.org> 0004 * Copyright 2010 Alexander Dymo <adymo@kdevelop.org> 0005 * Copyright (C) 2011-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0006 * 0007 * This program is free software; you can redistribute it and/or modify 0008 * it under the terms of the GNU Library General Public License as 0009 * published by the Free Software Foundation; either version 2 of the 0010 * License, or (at your option) any later version. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public 0018 * License along with this program; if not, write to the 0019 * Free Software Foundation, Inc., 0020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include <duchain/editorintegrator.h> 0024 0025 #include <parser/parser.h> 0026 0027 using namespace KDevelop; 0028 namespace ruby { 0029 0030 EditorIntegrator::EditorIntegrator() 0031 { 0032 } 0033 0034 const CursorInRevision EditorIntegrator::findPosition(const Node *node, 0035 Edge edge) const 0036 { 0037 Q_ASSERT(node); 0038 0039 if (edge == Edge::BackEdge) { 0040 return CursorInRevision(node->pos.end_line - 1, node->pos.end_col); 0041 } 0042 return CursorInRevision(node->pos.start_line - 1, node->pos.start_col); 0043 } 0044 0045 const RangeInRevision EditorIntegrator::findRange(const Node *from, 0046 const Node *to) const 0047 { 0048 CursorInRevision c_from = findPosition(from, Edge::FrontEdge); 0049 CursorInRevision c_to = findPosition(to, Edge::BackEdge); 0050 0051 return RangeInRevision(c_from, c_to); 0052 } 0053 0054 const RangeInRevision EditorIntegrator::findRange(const Node *node) const 0055 { 0056 CursorInRevision c_from = findPosition(node, Edge::FrontEdge); 0057 CursorInRevision c_to = findPosition(node, Edge::BackEdge); 0058 0059 return RangeInRevision(c_from, c_to); 0060 } 0061 0062 const IndexedString & EditorIntegrator::url() const 0063 { 0064 return m_session->currentDocument; 0065 } 0066 0067 void EditorIntegrator::setParseSession(Parser *session) 0068 { 0069 m_session = session; 0070 } 0071 0072 Parser * EditorIntegrator::parseSession() const 0073 { 0074 return m_session; 0075 } 0076 0077 const QString EditorIntegrator::tokenToString(const Node *node) const 0078 { 0079 return m_session->symbol(node); 0080 } 0081 0082 }