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
78fef2e6
Commit
78fef2e6
authored
Jun 11, 2021
by
Waqar Ahmed
Browse files
workspace/symbols response parsing
Signed-off-by:
Waqar Ahmed
<
waqar.17a@gmail.com
>
parent
6b80bd9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
addons/lspclient/lspclientprotocol.h
View file @
78fef2e6
...
...
@@ -162,9 +162,22 @@ enum class LSPSymbolKind {
Number
=
16
,
Boolean
=
17
,
Array
=
18
,
Object
=
19
,
Key
=
20
,
Null
=
21
,
EnumMember
=
22
,
Struct
=
23
,
Event
=
24
,
Operator
=
25
,
TypeParameter
=
26
,
};
enum
class
LSPSymbolTag
:
uint8_t
{
Deprecated
=
1
,
};
struct
LSPSymbolInformation
{
LSPSymbolInformation
()
=
default
;
LSPSymbolInformation
(
const
QString
&
_name
,
LSPSymbolKind
_kind
,
LSPRange
_range
,
const
QString
&
_detail
)
:
name
(
_name
)
,
detail
(
_detail
)
...
...
@@ -175,7 +188,10 @@ struct LSPSymbolInformation {
QString
name
;
QString
detail
;
LSPSymbolKind
kind
;
QUrl
url
;
LSPRange
range
;
double
score
=
0.0
;
LSPSymbolTag
tags
;
QList
<
LSPSymbolInformation
>
children
;
};
...
...
addons/lspclient/lspclientserver.cpp
View file @
78fef2e6
...
...
@@ -804,10 +804,35 @@ static LSPShowMessageParams parseMessage(const QJsonObject &result)
return
ret
;
}
static
QString
parseWorkspaceSymbols
(
const
QJsonValue
&
result
)
static
std
::
vector
<
LSPSymbolInformation
>
parseWorkspaceSymbols
(
const
QJsonValue
&
result
)
{
// result has an array in it
return
{};
auto
res
=
result
.
toArray
();
std
::
vector
<
LSPSymbolInformation
>
symbols
;
symbols
.
reserve
(
res
.
size
());
std
::
transform
(
res
.
cbegin
(),
res
.
cend
(),
std
::
back_inserter
(
symbols
),
[](
const
QJsonValue
&
jv
)
{
auto
symbol
=
jv
.
toObject
();
LSPSymbolInformation
symInfo
;
const
auto
location
=
symbol
.
value
(
MEMBER_LOCATION
).
toObject
();
const
auto
mrange
=
symbol
.
contains
(
MEMBER_RANGE
)
?
symbol
.
value
(
MEMBER_RANGE
)
:
location
.
value
(
MEMBER_RANGE
);
symInfo
.
name
=
symbol
.
value
(
QStringLiteral
(
"name"
)).
toString
();
symInfo
.
kind
=
(
LSPSymbolKind
)
symbol
.
value
(
MEMBER_KIND
).
toInt
();
symInfo
.
range
=
parseRange
(
mrange
.
toObject
());
symInfo
.
url
=
QUrl
(
location
.
value
(
MEMBER_URI
).
toString
());
symInfo
.
score
=
symbol
.
value
(
QStringLiteral
(
"score"
)).
toDouble
();
symInfo
.
tags
=
(
LSPSymbolTag
)
symbol
.
value
(
QStringLiteral
(
"tags"
)).
toInt
();
return
symInfo
;
});
std
::
sort
(
symbols
.
begin
(),
symbols
.
end
(),
[](
const
LSPSymbolInformation
&
l
,
const
LSPSymbolInformation
&
r
)
{
return
l
.
score
>
r
.
score
;
});
return
symbols
;
}
using
GenericReplyType
=
QJsonValue
;
...
...
@@ -1645,7 +1670,7 @@ void LSPClientServer::didChangeConfiguration(const QJsonValue &settings)
return
d
->
didChangeConfiguration
(
settings
);
}
void
LSPClientServer
::
workspaceSymbol
(
const
QString
&
symbol
,
const
QObject
*
context
,
const
ReplyHandler
<
QString
>
&
h
)
void
LSPClientServer
::
workspaceSymbol
(
const
QString
&
symbol
,
const
QObject
*
context
,
const
WorkspaceSymbols
ReplyHandler
&
h
)
{
return
d
->
workspaceSymbol
(
symbol
,
make_handler
(
h
,
context
,
parseWorkspaceSymbols
));
}
addons/lspclient/lspclientserver.h
View file @
78fef2e6
...
...
@@ -65,6 +65,7 @@ using WorkspaceEditReplyHandler = ReplyHandler<LSPWorkspaceEdit>;
using
ApplyEditReplyHandler
=
ReplyHandler
<
LSPApplyWorkspaceEditResponse
>
;
using
SwitchSourceHeaderHandler
=
ReplyHandler
<
QString
>
;
using
SemanticTokensDeltaReplyHandler
=
ReplyHandler
<
LSPSemanticTokensDelta
>
;
using
WorkspaceSymbolsReplyHandler
=
ReplyHandler
<
std
::
vector
<
LSPSymbolInformation
>>
;
class
LSPClientPlugin
;
...
...
@@ -169,7 +170,7 @@ public:
void
didChangeConfiguration
(
const
QJsonValue
&
settings
);
// workspace
void
workspaceSymbol
(
const
QString
&
symbol
,
const
QObject
*
context
,
const
ReplyHandler
<
QString
>
&
h
);
void
workspaceSymbol
(
const
QString
&
symbol
,
const
QObject
*
context
,
const
WorkspaceSymbols
ReplyHandler
&
h
);
// notification = signal
Q_SIGNALS:
...
...
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