File indexing completed on 2024-05-12 04:38:07
0001 /* 0002 SPDX-FileCopyrightText: 2007 Alexander Dymo <adymo@kdevelop.org> 0003 SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_ILANGUAGESUPPORT_H 0009 #define KDEVPLATFORM_ILANGUAGESUPPORT_H 0010 0011 #include <QScopedPointer> 0012 #include <QUrl> 0013 0014 #include <language/languageexport.h> 0015 0016 #include "interfaces/isourceformatter.h" 0017 0018 class QReadWriteLock; 0019 0020 namespace KTextEditor { 0021 class Cursor; 0022 class Range; 0023 class Document; 0024 } 0025 0026 namespace KDevelop { 0027 class BasicRefactoring; 0028 class IndexedString; 0029 class ParseJob; 0030 class TopDUContext; 0031 class ICodeHighlighting; 0032 class ICreateClassHelper; 0033 class ILanguageSupportPrivate; 0034 0035 class KDEVPLATFORMLANGUAGE_EXPORT ILanguageSupport 0036 { 0037 public: 0038 ILanguageSupport(); 0039 virtual ~ILanguageSupport(); 0040 0041 /** @return the name of the language.*/ 0042 virtual QString name() const = 0; 0043 /** @return the parse job that is used by background parser to parse given @p url.*/ 0044 virtual ParseJob* createParseJob(const IndexedString& url) = 0; 0045 /** 0046 * Only important for languages that can parse multiple different versions of a file, like C++ due to the preprocessor. 0047 * The default-implementation for other languages is "return DUChain::chainForDocument(url);" 0048 * 0049 * @param proxyContext Whether the returned context should be a proxy-contexts. In C++, a proxy-contexts has no direct content. 0050 * It mainly just imports an actual content-context, and it holds all the imports. It can also represent 0051 * multiple different versions of the same content in the eyes of the preprocessor. Also, a proxy-context may contain the problem- 0052 * descriptions of preprocessor problems. 0053 * The proxy-context should be preferred whenever the problem-list is required, or for deciding whether a document needs to be updated 0054 * (only the proxy-context knows about all the dependencies, since it contains most of the imports) 0055 * 0056 * @warning The DUChain must be locked before calling this, @see KDevelop::DUChainReadLocker 0057 * 0058 * @return the standard context used by this language for the given @p url 0059 **/ 0060 virtual TopDUContext* standardContext(const QUrl& url, bool proxyContext = false); 0061 0062 /** 0063 * Should return a code-highlighting instance for this language, or zero. 0064 */ 0065 virtual ICodeHighlighting* codeHighlighting() const; 0066 0067 /** 0068 * Should return a BasicRefactoring instance that controls the language-agnostic refactoring rules, or zero 0069 */ 0070 virtual BasicRefactoring* refactoring() const; 0071 0072 /** 0073 * Should return a class creating helper for this language, or zero. 0074 * 0075 * If zero is returned, a default class helper will be created. 0076 * Reimplementing this method is therefore not necessary to have classes created in this language. 0077 * */ 0078 virtual ICreateClassHelper* createClassHelper() const; 0079 0080 /** 0081 * Every thread that does background-parsing should read-lock its language's parse-mutex while parsing. 0082 * Any other thread may write-lock the parse-mutex in order to wait for all parsing-threads to finish the parsing. 0083 * The parse-mutex only needs to be locked while working on the du-chain, not while preprocessing or reading. 0084 * Tip: use QReadLocker for read-locking. 0085 * The duchain must always be unlocked when you try to lock a parseLock! 0086 */ 0087 virtual QReadWriteLock* parseLock() const; 0088 0089 /** 0090 * The following functions are used to allow navigation-features, tooltips, etc. for non-duchain language objects. 0091 * In C++, they are used to allow highlighting and navigation of macro-uses. 0092 * */ 0093 0094 /**Should return the local range within the given url that belongs to the 0095 * special language-object that contains @p position , or (QUrl(), KTextEditor::Range:invalid()) */ 0096 virtual KTextEditor::Range specialLanguageObjectRange(const QUrl& url, const KTextEditor::Cursor& position); 0097 0098 /**Should return the source-range and source-document that the 0099 * special language-object that contains @p position refers to, or KTextEditor::Range:invalid(). */ 0100 virtual QPair<QUrl, KTextEditor::Cursor> specialLanguageObjectJumpCursor(const QUrl& url, 0101 const KTextEditor::Cursor& position); 0102 0103 /**Should return a navigation-widget for the 0104 * special language-object that contains @p position refers to as well as the range the object takes there, 0105 * or nullptr and an invalid range. 0106 * If you setProperty("DoNotCloseOnCursorMove", true) on the widget returned, 0107 * then the widget will not close when the cursor moves in the document, which 0108 * enables you to change the document contents from the widget without immediately closing the widget.*/ 0109 virtual QPair<QWidget*, KTextEditor::Range> specialLanguageObjectNavigationWidget(const QUrl& url, 0110 const KTextEditor::Cursor& position); 0111 0112 /**Should return a tiny piece of code which makes it possible for KDevelop to derive the indentation 0113 * settings from an automatic source formatter. Example for C++: "class C{\n class D {\n void c() {\n int m;\n }\n }\n};\n" 0114 * The sample must be completely unindented (no line must start with leading whitespace), 0115 * and it must contain at least 4 indentation levels! 0116 * The default implementation returns an empty string.*/ 0117 virtual QString indentationSample() const; 0118 0119 /** 0120 * Can return a list of source formatting items for this language. 0121 * For example, if your language wants to use the CustomScript engine with 0122 * a specific executable, return an item with "customscript" as the engine 0123 * and a style describing your options as the style (in this case, especially 0124 * the command to execute in the "content" member). 0125 * Multiple items can be returned. Make sure to set the mime type(s) of your language 0126 * on the returned items. 0127 */ 0128 virtual SourceFormatterItemList sourceFormatterItems() const; 0129 0130 enum ReparseDelaySpecialValues { 0131 DefaultDelay = -1, 0132 NoUpdateRequired = -2 0133 }; 0134 0135 /** 0136 * @brief Enables the language to control how long the background parser waits until a changed document is reparsed. 0137 * 0138 * You can return DefaultDelay to use the default delay, or NoUpdateRequired to indicate that 0139 * this change does not require a re-parse at all. 0140 * 0141 * The default implementation returns DefaultDelay if the change was not whitespace-only, 0142 * and NoUpdateRequired otherwise. 0143 * 0144 * @param doc the document which was modified 0145 * @param changedRange the range which was modified 0146 * @param changedText the text which was inserted or removed 0147 * @param removal whether text was removed or inserted 0148 * @return int duration in ms to wait until re-parsing or a value of the ReparseDelaySpecialValues enum. 0149 */ 0150 virtual int suggestedReparseDelayForChange(KTextEditor::Document* doc, const KTextEditor::Range& changedRange, 0151 const QString& changedText, bool removal) const; 0152 0153 private: 0154 const QScopedPointer<class ILanguageSupportPrivate> d_ptr; 0155 Q_DECLARE_PRIVATE(ILanguageSupport) 0156 }; 0157 } 0158 0159 Q_DECLARE_INTERFACE(KDevelop::ILanguageSupport, "org.kdevelop.ILanguageSupport") 0160 0161 #endif