1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef STYLELSP_H
6#define STYLELSP_H
7
8#include <QObject>
9#include <QList>
10
11#include "stylesci.h"
12#include "ScintillaEditBase.h"
13
14#include "common/common.h"
15
16#include <iostream>
17
18class TextEdit;
19class StyleLspPrivate;
20class StyleLsp : public QObject
21{
22 Q_OBJECT
23 StyleLspPrivate *const d;
24public:
25
26 enum Margin
27 {
28 LspCustom = StyleSci::Margin::Custom
29 };
30
31 enum MarkerNumber
32 {
33 Error = StyleSci::MarkerNumber::Extern,
34 Warning,
35 Information,
36 Hint,
37 ErrorLineBackground,
38 WarningLineBackground,
39 InformationLineBackground,
40 HintLineBackground,
41 };
42
43 struct IndicStyleExt
44 {
45 QMap<int, int> fore;
46 };
47
48 enum EOLAnnotation
49 {
50 RedTextFore = 63,
51 };
52
53 static Sci_Position getSciPosition(sptr_t doc, const newlsp::Position &pos);
54 static lsp::Position getLspPosition(sptr_t doc, sptr_t sciPosition);
55 static int getLspCharacter(sptr_t doc, sptr_t sciPosition);
56 static bool isCharSymbol(const char ch);
57
58 StyleLsp(TextEdit *parent);
59 TextEdit *edit();
60 virtual ~StyleLsp();
61
62 virtual void initLspConnection(); //setting main
63
64 virtual IndicStyleExt symbolIndic(lsp::SemanticTokenType::type_value token,
65 QList<lsp::SemanticTokenType::type_index> modifier);
66 /*!
67 * \brief tokenFromServProvider find local token from lsp protocol init response provider data
68 * \param token from token request (tokenFull) key
69 * \return local key
70 */
71 virtual lsp::SemanticTokenType::type_value tokenToDefine(int token);
72
73 virtual void setIndicStyle();
74 virtual void setMargin();
75
76 virtual void setDiagnostics(const newlsp::PublishDiagnosticsParams &data);
77 virtual void cleanDiagnostics();
78
79 virtual void setTokenFull(const QList<lsp::Data> &tokens);
80 virtual void cleanTokenFull();
81
82 virtual void setHover(const newlsp::Hover &hover);
83 virtual void cleanHover();
84
85 virtual void setDefinition(const newlsp::Location &data);
86 virtual void setDefinition(const std::vector<newlsp::Location> &data);
87 virtual void setDefinition(const std::vector<newlsp::LocationLink> &data);
88 virtual void cleanDefinition(const Scintilla::Position &pos);
89
90 virtual void rangeFormattingReplace(const std::vector<newlsp::TextEdit> &edits);
91
92private slots:
93 void setDefinitionSelectedStyle(const Scintilla::Position start,
94 const Scintilla::Position end);
95 void setCompletion(const QByteArray &text,
96 const Scintilla::Position enterLenght,
97 const lsp::CompletionProvider &provider);
98
99 void sciTextInsertedTotal(Scintilla::Position position,
100 Scintilla::Position length, Scintilla::Position linesAdded,
101 const QByteArray &text, Scintilla::Position line);
102
103 void sciTextDeletedTotal(Scintilla::Position position,
104 Scintilla::Position length, Scintilla::Position linesAdded,
105 const QByteArray &text, Scintilla::Position line);
106
107 void sciLinesAdded(Scintilla::Position position);
108 void SciCharAdded(int ch);
109 void sciTextChangedTotal();
110 void sciHovered(Scintilla::Position position);
111 void sciHoverCleaned(Scintilla::Position position);
112 void sciDefinitionHover(Scintilla::Position position);
113 void sciDefinitionHoverCleaned(Scintilla::Position position);
114 void sciIndicClicked(Scintilla::Position position);
115 void sciIndicReleased(Scintilla::Position position);
116 void sciSelectionMenu(QContextMenuEvent *event);
117 void sciReplaced(const QString &file, Scintilla::Position start,
118 Scintilla::Position end, const QString &text);
119 void sciClosed(const QString &file);
120 void renameRequest(const QString &newText);
121};
122
123#endif // STYLELSP_H
124