Commit b3f73c08 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Make sure unsupported token types don't mess up things


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent 14b6e7b5
......@@ -77,18 +77,18 @@ void SemanticHighlighter::highlight(const QUrl &url)
return;
}
int currentLine = 0;
int start = 0;
uint32_t currentLine = 0;
uint32_t start = 0;
int reusedRanges = 0;
int newRanges = 0;
for (size_t i = 0; i < data.size(); i += 5) {
int deltaLine = data.at(i);
int deltaStart = data.at(i + 1);
int len = data.at(i + 2);
int type = data.at(i + 3);
int mod = data.at(i + 4);
auto deltaLine = data.at(i);
auto deltaStart = data.at(i + 1);
auto len = data.at(i + 2);
auto type = data.at(i + 3);
auto mod = data.at(i + 4);
(void)mod;
currentLine += deltaLine;
......@@ -107,11 +107,13 @@ void SemanticHighlighter::highlight(const QUrl &url)
// Check if we have a moving ranges already available in the cache
const auto index = i / 5;
if (index < movingRanges.size()) {
auto &range = movingRanges[index];
range->setRange(r);
range->setAttribute(m_legend->attrForIndex(type));
reusedRanges++;
continue;
KTextEditor::MovingRange *range = movingRanges[index];
if (range) {
range->setRange(r);
range->setAttribute(m_legend->attrForIndex(type));
reusedRanges++;
continue;
}
}
KTextEditor::MovingRange *mr = miface->newMovingRange(r);
......
......@@ -139,50 +139,52 @@ void SemanticTokensLegend::initialize(const std::vector<QString> &types)
for (const auto &type : types) {
if (type == QStringLiteral("type"))
tokenTypes[i] = TokenType::Type;
if (type == QStringLiteral("class"))
else if (type == QStringLiteral("class"))
tokenTypes[i] = TokenType::Class;
if (type == QStringLiteral("enum"))
else if (type == QStringLiteral("enum"))
tokenTypes[i] = TokenType::Enum;
if (type == QStringLiteral("type"))
else if (type == QStringLiteral("type"))
tokenTypes[i] = TokenType::Type;
if (type == QStringLiteral("interface"))
else if (type == QStringLiteral("interface"))
tokenTypes[i] = TokenType::Interface;
if (type == QStringLiteral("struct"))
else if (type == QStringLiteral("struct"))
tokenTypes[i] = TokenType::Struct;
if (type == QStringLiteral("typeParameter"))
else if (type == QStringLiteral("typeParameter"))
tokenTypes[i] = TokenType::TypeParameter;
if (type == QStringLiteral("parameter"))
else if (type == QStringLiteral("parameter"))
tokenTypes[i] = TokenType::Parameter;
if (type == QStringLiteral("variable"))
else if (type == QStringLiteral("variable"))
tokenTypes[i] = TokenType::Variable;
if (type == QStringLiteral("property"))
else if (type == QStringLiteral("property"))
tokenTypes[i] = TokenType::Property;
if (type == QStringLiteral("enumMember"))
else if (type == QStringLiteral("enumMember"))
tokenTypes[i] = TokenType::EnumMember;
if (type == QStringLiteral("event"))
else if (type == QStringLiteral("event"))
tokenTypes[i] = TokenType::Event;
if (type == QStringLiteral("function"))
else if (type == QStringLiteral("function"))
tokenTypes[i] = TokenType::Function;
if (type == QStringLiteral("method"))
else if (type == QStringLiteral("method"))
tokenTypes[i] = TokenType::Method;
if (type == QStringLiteral("macro"))
else if (type == QStringLiteral("macro"))
tokenTypes[i] = TokenType::Macro;
if (type == QStringLiteral("keyword"))
else if (type == QStringLiteral("keyword"))
tokenTypes[i] = TokenType::Keyword;
if (type == QStringLiteral("modifier"))
else if (type == QStringLiteral("modifier"))
tokenTypes[i] = TokenType::Modifier;
if (type == QStringLiteral("comment"))
else if (type == QStringLiteral("comment"))
tokenTypes[i] = TokenType::Comment; // Can mean inactive code
if (type == QStringLiteral("string"))
else if (type == QStringLiteral("string"))
tokenTypes[i] = TokenType::String;
if (type == QStringLiteral("number"))
else if (type == QStringLiteral("number"))
tokenTypes[i] = TokenType::Number;
if (type == QStringLiteral("regexp"))
else if (type == QStringLiteral("regexp"))
tokenTypes[i] = TokenType::Regexp;
if (type == QStringLiteral("operator"))
else if (type == QStringLiteral("operator"))
tokenTypes[i] = TokenType::Operator;
if (type == QStringLiteral("namespace"))
else if (type == QStringLiteral("namespace"))
tokenTypes[i] = TokenType::Namespace;
else
tokenTypes[i] = TokenType::Unsupported;
i++;
}
totalTokenTypes = tokenTypes.size();
......
......@@ -13,6 +13,7 @@ class Editor;
class SemanticTokensLegend : public QObject
{
enum TokenType {
Unsupported = -1,
Type,
Class,
Enum,
......@@ -53,6 +54,11 @@ public:
return sharedAttrs.at(idx);
}
size_t tokenTypeCount() const
{
return totalTokenTypes;
}
private:
Q_SLOT void themeChange(KTextEditor::Editor *e);
void refresh(const std::vector<TokenType> &m_tokenTypes);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment