1#ifndef TEXTMATELIB_SYNTAX_HIGHLIGHTER_H
2#define TEXTMATELIB_SYNTAX_HIGHLIGHTER_H
17class SyntaxHighlighter;
18class HighlighterCache;
21struct HighlightedToken {
24 std::vector<std::string> scopes;
27 std::string foregroundColor;
28 std::string backgroundColor;
33 std::string debugInfo;
38 fontStyle(static_cast<int>(
FontStyle::None)),
43struct HighlightedLine {
46 std::vector<HighlightedToken> tokens;
57struct SyntaxHighlightingMetadata {
63 double averageLineTokenizationMs;
67 std::string themeName;
70 SyntaxHighlightingMetadata()
74 averageLineTokenizationMs(0.0),
82class SyntaxHighlighter {
85 std::shared_ptr<IGrammar> grammar;
87 std::shared_ptr<SessionImpl> session;
88 std::unique_ptr<HighlighterCache> cache;
92 uint64_t lastUpdateMs;
99 HighlightedToken tokenToHighlighted(
const IToken& token);
104 ScopeStack* buildScopeStack(
const std::vector<std::string>& scopes);
107 static uint64_t getCurrentTimeMs();
119 std::shared_ptr<IGrammar> gram,
121 bool enableCache =
true
124 ~SyntaxHighlighter();
127 SyntaxHighlighter(
const SyntaxHighlighter&) =
delete;
128 SyntaxHighlighter& operator=(
const SyntaxHighlighter&) =
delete;
131 SyntaxHighlighter(SyntaxHighlighter&&) noexcept = default;
132 SyntaxHighlighter& operator=(SyntaxHighlighter&&) noexcept = default;
140 void setDocument(const std::vector<std::
string>& lines);
145 void editLine(
int lineIndex, const std::
string& newContent);
150 void insertLines(
int startIndex, const std::vector<std::
string>& lines);
155 void removeLines(
int startIndex,
int count);
158 int getLineCount() const;
168 HighlightedLine getHighlightedLine(
int lineIndex);
175 std::vector<HighlightedLine> getHighlightedRange(
int startIndex,
int endIndex);
181 std::vector<IToken> getLineTokens(
int lineIndex);
190 void setTheme(Theme* newTheme);
194 Theme* getTheme() const;
207 void invalidateCacheRange(
int startIndex,
int endIndex);
215 SyntaxHighlightingMetadata getMetadata() const;
219 SessionImpl* getSession() const;
224class HighlighterCache {
227 HighlightedLine line;
231 std::map<int, CachedEntry> lineCache;
234 HighlighterCache() =
default;
235 ~HighlighterCache() =
default;
238 HighlighterCache(
const HighlighterCache&) =
delete;
239 HighlighterCache& operator=(
const HighlighterCache&) =
delete;
245 HighlightedLine* getCachedLine(
int lineIndex, uint64_t version);
250 void cacheLine(
const HighlightedLine& line, uint64_t version);
254 void invalidateLine(
int lineIndex);
259 void invalidateRange(
int startIndex,
int endIndex);
265 size_t getCachedLineCount()
const;
FontStyle
Font styling attributes (italic, bold, underline, strikethrough)
StandardTokenType
Standard TextMate token type for syntax classification.
@ Other
Not a recognized standard type.
Core type definitions and interfaces for TextMateLib.