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