fix: truncate context logic

This commit is contained in:
2026-09-30 15:01:28 +02:00
parent a59e4286ad
commit 5fc6fda804
15 changed files with 238 additions and 126 deletions
+5 -6
View File
@@ -37,10 +37,10 @@ class CodeHighlighter : public QObject {
private:
struct State {
bool bad = false; // permanent failure, do not retry
bool bad = false;
void* lib = nullptr;
const void* lang = nullptr; // const TSLanguage*
void* query = nullptr; // TSQuery*
const void* lang = nullptr;
void* query = nullptr;
};
[[nodiscard]] static const QHash<QString, QString>& aliases();
@@ -59,15 +59,14 @@ class CodeHighlighter : public QObject {
const QVariantList& spans) const;
struct SpanCacheEntry {
QString code; // re-compared on lookup; a hash collision can
// never deliver the wrong spans
QString code;
QVariantList spans;
};
mutable QHash<QString, std::shared_ptr<const State>> m_states;
mutable QMutex m_stateMutex;
mutable QHash<QString, SpanCacheEntry> m_spanCache;
mutable QStringList m_spanCacheOrder; // LRU order, oldest first
mutable QStringList m_spanCacheOrder;
mutable int m_spanCacheBytes = 0;
mutable QMutex m_cacheMutex;
static CodeHighlighter* s_instance;