File indexing completed on 2024-04-28 05:49:01

0001 /*
0002     SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 #pragma once
0007 
0008 #include <QObject>
0009 
0010 #include <KTextEditor/Attribute>
0011 
0012 namespace KTextEditor
0013 {
0014 class Editor;
0015 }
0016 
0017 class SemanticTokensLegend : public QObject
0018 {
0019     enum TokenType {
0020         Unsupported = -1,
0021         Type,
0022         Class,
0023         Enum,
0024         Interface,
0025         Struct,
0026         TypeParameter,
0027         Parameter,
0028         Variable,
0029         Property,
0030         EnumMember,
0031         Event,
0032         Function,
0033         Method,
0034         Macro,
0035         Keyword,
0036         Modifier,
0037         Comment,
0038         String,
0039         Number,
0040         Regexp,
0041         Operator,
0042         Namespace
0043     };
0044 
0045 public:
0046     explicit SemanticTokensLegend(QObject *parent = nullptr);
0047 
0048     /**
0049      * Called from LSP Server when capabilities are recieved
0050      */
0051     void initialize(const std::vector<QString> &types);
0052 
0053     KTextEditor::Attribute::Ptr attributeForTokenType(size_t idx) const
0054     {
0055         if (idx >= totalTokenTypes) {
0056             return {};
0057         }
0058         return sharedAttrs.at(idx);
0059     }
0060 
0061     size_t tokenTypeCount() const
0062     {
0063         return totalTokenTypes;
0064     }
0065 
0066 private:
0067     Q_SLOT void themeChange(KTextEditor::Editor *e);
0068     void refresh(const std::vector<TokenType> &m_tokenTypes);
0069 
0070     size_t totalTokenTypes;
0071     std::vector<KTextEditor::Attribute::Ptr> sharedAttrs;
0072     KTextEditor::Attribute::Ptr fixedAttrs[7];
0073 };