Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
5c5ef2cc
Commit
5c5ef2cc
authored
May 19, 2021
by
Waqar Ahmed
Browse files
Move everything to SemanticHighlighter
Signed-off-by:
Waqar Ahmed
<
waqar.17a@gmail.com
>
parent
2704109e
Changes
3
Hide whitespace changes
Inline
Side-by-side
addons/lspclient/lspclientpluginview.cpp
View file @
5c5ef2cc
...
...
@@ -627,33 +627,6 @@ public:
}
}
void
doSemanticHighlighting
(
KTextEditor
::
View
*
view
)
{
if
(
!
view
)
{
return
;
}
auto
server
=
m_serverManager
->
findServer
(
view
);
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
&&
server
)
{
const
auto
legend
=
&
server
->
capabilities
().
semanticTokenProvider
.
legend
;
m_semHighlightingManager
.
processTokens
(
st
,
v
,
legend
);
}
};
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
);
}
}
// This is taken from KDevelop :)
KTextEditor
::
View
*
viewFromWidget
(
QWidget
*
widget
)
{
...
...
@@ -2190,7 +2163,7 @@ public:
}
if
(
m_plugin
->
m_semanticHighlighting
)
{
doSemanticHighlighting
(
activeView
);
m_semHighlightingManager
.
doSemanticHighlighting
(
activeView
,
m_serverManager
);
}
if
(
m_onTypeFormattingTriggers
.
empty
())
{
...
...
@@ -2252,21 +2225,8 @@ public:
isClangd
=
lspServer
==
QStringLiteral
(
"clangd"
);
const
bool
semHighlightingEnabled
=
m_plugin
->
m_semanticHighlighting
;
const
bool
serverSupportsSemHighlighting
=
caps
.
semanticTokenProvider
.
full
||
caps
.
semanticTokenProvider
.
fullDelta
;
if
(
semHighlightingEnabled
&&
serverSupportsSemHighlighting
)
{
if
(
doc
)
{
connect
(
doc
,
SIGNAL
(
aboutToInvalidateMovingInterfaceContent
(
KTextEditor
::
Document
*
)),
this
,
SLOT
(
clearSemanticTokensHighlighting
(
KTextEditor
::
Document
*
)),
Qt
::
UniqueConnection
);
connect
(
doc
,
SIGNAL
(
aboutToDeleteMovingInterfaceContent
(
KTextEditor
::
Document
*
)),
this
,
SLOT
(
clearSemanticTokensHighlighting
(
KTextEditor
::
Document
*
)),
Qt
::
UniqueConnection
);
doSemanticHighlighting
(
activeView
);
}
if
(
semHighlightingEnabled
)
{
m_semHighlightingManager
.
doSemanticHighlighting
(
activeView
,
m_serverManager
);
}
}
...
...
@@ -2340,13 +2300,6 @@ public:
}
}
Q_SLOT
void
clearSemanticTokensHighlighting
(
KTextEditor
::
Document
*
doc
)
{
if
(
doc
)
{
m_semHighlightingManager
.
remove
(
doc
);
}
}
void
viewDestroyed
(
QObject
*
view
)
{
m_completionViews
.
remove
(
static_cast
<
KTextEditor
::
View
*>
(
view
));
...
...
addons/lspclient/lspsemantichighlighting.cpp
View file @
5c5ef2cc
...
...
@@ -6,12 +6,72 @@
*/
#include "lspsemantichighlighting.h"
#include "lspclientprotocol.h"
#include "lspclientservermanager.h"
#include "semantic_tokens_legend.h"
#include <KTextEditor/MovingInterface>
#include <KTextEditor/MovingRange>
#include <KTextEditor/View>
SemanticHighlighter
::
SemanticHighlighter
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
void
SemanticHighlighter
::
doSemanticHighlighting
(
KTextEditor
::
View
*
view
,
QSharedPointer
<
LSPClientServerManager
>
serverManager
)
{
if
(
!
view
)
{
return
;
}
auto
server
=
serverManager
->
findServer
(
view
);
if
(
!
server
)
{
return
;
}
const
auto
&
caps
=
server
->
capabilities
();
const
bool
serverSupportsSemHighlighting
=
caps
.
semanticTokenProvider
.
full
||
caps
.
semanticTokenProvider
.
fullDelta
;
if
(
!
serverSupportsSemHighlighting
)
{
return
;
}
auto
doc
=
view
->
document
();
if
(
m_docResultId
.
count
(
doc
)
==
0
)
{
connect
(
doc
,
SIGNAL
(
aboutToInvalidateMovingInterfaceContent
(
KTextEditor
::
Document
*
)),
this
,
SLOT
(
remove
(
KTextEditor
::
Document
*
)),
Qt
::
UniqueConnection
);
connect
(
doc
,
SIGNAL
(
aboutToDeleteMovingInterfaceContent
(
KTextEditor
::
Document
*
)),
this
,
SLOT
(
remove
(
KTextEditor
::
Document
*
)),
Qt
::
UniqueConnection
);
}
// m_semHighlightingManager.setTypes(server->capabilities().semanticTokenProvider.types);
QPointer
<
KTextEditor
::
View
>
v
=
view
;
auto
h
=
[
this
,
v
,
server
](
const
LSPSemanticTokensDelta
&
st
)
{
if
(
v
&&
server
)
{
const
auto
legend
=
&
server
->
capabilities
().
semanticTokenProvider
.
legend
;
processTokens
(
st
,
v
,
legend
);
}
};
if
(
!
server
->
capabilities
().
semanticTokenProvider
.
fullDelta
)
{
server
->
documentSemanticTokensFull
(
doc
->
url
(),
QString
(),
this
,
h
);
}
else
{
auto
prevResultId
=
previousResultIdForDoc
(
doc
);
server
->
documentSemanticTokensFullDelta
(
doc
->
url
(),
prevResultId
,
this
,
h
);
}
}
QString
SemanticHighlighter
::
previousResultIdForDoc
(
KTextEditor
::
Document
*
doc
)
const
{
auto
it
=
m_docResultId
.
find
(
doc
);
if
(
it
!=
m_docResultId
.
end
())
{
return
it
->
second
;
}
return
QString
();
}
void
SemanticHighlighter
::
processTokens
(
const
LSPSemanticTokensDelta
&
tokens
,
KTextEditor
::
View
*
view
,
const
SemanticTokensLegend
*
legend
)
{
Q_ASSERT
(
view
);
...
...
addons/lspclient/lspsemantichighlighting.h
View file @
5c5ef2cc
...
...
@@ -7,6 +7,7 @@
#ifndef LSP_SEMANTIC_HIGHLIGHTING_H
#define LSP_SEMANTIC_HIGHLIGHTING_H
#include <QObject>
#include <QString>
#include <KTextEditor/MovingRange>
...
...
@@ -22,28 +23,27 @@ class Document;
}
class
SemanticTokensLegend
;
class
LSPClientServerManager
;
struct
LSPSemanticTokensDelta
;
class
SemanticHighlighter
class
SemanticHighlighter
:
public
QObject
{
Q_OBJECT
public:
QString
previousResultIdForDoc
(
KTextEditor
::
Document
*
doc
)
const
{
auto
it
=
m_docResultId
.
find
(
doc
);
if
(
it
!=
m_docResultId
.
end
())
{
return
it
->
second
;
}
return
QString
();
}
SemanticHighlighter
(
QObject
*
parent
=
nullptr
);
void
doSemanticHighlighting
(
KTextEditor
::
View
*
v
,
QSharedPointer
<
LSPClientServerManager
>
serverManager
);
private:
QString
previousResultIdForDoc
(
KTextEditor
::
Document
*
doc
)
const
;
/**
* Unregister a doc from highlighter and remove all its associated moving ranges and tokens
*/
void
remove
(
KTextEditor
::
Document
*
doc
);
Q_SLOT
void
remove
(
KTextEditor
::
Document
*
doc
);
void
processTokens
(
const
LSPSemanticTokensDelta
&
tokens
,
KTextEditor
::
View
*
view
,
const
SemanticTokensLegend
*
legend
);
private:
/**
* Does the actual highlighting
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment