| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "stylelspcpp.h" |
| 6 | #include "textedittabwidget/textedit.h" |
| 7 | #include "textedittabwidget/style/stylecolor.h" |
| 8 | #include "textedittabwidget/style/stylejsonfile.h" |
| 9 | #include "common/common.h" |
| 10 | |
| 11 | #include <QDir> |
| 12 | #include <QJsonObject> |
| 13 | #include <QRegularExpression> |
| 14 | |
| 15 | StyleLspCpp::StyleLspCpp(TextEdit *parent) |
| 16 | : StyleLsp (parent) |
| 17 | { |
| 18 | |
| 19 | } |
| 20 | |
| 21 | StyleLsp::IndicStyleExt StyleLspCpp::symbolIndic(lsp::SemanticTokenType::type_value token, |
| 22 | QList<lsp::SemanticTokenModifier::type_index> modifier) |
| 23 | { |
| 24 | Q_UNUSED(modifier); |
| 25 | IndicStyleExt result; |
| 26 | |
| 27 | auto jsonFile = edit()->getStyleFile(); |
| 28 | if (jsonFile->setTheme(StyleJsonFile::Theme::get()->Dark)) { |
| 29 | QJsonObject tempObj; |
| 30 | int tempFore = 0; |
| 31 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Self).toObject(); |
| 32 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 33 | if (lsp::SemanticTokenType::get()->Namespace == token) { |
| 34 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Namespace).toObject(); |
| 35 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 36 | } |
| 37 | if (lsp::SemanticTokenType::get()->Type == token) { |
| 38 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Type).toObject(); |
| 39 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 40 | } |
| 41 | if (lsp::SemanticTokenType::get()->Class == token) { |
| 42 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Class).toObject(); |
| 43 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 44 | } |
| 45 | if (lsp::SemanticTokenType::get()->Enum == token) { |
| 46 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Enumeration).toObject(); |
| 47 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 48 | } |
| 49 | if (lsp::SemanticTokenType::get()->Interface == token) { |
| 50 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Text).toObject(); |
| 51 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 52 | } |
| 53 | if (lsp::SemanticTokenType::get()->Struct == token) { |
| 54 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Text).toObject(); |
| 55 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 56 | } |
| 57 | if (lsp::SemanticTokenType::get()->TypeParameter == token) { |
| 58 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Variable).toObject(); |
| 59 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 60 | } |
| 61 | if (lsp::SemanticTokenType::get()->Parameter == token) { |
| 62 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Parameter).toObject(); |
| 63 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 64 | } |
| 65 | if (lsp::SemanticTokenType::get()->Variable == token) { |
| 66 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Variable).toObject(); |
| 67 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 68 | } |
| 69 | if (lsp::SemanticTokenType::get()->Property == token) { |
| 70 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Property).toObject(); |
| 71 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 72 | } |
| 73 | if (lsp::SemanticTokenType::get()->EnumMember == token) { |
| 74 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Enumeration).toObject(); |
| 75 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 76 | } |
| 77 | if (lsp::SemanticTokenType::get()->Event == token) { |
| 78 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Text).toObject(); |
| 79 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 80 | } |
| 81 | if (lsp::SemanticTokenType::get()->Function == token) { |
| 82 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Function).toObject(); |
| 83 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 84 | } |
| 85 | if (lsp::SemanticTokenType::get()->Method == token){ |
| 86 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Method).toObject(); |
| 87 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 88 | } |
| 89 | if (lsp::SemanticTokenType::get()->Macro == token) { |
| 90 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Macro).toObject(); |
| 91 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 92 | } |
| 93 | if (lsp::SemanticTokenType::get()->Keyword == token) { |
| 94 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Keyword).toObject(); |
| 95 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 96 | } |
| 97 | if (lsp::SemanticTokenType::get()->Modifier == token) { |
| 98 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Text).toObject(); |
| 99 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 100 | } |
| 101 | if (lsp::SemanticTokenType::get()->Comment == token) { |
| 102 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Comment).toObject(); |
| 103 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 104 | } |
| 105 | if (lsp::SemanticTokenType::get()->String == token){ |
| 106 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->String).toObject(); |
| 107 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 108 | } |
| 109 | if (lsp::SemanticTokenType::get()->Number == token) { |
| 110 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Number).toObject(); |
| 111 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 112 | } |
| 113 | if (lsp::SemanticTokenType::get()->Regexp == token) { |
| 114 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->String).toObject(); |
| 115 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 116 | } |
| 117 | if (lsp::SemanticTokenType::get()->Operator == token) { |
| 118 | tempObj = jsonFile->value(StyleJsonFile::Key_1::get()->Operators).toObject(); |
| 119 | tempFore = StyleColor::color(tempObj.value(StyleJsonFile::Key_2::get()->Foreground).toString().toInt(nullptr, 16)); |
| 120 | } |
| 121 | result.fore[INDIC_TEXTFORE] = tempFore; |
| 122 | } |
| 123 | return result; |
| 124 | } |
| 125 | |