• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevelop/kdevplatform/language/highlighting

  • extragear
  • kdevelop
  • kdevelop
  • kdevplatform
  • language
  • highlighting
codehighlighting.h
Go to the documentation of this file.
1 /*
2  * This file is part of KDevelop
3  *
4  * Copyright 2007-2010 David Nolden <[email protected]>
5  * Copyright 2006 Hamish Rodda <[email protected]>
6  * Copyright 2009 Milian Wolff <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Library General Public License as
10  * published by the Free Software Foundation; either version 2 of the
11  * License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef KDEVPLATFORM_CODEHIGHLIGHTING_H
25 #define KDEVPLATFORM_CODEHIGHLIGHTING_H
26 
27 #include <QObject>
28 #include <QHash>
29 
30 #include <serialization/indexedstring.h>
31 #include <language/duchain/ducontext.h>
32 #include <language/interfaces/icodehighlighting.h>
33 #include <language/backgroundparser/documentchangetracker.h>
34 
35 #include <KTextEditor/Attribute>
36 #include <KTextEditor/MovingRange>
37 
38 namespace KDevelop {
39 class DUContext;
40 class Declaration;
41 
42 using ColorMap = QVector<KDevelop::Declaration*>;
43 
44 class CodeHighlighting;
45 
46 struct HighlightingEnumContainer
47 {
48  enum Types {
49  UnknownType,
50  //Primary highlighting:
51  LocalClassMemberType,
52  InheritedClassMemberType,
53  LocalVariableType,
54 
55  //Other highlighting:
56  ClassType,
57  FunctionType,
58  ForwardDeclarationType,
59  EnumType,
60  EnumeratorType,
61  TypeAliasType,
62  MacroType,
63  MacroFunctionLikeType,
64 
65  //If none of the above match:
66  MemberVariableType,
67  NamespaceVariableType,
68  GlobalVariableType,
69 
70  //Most of these are currently not used:
71  ArgumentType,
72  CodeType,
73  FileType,
74  NamespaceType,
75  ScopeType,
76  TemplateType,
77  TemplateParameterType,
78  FunctionVariableType,
79  ErrorVariableType
80  };
81 
82  enum Contexts {
83  DefinitionContext,
84  DeclarationContext,
85  ReferenceContext
86  };
87 };
88 
89 struct HighlightedRange
90 {
91  RangeInRevision range;
92  KTextEditor::Attribute::Ptr attribute;
93  bool operator<(const HighlightedRange& rhs) const
94  {
95  return range.start < rhs.range.start;
96  }
97 };
98 
103 class KDEVPLATFORMLANGUAGE_EXPORT CodeHighlightingInstance
104  : public HighlightingEnumContainer
105 {
106 public:
107  explicit CodeHighlightingInstance(const CodeHighlighting* highlighting) : m_useClassCache(false)
108  , m_highlighting(highlighting)
109  {
110  }
111  virtual ~CodeHighlightingInstance()
112  {
113  }
114 
115  virtual void highlightDeclaration(KDevelop::Declaration* declaration, const QColor& color);
116  virtual void highlightUse(KDevelop::DUContext* context, int index, const QColor& color);
117  virtual void highlightUses(KDevelop::DUContext* context);
118 
119  void highlightDUChain(KDevelop::TopDUContext* context);
120  void highlightDUChain(KDevelop::DUContext* context, QHash<KDevelop::Declaration*, uint> colorsForDeclarations,
121  ColorMap);
122 
123  KDevelop::Declaration* localClassFromCodeContext(KDevelop::DUContext* context) const;
127  virtual Types typeForDeclaration(KDevelop::Declaration* dec, KDevelop::DUContext* context) const;
132  virtual bool useRainbowColor(KDevelop::Declaration* dec) const;
133 
134  //A temporary hash for speedup
135  mutable QHash<KDevelop::DUContext*, KDevelop::Declaration*> m_contextClasses;
136 
137  //Here the colors of function context are stored until they are merged into the function body
138  mutable QMap<KDevelop::IndexedDUContext, QHash<KDevelop::Declaration*, uint>> m_functionColorsForDeclarations;
139  mutable QMap<KDevelop::IndexedDUContext, ColorMap> m_functionDeclarationsForColors;
140 
141  mutable bool m_useClassCache;
142  const CodeHighlighting* m_highlighting;
143 
144  QVector<HighlightedRange> m_highlight;
145 };
146 
150 class KDEVPLATFORMLANGUAGE_EXPORT CodeHighlighting
151  : public QObject
152  , public KDevelop::ICodeHighlighting
153  , public HighlightingEnumContainer
154 {
155  Q_OBJECT
156  Q_INTERFACES(KDevelop::ICodeHighlighting)
157 
158 public:
159 
160  explicit CodeHighlighting(QObject* parent);
161  ~CodeHighlighting() override;
162 
165  void highlightDUChain(ReferencedTopDUContext context) override;
166 
167  //color should be zero when undecided
168  KTextEditor::Attribute::Ptr attributeForType(Types type, Contexts context, const QColor& color) const;
169  KTextEditor::Attribute::Ptr attributeForDepth(int depth) const;
170 
173  bool hasHighlighting(IndexedString url) const override;
174 
175 private:
176  //Returns whether the given attribute was set by the code highlighting, and not by something else
177  //Always returns true when the attribute is zero
178  bool isCodeHighlight(KTextEditor::Attribute::Ptr attr) const;
179 
180 protected:
181  //Can be overridden to create an own instance type
182  virtual CodeHighlightingInstance* createInstance() const;
183 
184 private:
185 
187  struct DocumentHighlighting
188  {
189  IndexedString m_document;
190  qint64 m_waitingRevision;
191  // The ranges are sorted by range start, so they can easily be matched
192  QVector<HighlightedRange> m_waiting;
193  QVector<KTextEditor::MovingRange*> m_highlightedRanges;
194  };
195 
196  QMap<DocumentChangeTracker*, DocumentHighlighting*> m_highlights;
197 
198  friend class CodeHighlightingInstance;
199 
200  mutable QHash<Types, KTextEditor::Attribute::Ptr> m_definitionAttributes;
201  mutable QHash<Types, KTextEditor::Attribute::Ptr> m_declarationAttributes;
202  mutable QHash<Types, KTextEditor::Attribute::Ptr> m_referenceAttributes;
203  mutable QList<KTextEditor::Attribute::Ptr> m_depthAttributes;
204  // Should be used to enable/disable the colorization of local variables and their uses
205  bool m_localColorization;
206  // Should be used to enable/disable the colorization of global types and their uses
207  bool m_globalColorization;
208 
209  mutable QMutex m_dataMutex;
210 
211 private Q_SLOTS:
212  void clearHighlightingForDocument(const KDevelop::IndexedString& document);
213  void applyHighlighting(void* highlighting);
214 
215  void trackerDestroyed(QObject* object);
216 
218  void adaptToColorChanges();
219 
220  void aboutToInvalidateMovingInterfaceContent(KTextEditor::Document*);
221  void aboutToRemoveText(const KTextEditor::Range&);
222 };
223 }
224 
225 Q_DECLARE_TYPEINFO(KDevelop::HighlightedRange, Q_MOVABLE_TYPE);
226 
227 #endif
KDevelop::HighlightingEnumContainer::FunctionType
Definition: codehighlighting.h:57
KDevelop::CodeHighlightingInstance::m_highlighting
const CodeHighlighting * m_highlighting
Definition: codehighlighting.h:142
KDevelop::HighlightingEnumContainer::TypeAliasType
Definition: codehighlighting.h:61
KDevelop::HighlightingEnumContainer::Contexts
Contexts
Definition: codehighlighting.h:82
QMutex
KDevelop::HighlightedRange::operator<
bool operator<(const HighlightedRange &rhs) const
Definition: codehighlighting.h:93
KDevelop::HighlightingEnumContainer::ErrorVariableType
Definition: codehighlighting.h:79
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(KDevelop::HighlightedRange, Q_MOVABLE_TYPE)
KDevelop::CodeHighlightingInstance::m_functionColorsForDeclarations
QMap< KDevelop::IndexedDUContext, QHash< KDevelop::Declaration *, uint > > m_functionColorsForDeclarations
Definition: codehighlighting.h:138
QMap
KDevelop::CodeHighlightingInstance::m_contextClasses
QHash< KDevelop::DUContext *, KDevelop::Declaration * > m_contextClasses
Definition: codehighlighting.h:135
KDevelop::HighlightingEnumContainer::ArgumentType
Definition: codehighlighting.h:71
KDevelop::HighlightingEnumContainer::LocalVariableType
Definition: codehighlighting.h:53
KDevelop::CodeHighlightingInstance::CodeHighlightingInstance
CodeHighlightingInstance(const CodeHighlighting *highlighting)
Definition: codehighlighting.h:107
KDevelop::HighlightingEnumContainer::ClassType
Definition: codehighlighting.h:56
KDevelop::HighlightedRange
Definition: codehighlighting.h:89
KDevelop::HighlightingEnumContainer::EnumeratorType
Definition: codehighlighting.h:60
KDevelop::HighlightingEnumContainer::Types
Types
Definition: codehighlighting.h:48
KDevelop::HighlightingEnumContainer::NamespaceType
Definition: codehighlighting.h:74
KDevelop::CodeHighlighting
General class representing the code highlighting for one language.
Definition: codehighlighting.h:150
KDevelop::HighlightingEnumContainer::MacroType
Definition: codehighlighting.h:62
KDevelop::HighlightingEnumContainer::NamespaceVariableType
Definition: codehighlighting.h:67
QHash
QObject
KDevelop::HighlightingEnumContainer::UnknownType
Definition: codehighlighting.h:49
KDevelop::HighlightingEnumContainer::FileType
Definition: codehighlighting.h:73
KDevelop::HighlightingEnumContainer::CodeType
Definition: codehighlighting.h:72
QList< KTextEditor::Attribute::Ptr >
QColor
KDevelop::HighlightingEnumContainer::ReferenceContext
Definition: codehighlighting.h:85
KDevelop::CodeHighlightingInstance
Code highlighting instance that is used to apply code highlighting to one specific top context...
Definition: codehighlighting.h:103
KDevelop::HighlightingEnumContainer::EnumType
Definition: codehighlighting.h:59
KDevelop::CodeHighlightingInstance::m_functionDeclarationsForColors
QMap< KDevelop::IndexedDUContext, ColorMap > m_functionDeclarationsForColors
Definition: codehighlighting.h:139
KDevelop::HighlightingEnumContainer::InheritedClassMemberType
Definition: codehighlighting.h:52
KDevelop::HighlightingEnumContainer::LocalClassMemberType
Definition: codehighlighting.h:51
KDevelop::HighlightingEnumContainer::FunctionVariableType
Definition: codehighlighting.h:78
KDevelop::HighlightedRange::range
RangeInRevision range
Definition: codehighlighting.h:91
KDevelop::HighlightingEnumContainer
Definition: codehighlighting.h:46
KDevelop::HighlightingEnumContainer::ForwardDeclarationType
Definition: codehighlighting.h:58
KDevelop::CodeHighlightingInstance::m_highlight
QVector< HighlightedRange > m_highlight
Definition: codehighlighting.h:144
QVector
KDevelop::HighlightingEnumContainer::TemplateType
Definition: codehighlighting.h:76
KDevelop::HighlightingEnumContainer::TemplateParameterType
Definition: codehighlighting.h:77
KDevelop::HighlightingEnumContainer::MacroFunctionLikeType
Declaration of a macro such as "#define FOO".
Definition: codehighlighting.h:63
KDevelop::CodeHighlightingInstance::m_useClassCache
bool m_useClassCache
Definition: codehighlighting.h:141
KDevelop::CodeHighlightingInstance::~CodeHighlightingInstance
virtual ~CodeHighlightingInstance()
Definition: codehighlighting.h:111
KDevelop::HighlightingEnumContainer::MemberVariableType
Declaration of a function like macro such as "#define FOO()".
Definition: codehighlighting.h:66
KDevelop::HighlightingEnumContainer::DeclarationContext
Definition: codehighlighting.h:84
KDevelop::HighlightedRange::attribute
KTextEditor::Attribute::Ptr attribute
Definition: codehighlighting.h:92
KDevelop::HighlightingEnumContainer::ScopeType
Definition: codehighlighting.h:75
KDevelop::HighlightingEnumContainer::GlobalVariableType
Definition: codehighlighting.h:68
KDevelop::HighlightingEnumContainer::DefinitionContext
Definition: codehighlighting.h:83
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Dec 12 2019 03:33:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevelop/kdevplatform/language/highlighting

Skip menu "kdevelop/kdevplatform/language/highlighting"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  •   kdevplatform
  •     debugger
  •     documentation
  •     interfaces
  •     language
  •       assistant
  •       backgroundparser
  •       checks
  •       classmodel
  •       codecompletion
  •       codegen
  •       duchain
  •       editor
  •       highlighting
  •       interfaces
  •       util
  •     outputview
  •     project
  •     serialization
  •     shell
  •     sublime
  •     tests
  •     util
  •     vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal