File indexing completed on 2024-04-14 04:31:13

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 #ifndef RUBY_EDITOR_INTEGRATOR_H
0024 #define RUBY_EDITOR_INTEGRATOR_H
0025 
0026 #include <language/editor/rangeinrevision.h>
0027 #include <serialization/indexedstring.h>
0028 
0029 #include <duchain/duchainexport.h>
0030 
0031 namespace ruby {
0032 
0033 class Parser;
0034 struct Node;
0035 
0036 /**
0037  * The different positions around a Node.
0038  */
0039 enum class Edge { FrontEdge, BackEdge };
0040 
0041 /**
0042  * @class EditorIntegrator
0043  *
0044  * The EditorIntegrator for the Ruby plugin.
0045  */
0046 class KDEVRUBYDUCHAIN_EXPORT EditorIntegrator
0047 {
0048 public:
0049     EditorIntegrator();
0050 
0051     /**
0052      * Find the position of the given node at the given edge.
0053      *
0054      * @param node the node to localize.
0055      * @param edge the edge this method has to look at.
0056      */
0057     const KDevelop::CursorInRevision findPosition(const Node *node,
0058                                                   Edge edge = Edge::BackEdge) const;
0059 
0060     /**
0061      * Find the range between the given nodes.
0062      *
0063      * @param from the former node.
0064      * @param to the latter node.
0065      */
0066     const KDevelop::RangeInRevision findRange(const Node *from,
0067                                               const Node *to) const;
0068 
0069     /**
0070      * Get the range of the given node.
0071      *
0072      * @param node the node to get its range.
0073      */
0074     const KDevelop::RangeInRevision findRange(const Node *node) const;
0075 
0076     /**
0077      * Get the url of the document we are editing.
0078      *
0079      * @return the url of the document we are editing.
0080      */
0081     const KDevelop::IndexedString & url() const;
0082 
0083     /**
0084      * Set the parse session (parser) for this EditorIntegrator.
0085      *
0086      * @param session the given RubyParser.
0087      */
0088     void setParseSession(Parser *session);
0089 
0090     /**
0091      * Implemented to make the AbstractUseBuilder happy.
0092      *
0093      * @return Get the parse session for this EditorIntegrator.
0094      */
0095     Parser * parseSession() const;
0096 
0097     /**
0098      * @return a QString that represents the value of the token
0099      * (not the node's name).
0100      */
0101     const QString tokenToString(const Node *node) const;
0102 
0103 private:
0104     Parser *m_session;
0105 };
0106 
0107 }
0108 
0109 #endif // RUBY_EDITOR_INTEGRATOR_H