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