forked from qt-creator/qt-creator
LSP: add Command and CodeAction support to the language client
Change-Id: I9e86c17b87c6b6aef36bd0ca293d9db40c554aad Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -105,6 +105,16 @@ DocumentSymbolsRequest::DocumentSymbolsRequest(const DocumentSymbolParams ¶m
|
||||
: Request(methodName, params)
|
||||
{ }
|
||||
|
||||
Utils::optional<QList<CodeActionKind> > CodeActionParams::CodeActionContext::only() const
|
||||
{
|
||||
return optionalArray<CodeActionKind>(onlyKey);
|
||||
}
|
||||
|
||||
void CodeActionParams::CodeActionContext::setOnly(const QList<CodeActionKind> &only)
|
||||
{
|
||||
insertArray(onlyKey, only);
|
||||
}
|
||||
|
||||
bool CodeActionParams::CodeActionContext::isValid(QStringList *error) const
|
||||
{
|
||||
return checkArray<Diagnostic>(error, diagnosticsKey);
|
||||
@@ -380,4 +390,32 @@ SignatureHelpRequest::SignatureHelpRequest(const TextDocumentPositionParams &par
|
||||
: Request(methodName, params)
|
||||
{ }
|
||||
|
||||
CodeActionResult::CodeActionResult(const QJsonValue &val)
|
||||
{
|
||||
using ResultArray = QList<Utils::variant<Command, CodeAction>>;
|
||||
if (val.isArray()) {
|
||||
QJsonArray array = val.toArray();
|
||||
ResultArray result;
|
||||
for (const QJsonValue &val : array) {
|
||||
Command command(val);
|
||||
if (command.isValid(nullptr))
|
||||
result << command;
|
||||
else
|
||||
result << CodeAction(val);
|
||||
}
|
||||
emplace<ResultArray>(result);
|
||||
return;
|
||||
}
|
||||
emplace<nullptr_t>(nullptr);
|
||||
}
|
||||
|
||||
bool CodeAction::isValid(QStringList *error) const
|
||||
{
|
||||
return check<QString>(error, titleKey)
|
||||
&& checkOptional<CodeActionKind>(error, codeActionKindKey)
|
||||
&& checkOptionalArray<Diagnostic>(error, diagnosticsKey)
|
||||
&& checkOptional<WorkspaceEdit>(error, editKey)
|
||||
&& checkOptional<Command>(error, commandKey);
|
||||
}
|
||||
|
||||
} // namespace LanguageServerProtocol
|
||||
|
||||
Reference in New Issue
Block a user