File indexing completed on 2024-04-21 04:35:54
0001 /* This file is part of KDevelop 0002 * 0003 * Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #ifndef RUBY_LOADER_H 0020 #define RUBY_LOADER_H 0021 0022 #include <duchain/duchainexport.h> 0023 #include <language/duchain/declaration.h> 0024 #include <language/util/includeitem.h> 0025 #include <util/path.h> 0026 0027 namespace ruby { 0028 0029 class EditorIntegrator; 0030 struct Node; 0031 0032 /** 0033 * @class Loader 0034 * 0035 * This class handles the ruby's require/require_relative statements. This 0036 * class implements a caching system to keep the whole thing as 0037 * optimal as possible. 0038 */ 0039 class KDEVRUBYDUCHAIN_EXPORT Loader 0040 { 0041 public: 0042 /** 0043 * Get the url of the file specified by a require statement. 0044 * 0045 * @param node The node containing the file to be required. Note that the 0046 * node's kind *must* be token_string. 0047 * @param editor The EditorIntegrator from the current builder. 0048 * @param local Set to true if the required file is relative to the current 0049 * document (used for the require_relative statement). 0050 * @returns a KDevelop::Path containing the path to the required file. 0051 */ 0052 static KDevelop::Path getRequiredFile(Node *node, 0053 const EditorIntegrator *editor, 0054 bool local); 0055 0056 /** 0057 * Get all the files/directories inside the given directory except for 0058 * (UNIX) hidden files, backup files (that end with ~) and .so files. 0059 * 0060 * @param url the url where to search. 0061 * @param hint The following text on the Completion context. 0062 * @param relative the absolute path of the directory that contains the 0063 * current file. If set, all the items returned are relative to the given 0064 * path. 0065 * @returns a list of IncludeItem's containing all the files/directories 0066 * that fit the given parameters. 0067 */ 0068 static QVector<KDevelop::IncludeItem> 0069 getFilesInSearchPath(const QString &url, const QString &hint, 0070 const KDevelop::Path &relative = KDevelop::Path()); 0071 0072 protected: 0073 /** 0074 * Get the path for the given gem name. 0075 * 0076 * @param name The given gem name. 0077 * @returns the path for the given gem name. 0078 * @note that it assumes that it does not end with ".rb". 0079 */ 0080 static KDevelop::Path getGem(const QString &name); 0081 0082 /** 0083 * Fill the m_urlCache attribute with the urls available from Ruby 0084 * through $: 0085 */ 0086 static void fillUrlCache(); 0087 0088 private: 0089 /// @returns true if the url cache has been filled with search paths. 0090 static inline bool urlsCached() 0091 { 0092 return !s_rubyPath.isEmpty() || !s_gemPath.isEmpty(); 0093 } 0094 0095 protected: 0096 /** 0097 * The cache of search paths. The m_rubyPath attribute is the list of 0098 * search paths for the Ruby standard library. The m_gemPath attribute 0099 * is the list of search paths for the gems. 0100 */ 0101 static QList<KDevelop::Path> s_rubyPath; 0102 static QList<KDevelop::Path> s_gemPath; 0103 }; 0104 0105 } 0106 0107 #endif /* RUBY_LOADER_H */