Commit abbc3f04 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Use a unique and remove tracking of connected views for vertical scroll

parent b2aa879e
......@@ -509,6 +509,7 @@ public:
, m_hover(LSPClientHover::new_(m_serverManager))
, m_forwardHover(new ForwardingTextHintProvider(this))
, m_symbolView(LSPClientSymbolView::new_(plugin, mainWin, m_serverManager))
, m_semHighlightingManager(m_serverManager)
{
connect(m_mainWindow, &KTextEditor::MainWindow::viewChanged, this, &self_type::updateState);
connect(m_mainWindow, &KTextEditor::MainWindow::unhandledShortcutOverride, this, &self_type::handleEsc);
......@@ -2277,7 +2278,7 @@ public:
}
if (m_plugin->m_semanticHighlighting) {
m_semHighlightingManager.doSemanticHighlighting(activeView, m_serverManager);
m_semHighlightingManager.doSemanticHighlighting(activeView);
}
if (m_onTypeFormattingTriggers.empty()) {
......@@ -2340,7 +2341,7 @@ public:
const bool semHighlightingEnabled = m_plugin->m_semanticHighlighting;
if (semHighlightingEnabled) {
m_semHighlightingManager.doSemanticHighlighting(activeView, m_serverManager);
m_semHighlightingManager.doSemanticHighlighting(activeView);
}
}
......
......@@ -13,8 +13,9 @@
#include <KTextEditor/MovingRange>
#include <KTextEditor/View>
SemanticHighlighter::SemanticHighlighter(QObject *parent)
SemanticHighlighter::SemanticHighlighter(QSharedPointer<LSPClientServerManager> serverManager, QObject *parent)
: QObject(parent)
, m_serverManager(std::move(serverManager))
{
}
......@@ -29,13 +30,13 @@ static KTextEditor::Range getCurrentViewLinesRange(KTextEditor::View *view)
return KTextEditor::Range(first, 0, last, lastLineLen);
}
void SemanticHighlighter::doSemanticHighlighting(KTextEditor::View *view, QSharedPointer<LSPClientServerManager> serverManager)
void SemanticHighlighter::doSemanticHighlighting(KTextEditor::View *view)
{
if (!view) {
return;
}
auto server = serverManager->findServer(view);
auto server = m_serverManager->findServer(view);
if (!server) {
return;
}
......@@ -57,24 +58,7 @@ void SemanticHighlighter::doSemanticHighlighting(KTextEditor::View *view, QShare
}
if (caps.semanticTokenProvider.range) {
if (!m_docSemanticConnectedViews.insert(view).second) {
// track vertical scrolling for this view
QPointer<KTextEditor::View> v = view;
connect(
view,
&KTextEditor::View::verticalScrollPositionChanged,
this,
[this, v, serverManager]() {
doSemanticHighlighting(v, serverManager);
},
Qt::UniqueConnection);
// clean it up from our set after the view is gone
connect(view, &KTextEditor::View::destroyed, this, [this](QObject *o) {
auto view = static_cast<KTextEditor::View *>(o);
m_docSemanticConnectedViews.erase(view);
});
}
connect(view, &KTextEditor::View::verticalScrollPositionChanged, this, &SemanticHighlighter::semanticHighlightRange, Qt::UniqueConnection);
}
// m_semHighlightingManager.setTypes(server->capabilities().semanticTokenProvider.types);
......@@ -97,6 +81,11 @@ void SemanticHighlighter::doSemanticHighlighting(KTextEditor::View *view, QShare
}
}
void SemanticHighlighter::semanticHighlightRange(KTextEditor::View *view, const KTextEditor::Cursor &)
{
doSemanticHighlighting(view);
}
QString SemanticHighlighter::previousResultIdForDoc(KTextEditor::Document *doc) const
{
auto it = m_docResultId.find(doc);
......
......@@ -31,11 +31,13 @@ class SemanticHighlighter : public QObject
{
Q_OBJECT
public:
SemanticHighlighter(QObject *parent = nullptr);
SemanticHighlighter(QSharedPointer<LSPClientServerManager> serverManager, QObject *parent = nullptr);
void doSemanticHighlighting(KTextEditor::View *v, QSharedPointer<LSPClientServerManager> serverManager);
void doSemanticHighlighting(KTextEditor::View *v);
private:
void semanticHighlightRange(KTextEditor::View *view, const KTextEditor::Cursor &);
QString previousResultIdForDoc(KTextEditor::Document *doc) const;
/**
......@@ -84,10 +86,6 @@ private:
*/
std::unordered_map<KTextEditor::Document *, TokensData> m_docSemanticInfo;
/**
* Views whose vertical scroll we are tracking for semantic tokens range request.
* This is important, otherwise performance can get really crappy.
*/
std::unordered_set<KTextEditor::View *> m_docSemanticConnectedViews;
QSharedPointer<LSPClientServerManager> m_serverManager;
};
#endif
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