Commit 550c63f1 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Use Document* as key


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent b3f73c08
......@@ -636,7 +636,7 @@ public:
auto server = m_serverManager->findServer(view);
if (server) {
auto reqId = m_semHighlightingManager.resultIdForDoc(view->document()->url());
auto reqId = m_semHighlightingManager.resultIdForDoc(view->document());
m_semHighlightingManager.setLegend(&server->capabilities().semanticTokenProvider.legend);
// m_semHighlightingManager.setTypes(server->capabilities().semanticTokenProvider.types);
/**
......@@ -644,25 +644,25 @@ public:
*/
if (reqId.isEmpty() || !server->capabilities().semanticTokenProvider.fullDelta) {
auto h = [this, view](const LSPSemanticTokens &st) {
auto url = view->document()->url();
auto doc = view->document();
m_semHighlightingManager.setCurrentView(view);
m_semHighlightingManager.insert(url, st.resultId, st.data);
m_semHighlightingManager.highlight(url);
m_semHighlightingManager.insert(doc, st.resultId, st.data);
m_semHighlightingManager.highlight(doc);
};
server->documentSemanticTokensFull(view->document()->url(), {}, this, h);
} else {
auto h = [this, view](const LSPSemanticTokensDelta &st) {
auto url = view->document()->url();
auto doc = view->document();
m_semHighlightingManager.setCurrentView(view);
for (const auto &semTokenEdit : st.edits) {
m_semHighlightingManager.update(url, st.resultId, semTokenEdit.start, semTokenEdit.deleteCount, semTokenEdit.data);
m_semHighlightingManager.update(doc, st.resultId, semTokenEdit.start, semTokenEdit.deleteCount, semTokenEdit.data);
}
if (!st.data.empty()) {
m_semHighlightingManager.insert(url, st.resultId, st.data);
m_semHighlightingManager.insert(doc, st.resultId, st.data);
}
m_semHighlightingManager.highlight(url);
m_semHighlightingManager.highlight(doc);
};
server->documentSemanticTokensFullDelta(view->document()->url(), reqId, this, h);
......@@ -2281,11 +2281,6 @@ public:
this,
SLOT(clearSemanticTokensHighlighting(KTextEditor::Document *)),
Qt::UniqueConnection);
connect(doc,
SIGNAL(aboutToClose(KTextEditor::Document *)),
this,
SLOT(clearSemanticTokensHighlighting(KTextEditor::Document *)),
Qt::UniqueConnection);
doSemanticHighlighting(activeView);
}
}
......@@ -2364,7 +2359,7 @@ public:
Q_SLOT void clearSemanticTokensHighlighting(KTextEditor::Document *doc)
{
if (doc) {
m_semHighlightingManager.remove(doc->url());
m_semHighlightingManager.remove(doc);
}
}
......
......@@ -5,11 +5,11 @@
#include "semantic_tokens_legend.h"
void SemanticHighlighter::remove(const QUrl &url)
void SemanticHighlighter::remove(KTextEditor::Document *doc)
{
m_docUrlToResultId.remove(url);
m_docUrlToResultId.remove(doc);
auto it = m_docSemanticInfo.find(url);
auto it = m_docSemanticInfo.find(doc);
if (it == m_docSemanticInfo.end()) {
return;
}
......@@ -20,22 +20,22 @@ void SemanticHighlighter::remove(const QUrl &url)
mr = nullptr;
}
movingRanges.clear();
m_docSemanticInfo.remove(url);
m_docSemanticInfo.remove(doc);
}
void SemanticHighlighter::insert(const QUrl &url, const QString &resultId, const std::vector<uint32_t> &data)
void SemanticHighlighter::insert(KTextEditor::Document *doc, const QString &resultId, const std::vector<uint32_t> &data)
{
m_docUrlToResultId[url] = resultId;
TokensData &tokensData = m_docSemanticInfo[url];
m_docUrlToResultId[doc] = resultId;
TokensData &tokensData = m_docSemanticInfo[doc];
tokensData.tokens = data;
}
/**
* Handle semantic tokens edits
*/
void SemanticHighlighter::update(const QUrl &url, const QString &resultId, uint32_t start, uint32_t deleteCount, const std::vector<uint32_t> &data)
void SemanticHighlighter::update(KTextEditor::Document *doc, const QString &resultId, uint32_t start, uint32_t deleteCount, const std::vector<uint32_t> &data)
{
auto toks = m_docSemanticInfo.find(url);
auto toks = m_docSemanticInfo.find(doc);
if (toks == m_docSemanticInfo.end()) {
return;
}
......@@ -49,10 +49,10 @@ void SemanticHighlighter::update(const QUrl &url, const QString &resultId, uint3
existingTokens.insert(existingTokens.begin() + start, data.begin(), data.end());
// Update result Id
m_docUrlToResultId[url] = resultId;
m_docUrlToResultId[doc] = resultId;
}
void SemanticHighlighter::highlight(const QUrl &url)
void SemanticHighlighter::highlight(KTextEditor::Document *doc)
{
Q_ASSERT(m_legend);
......@@ -60,7 +60,6 @@ void SemanticHighlighter::highlight(const QUrl &url)
return;
}
auto doc = view->document();
if (!doc) {
qWarning() << "View doesn't have doc!";
return;
......@@ -68,12 +67,12 @@ void SemanticHighlighter::highlight(const QUrl &url)
auto miface = qobject_cast<KTextEditor::MovingInterface *>(doc);
TokensData &semanticData = m_docSemanticInfo[url];
TokensData &semanticData = m_docSemanticInfo[doc];
auto &movingRanges = semanticData.movingRanges;
auto &data = semanticData.tokens;
if (data.size() % 5 != 0) {
qWarning() << "Bad data for doc: " << url << " skipping";
qWarning() << "Bad data for doc: " << doc->url() << " skipping";
return;
}
......@@ -99,8 +98,8 @@ void SemanticHighlighter::highlight(const QUrl &url)
start = deltaStart;
}
QString text = doc->line(currentLine);
text = text.mid(start, len);
// QString text = doc->line(currentLine);
// text = text.mid(start, len);
KTextEditor::Range r(currentLine, start, currentLine, start + len);
......
......@@ -18,17 +18,17 @@ public:
/**
* Does the actual highlighting
*/
void highlight(const QUrl &url);
void highlight(KTextEditor::Document *doc);
/**
* Insert tokens @p data for doc with @p url
*/
void insert(const QUrl &url, const QString &resultId, const std::vector<uint32_t> &data);
void insert(KTextEditor::Document *doc, const QString &resultId, const std::vector<uint32_t> &data);
/**
* Unregister a doc from highlighter and remove all its moving ranges and tokens
*/
void remove(const QUrl &url);
void remove(KTextEditor::Document *doc);
/**
* This function is more or less useless for Kate? Maybe because MovingRange already handles this for us
......@@ -37,11 +37,11 @@ public:
* 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.
*/
void update(const QUrl &url, const QString &resultId, uint32_t start, uint32_t deleteCount, const std::vector<uint32_t> &data);
void update(KTextEditor::Document *doc, const QString &resultId, uint32_t start, uint32_t deleteCount, const std::vector<uint32_t> &data);
QString resultIdForDoc(const QUrl &url) const
QString resultIdForDoc(KTextEditor::Document *doc) const
{
return m_docUrlToResultId.value(url);
return m_docUrlToResultId.value(doc);
}
void setCurrentView(KTextEditor::View *v)
......@@ -77,12 +77,12 @@ private:
/**
* Doc => result-id mapping
*/
QHash<QUrl, QString> m_docUrlToResultId;
QHash<KTextEditor::Document *, QString> m_docUrlToResultId;
/**
* semantic token and moving range mapping for doc
*/
QHash<QUrl, TokensData> m_docSemanticInfo;
QHash<KTextEditor::Document *, TokensData> m_docSemanticInfo;
/**
* Legend which is basically used to fetch color for a type
......
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