Commit 2704109e authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Remove unused includes + clean up comments and some renaming

parent 53098231
......@@ -362,7 +362,6 @@ class LSPClientActionView : public QObject
// applied search ranges
typedef QMultiHash<KTextEditor::Document *, KTextEditor::MovingRange *> RangeCollection;
RangeCollection m_ranges;
QHash<KTextEditor::Document *, QHash<int, QVector<KTextEditor::MovingRange *>>> m_semanticHighlightRanges;
// applied marks
typedef QSet<KTextEditor::Document *> DocumentCollection;
DocumentCollection m_marks;
......@@ -633,26 +632,25 @@ public:
if (!view) {
return;
}
auto server = m_serverManager->findServer(view);
if (server) {
// m_semHighlightingManager.setTypes(server->capabilities().semanticTokenProvider.types);
if (!server) {
return;
}
// m_semHighlightingManager.setTypes(server->capabilities().semanticTokenProvider.types);
QPointer<KTextEditor::View> v = view;
auto h = [this, v, server](const LSPSemanticTokensDelta &st) {
if (!v) {
return;
}
QPointer<KTextEditor::View> v = view;
auto h = [this, v, server](const LSPSemanticTokensDelta &st) {
if (v && server) {
const auto legend = &server->capabilities().semanticTokenProvider.legend;
m_semHighlightingManager.processTokens(st, v, legend);
};
auto resultId = m_semHighlightingManager.resultIdForDoc(view->document());
if (!server->capabilities().semanticTokenProvider.fullDelta) {
server->documentSemanticTokensFull(view->document()->url(), resultId, this, h);
} else {
server->documentSemanticTokensFullDelta(view->document()->url(), resultId, this, h);
}
};
auto prevResultId = m_semHighlightingManager.previousResultIdForDoc(view->document());
if (!server->capabilities().semanticTokenProvider.fullDelta) {
server->documentSemanticTokensFull(view->document()->url(), QString(), this, h);
} else {
server->documentSemanticTokensFullDelta(view->document()->url(), prevResultId, this, h);
}
}
......
......@@ -9,6 +9,7 @@
#include "semantic_tokens_legend.h"
#include <KTextEditor/MovingInterface>
#include <KTextEditor/MovingRange>
#include <KTextEditor/View>
void SemanticHighlighter::processTokens(const LSPSemanticTokensDelta &tokens, KTextEditor::View *view, const SemanticTokensLegend *legend)
......@@ -112,14 +113,14 @@ void SemanticHighlighter::highlight(KTextEditor::View *view, const SemanticToken
auto &range = movingRanges[index];
if (range) {
range->setRange(r);
range->setAttribute(legend->attrForIndex(type));
range->setAttribute(legend->attributeForTokenType(type));
reusedRanges++;
continue;
}
}
std::unique_ptr<KTextEditor::MovingRange> mr(miface->newMovingRange(r));
mr->setAttribute(legend->attrForIndex(type));
mr->setAttribute(legend->attributeForTokenType(type));
movingRanges.push_back(std::move(mr));
newRanges++;
......
......@@ -7,15 +7,19 @@
#ifndef LSP_SEMANTIC_HIGHLIGHTING_H
#define LSP_SEMANTIC_HIGHLIGHTING_H
#include <QHash>
#include <QPointer>
#include <QString>
#include <QUrl>
#include <QVector>
#include <KTextEditor/Attribute>
#include <KTextEditor/MovingRange>
#include <KTextEditor/View>
#include <memory>
#include <unordered_map>
#include <vector>
namespace KTextEditor
{
class View;
class Document;
}
class SemanticTokensLegend;
struct LSPSemanticTokensDelta;
......@@ -23,7 +27,7 @@ struct LSPSemanticTokensDelta;
class SemanticHighlighter
{
public:
QString resultIdForDoc(KTextEditor::Document *doc) const
QString previousResultIdForDoc(KTextEditor::Document *doc) const
{
auto it = m_docResultId.find(doc);
if (it != m_docResultId.end()) {
......@@ -46,16 +50,12 @@ private:
void highlight(KTextEditor::View *view, const SemanticTokensLegend *legend);
/**
* Insert tokens @p data for doc with @p url
* Insert new incoming tokens @p data for doc with @p url
*/
void insert(KTextEditor::Document *doc, const QString &resultId, const std::vector<uint32_t> &data);
/**
* This function is more or less useless for Kate? Maybe because MovingRange already handles this for us
*
* An update or SemanticTokensEdit only arrives if you entered a new line or something trivial. If you insert new characters you
* get a full new vector with new data which has to be replaced with the old and everything rehighlighted. This is the behaviour of
* clangd, not sure about others.
* Handle SemanticTokensEdits
*/
void update(KTextEditor::Document *doc, const QString &resultId, uint32_t start, uint32_t deleteCount, const std::vector<uint32_t> &data);
......@@ -69,7 +69,7 @@ private:
};
/**
* token types specified in server caps. Uncomment for debuggin
* token types specified in server caps. Uncomment for debugging
*/
// QVector<QString> m_types;
......
......@@ -52,7 +52,7 @@ public:
*/
void initialize(const std::vector<QString> &types);
KTextEditor::Attribute::Ptr attrForIndex(int idx) const
KTextEditor::Attribute::Ptr attributeForTokenType(int idx) const
{
if (idx >= totalTokenTypes) {
return {};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment