File indexing completed on 2024-04-28 05:49:07
0001 /* This file is part of the Kate project. 0002 * 0003 * SPDX-FileCopyrightText: 2010 Christoph Cullmann <cullmann@kde.org> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <ktexteditor/document.h> 0011 #include <ktexteditor/view.h> 0012 0013 #include <QStandardItemModel> 0014 #include <QStringList> 0015 #include <QTemporaryFile> 0016 0017 /** 0018 * ctags reading 0019 */ 0020 #include "ctags/readtags.h" 0021 0022 /** 0023 * Class representing the index of a project. 0024 * This includes knowledge from ctags and Co. 0025 * Allows you to search for stuff and to get some useful auto-completion. 0026 * Is created in Worker thread in the background, then passed to project in 0027 * the main thread for usage. 0028 */ 0029 class KateProjectIndex 0030 { 0031 public: 0032 /** 0033 * construct new index for given files 0034 * @param files files to index 0035 * @param ctagsMap ctags section for extra options 0036 */ 0037 KateProjectIndex(const QString &baseDir, const QString &indexDir, const QStringList &files, const QVariantMap &ctagsMap, bool force); 0038 0039 /** 0040 * deconstruct project 0041 */ 0042 ~KateProjectIndex(); 0043 0044 /** 0045 * Which kind of match items should be created in the passed model 0046 * of the findMatches function? 0047 */ 0048 enum MatchType { 0049 /** 0050 * Completion matches, containing only name and same name only once 0051 */ 0052 CompletionMatches, 0053 0054 /** 0055 * Find matches, containing name, kind, file, line, ... 0056 */ 0057 FindMatches 0058 }; 0059 0060 /** 0061 * Fill in completion matches for given view/range. 0062 * Uses e.g. ctags index. 0063 * @param model model to fill with matches 0064 * @param searchWord word to search for 0065 * @param type type of matches 0066 * @param options ctags find options (use default if -1) 0067 */ 0068 void findMatches(QStandardItemModel &model, const QString &searchWord, MatchType type, int options = -1); 0069 0070 /** 0071 * Check if running ctags was successful. This can be used 0072 * as indicator whether ctags is installed or not. 0073 * @return true if a valid index exists, otherwise false 0074 */ 0075 bool isValid() const 0076 { 0077 return m_ctagsIndexHandle; 0078 } 0079 0080 private: 0081 /** 0082 * Load ctags tags. 0083 * @param files files to index 0084 * @param ctagsMap ctags section for extra options 0085 */ 0086 void loadCtags(const QStringList &files, const QVariantMap &ctagsMap, bool force); 0087 0088 /** 0089 * Open ctags tags. 0090 */ 0091 void openCtags(); 0092 0093 private: 0094 /** 0095 * ctags index file 0096 */ 0097 std::unique_ptr<QFile> m_ctagsIndexFile; 0098 0099 /** 0100 * handle to ctags file for querying, if possible 0101 */ 0102 tagFile *m_ctagsIndexHandle; 0103 };