-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsyntaxhighlighter.h
More file actions
45 lines (37 loc) · 1.44 KB
/
syntaxhighlighter.h
File metadata and controls
45 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef SYNTAXHIGHLIGHTER_H
#define SYNTAXHIGHLIGHTER_H
#include <QTextDocument>
#include <QTextLayout>
#include <QTextCharFormat>
#include <QString>
#include <QList>
#include <QSet>
#include <tree_sitter/api.h>
// Structure for storing highlight block information
struct HighlightBlock {
int startPosition;
int length;
QString type; // The highlighting type/category
bool operator==(const HighlightBlock& other) const {
return startPosition == other.startPosition &&
length == other.length &&
type == other.type;
}
};
class SyntaxHighlighter {
public:
// Convert tree-sitter tree into list of highlight blocks
QList<HighlightBlock> getHighlightBlocks(TSNode root, uint32_t start, uint32_t end);
void setLanguage(QString language);
// Apply highlighting only where needed
void fullDocRehighlight(QTextDocument* document, TSTree* tree);
void updateHighlighting(QTextDocument* document, int cursorPos, int addedLen, TSTree* oldTree, TSTree* newTree, bool forceFull);
void setFormats(QList<QTextCharFormat> newFormats);
std::unordered_map<QString, int> colormap;
private:
int specificPythonFix(QStringList parents, QStringList PAT, QString following);
void traverseNode(QStringList parents, QString p, TSNode node, QList<HighlightBlock>& blocks, uint32_t start, uint32_t end, QList<QString> siblings);
bool shouldHighlight(TSNode node);
QTextCharFormat getFormatForType(const QString& parentAndType);
};
#endif // SYNTAXHIGHLIGHTER_H