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
6d44fc0c
Commit
6d44fc0c
authored
May 16, 2021
by
Waqar Ahmed
Browse files
Use one callback for both delta and full
This is because delta can easily handle result for full as well.
parent
8a382bc2
Changes
5
Hide whitespace changes
Inline
Side-by-side
addons/lspclient/lspclientpluginview.cpp
View file @
6d44fc0c
...
...
@@ -636,36 +636,28 @@ public:
auto
server
=
m_serverManager
->
findServer
(
view
);
if
(
server
)
{
auto
re
q
Id
=
m_semHighlightingManager
.
resultIdForDoc
(
view
->
document
());
auto
re
sult
Id
=
m_semHighlightingManager
.
resultIdForDoc
(
view
->
document
());
m_semHighlightingManager
.
setLegend
(
&
server
->
capabilities
().
semanticTokenProvider
.
legend
);
// m_semHighlightingManager.setTypes(server->capabilities().semanticTokenProvider.types);
/**
* Full delta only if server supports it or if we don't have a result ID for this document
*/
if
(
reqId
.
isEmpty
()
||
!
server
->
capabilities
().
semanticTokenProvider
.
fullDelta
)
{
auto
h
=
[
this
,
view
](
const
LSPSemanticTokens
&
st
)
{
auto
doc
=
view
->
document
();
m_semHighlightingManager
.
setCurrentView
(
view
);
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
doc
=
view
->
document
();
m_semHighlightingManager
.
setCurrentView
(
view
);
for
(
const
auto
&
semTokenEdit
:
st
.
edits
)
{
m_semHighlightingManager
.
update
(
doc
,
st
.
resultId
,
semTokenEdit
.
start
,
semTokenEdit
.
deleteCount
,
semTokenEdit
.
data
);
}
auto
h
=
[
this
,
view
](
const
LSPSemanticTokensDelta
&
st
)
{
auto
doc
=
view
->
document
(
);
m_semHighlightingManager
.
setCurrentView
(
view
);
if
(
!
st
.
data
.
empty
())
{
m_semHighlightingManager
.
insert
(
doc
,
st
.
resultId
,
st
.
data
);
}
m_semHighlightingManager
.
highlight
(
doc
);
};
for
(
const
auto
&
semTokenEdit
:
st
.
edits
)
{
m_semHighlightingManager
.
update
(
doc
,
st
.
resultId
,
semTokenEdit
.
start
,
semTokenEdit
.
deleteCount
,
semTokenEdit
.
data
);
}
server
->
documentSemanticTokensFullDelta
(
view
->
document
()
->
url
(),
reqId
,
this
,
h
);
if
(
!
st
.
data
.
empty
())
{
m_semHighlightingManager
.
insert
(
doc
,
st
.
resultId
,
st
.
data
);
}
m_semHighlightingManager
.
highlight
(
doc
);
};
if
(
!
server
->
capabilities
().
semanticTokenProvider
.
fullDelta
)
{
server
->
documentSemanticTokensFull
(
view
->
document
()
->
url
(),
resultId
,
this
,
h
);
}
else
{
server
->
documentSemanticTokensFullDelta
(
view
->
document
()
->
url
(),
resultId
,
this
,
h
);
}
}
}
...
...
addons/lspclient/lspclientprotocol.h
View file @
6d44fc0c
...
...
@@ -342,11 +342,6 @@ struct LSPSemanticTokensEdit {
std
::
vector
<
uint32_t
>
data
;
};
struct
LSPSemanticTokens
{
QString
resultId
;
std
::
vector
<
uint32_t
>
data
;
};
struct
LSPSemanticTokensDelta
{
QString
resultId
;
std
::
vector
<
LSPSemanticTokensEdit
>
edits
;
...
...
addons/lspclient/lspclientserver.cpp
View file @
6d44fc0c
...
...
@@ -277,7 +277,6 @@ static void from_json(LSPSemanticTokensOptions &options, const QJsonObject &json
if
(
json
.
value
(
QStringLiteral
(
"full"
)).
isObject
())
{
auto
full
=
json
.
value
(
QStringLiteral
(
"full"
)).
toObject
();
options
.
fullDelta
=
full
.
value
(
QStringLiteral
(
"delta"
)).
toBool
();
options
.
full
=
options
.
fullDelta
;
}
else
{
options
.
full
=
json
.
value
(
QStringLiteral
(
"full"
)).
toBool
();
}
...
...
@@ -737,26 +736,9 @@ static QJsonArray supportedSemanticTokenTypes()
QStringLiteral
(
"regexp"
),
QStringLiteral
(
"operator"
)});
}
static
LSPSemanticTokens
parseSemanticTokens
(
const
QJsonValue
&
result
)
{
LSPSemanticTokens
ret
;
auto
json
=
result
.
toObject
();
ret
.
resultId
=
json
.
value
(
QStringLiteral
(
"resultId"
)).
toString
();
if
(
ret
.
resultId
.
isEmpty
())
{
qCDebug
(
LSPCLIENT
)
<<
"unexpected emtpy result id when parsing semantic tokens"
;
return
ret
;
}
auto
data
=
json
.
value
(
QStringLiteral
(
"data"
)).
toArray
();
ret
.
data
.
reserve
(
data
.
size
());
std
::
transform
(
data
.
cbegin
(),
data
.
cend
(),
std
::
back_inserter
(
ret
.
data
),
[](
const
QJsonValue
&
jv
)
{
return
jv
.
toInt
();
});
return
ret
;
}
/**
* Used for both delta and full
*/
static
LSPSemanticTokensDelta
parseSemanticTokensDelta
(
const
QJsonValue
&
result
)
{
LSPSemanticTokensDelta
ret
;
...
...
@@ -770,12 +752,6 @@ static LSPSemanticTokensDelta parseSemanticTokensDelta(const QJsonValue &result)
return
ret
;
}
/**
* Intentionally disabled as "edits" part is already being handled by MovingRange
*
* Any new text that is entered is sent as new data that replaces all old data.
*
*/
auto
edits
=
json
.
value
(
QStringLiteral
(
"edits"
)).
toArray
();
for
(
const
auto
&
edit_jsonValue
:
edits
)
{
...
...
@@ -1605,9 +1581,9 @@ LSPClientServer::RequestHandle LSPClientServer::documentCodeAction(const QUrl &d
}
LSPClientServer
::
RequestHandle
LSPClientServer
::
documentSemanticTokensFull
(
const
QUrl
&
document
,
const
QString
requestId
,
const
QObject
*
context
,
const
SemanticTokensReplyHandler
&
h
)
LSPClientServer
::
documentSemanticTokensFull
(
const
QUrl
&
document
,
const
QString
requestId
,
const
QObject
*
context
,
const
SemanticTokens
Delta
ReplyHandler
&
h
)
{
return
d
->
documentSemanticTokensFull
(
document
,
/* delta = */
false
,
requestId
,
make_handler
(
h
,
context
,
parseSemanticTokens
));
return
d
->
documentSemanticTokensFull
(
document
,
/* delta = */
false
,
requestId
,
make_handler
(
h
,
context
,
parseSemanticTokens
Delta
));
}
LSPClientServer
::
RequestHandle
LSPClientServer
::
documentSemanticTokensFullDelta
(
const
QUrl
&
document
,
...
...
addons/lspclient/lspclientserver.h
View file @
6d44fc0c
...
...
@@ -64,7 +64,6 @@ using CodeActionReplyHandler = ReplyHandler<QList<LSPCodeAction>>;
using
WorkspaceEditReplyHandler
=
ReplyHandler
<
LSPWorkspaceEdit
>
;
using
ApplyEditReplyHandler
=
ReplyHandler
<
LSPApplyWorkspaceEditResponse
>
;
using
SwitchSourceHeaderHandler
=
ReplyHandler
<
QString
>
;
using
SemanticTokensReplyHandler
=
ReplyHandler
<
LSPSemanticTokens
>
;
using
SemanticTokensDeltaReplyHandler
=
ReplyHandler
<
LSPSemanticTokensDelta
>
;
class
LSPClientPlugin
;
...
...
@@ -150,7 +149,7 @@ public:
const
QObject
*
context
,
const
CodeActionReplyHandler
&
h
);
RequestHandle
documentSemanticTokensFull
(
const
QUrl
&
document
,
const
QString
requestId
,
const
QObject
*
context
,
const
SemanticTokensReplyHandler
&
h
);
RequestHandle
documentSemanticTokensFull
(
const
QUrl
&
document
,
const
QString
requestId
,
const
QObject
*
context
,
const
SemanticTokens
Delta
ReplyHandler
&
h
);
RequestHandle
documentSemanticTokensFullDelta
(
const
QUrl
&
document
,
const
QString
requestId
,
const
QObject
*
context
,
const
SemanticTokensDeltaReplyHandler
&
h
);
...
...
addons/lspclient/lspsemantichighlighting.cpp
View file @
6d44fc0c
...
...
@@ -23,9 +23,7 @@ void SemanticHighlighter::remove(KTextEditor::Document *doc)
auto
&
movingRanges
=
it
->
movingRanges
;
for
(
auto
mr
:
movingRanges
)
{
delete
mr
;
mr
=
nullptr
;
}
movingRanges
.
clear
();
m_docSemanticInfo
.
remove
(
doc
);
}
...
...
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