mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Add CodeActionLiteralSupport
This slightly optimize MessageHandler::textDocument_codeAction
This commit is contained in:
parent
c5acf62060
commit
8b4d0fc055
@ -121,6 +121,11 @@ struct Config {
|
|||||||
// If false, disable snippets and complete just the identifier part.
|
// If false, disable snippets and complete just the identifier part.
|
||||||
// TextDocumentClientCapabilities.completion.completionItem.snippetSupport
|
// TextDocumentClientCapabilities.completion.completionItem.snippetSupport
|
||||||
bool snippetSupport = true;
|
bool snippetSupport = true;
|
||||||
|
|
||||||
|
// List of supported CodeActionKinds. If empty, client does not
|
||||||
|
// have CodeActionLiteralSupport.
|
||||||
|
// TextDocumentClientCapabilities.codeAction.codeActionLiteralSupport.codeActionKind.valueSet
|
||||||
|
std::vector<std::string> codeActionKind;
|
||||||
} client;
|
} client;
|
||||||
|
|
||||||
struct CodeLens {
|
struct CodeLens {
|
||||||
|
@ -19,7 +19,7 @@ using namespace clang;
|
|||||||
MAKE_HASHABLE(ccls::SymbolIdx, t.usr, t.kind);
|
MAKE_HASHABLE(ccls::SymbolIdx, t.usr, t.kind);
|
||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
REFLECT_STRUCT(CodeActionParam::Context, diagnostics);
|
REFLECT_STRUCT(CodeActionParam::Context, diagnostics, only);
|
||||||
REFLECT_STRUCT(CodeActionParam, textDocument, range, context);
|
REFLECT_STRUCT(CodeActionParam, textDocument, range, context);
|
||||||
void reflect(JsonReader &, EmptyParam &) {}
|
void reflect(JsonReader &, EmptyParam &) {}
|
||||||
REFLECT_STRUCT(TextDocumentParam, textDocument);
|
REFLECT_STRUCT(TextDocumentParam, textDocument);
|
||||||
|
@ -30,6 +30,7 @@ struct CodeActionParam {
|
|||||||
lsRange range;
|
lsRange range;
|
||||||
struct Context {
|
struct Context {
|
||||||
std::vector<Diagnostic> diagnostics;
|
std::vector<Diagnostic> diagnostics;
|
||||||
|
std::vector<std::string> only;
|
||||||
} context;
|
} context;
|
||||||
};
|
};
|
||||||
struct EmptyParam {};
|
struct EmptyParam {};
|
||||||
|
@ -162,6 +162,15 @@ struct TextDocumentClientCap {
|
|||||||
bool hierarchicalDocumentSymbolSupport = false;
|
bool hierarchicalDocumentSymbolSupport = false;
|
||||||
} documentSymbol;
|
} documentSymbol;
|
||||||
|
|
||||||
|
struct CodeAction {
|
||||||
|
bool dynamicRegistration = false;
|
||||||
|
struct CodeActionLiteralSupport {
|
||||||
|
struct CodeActionKind {
|
||||||
|
std::vector<std::string> valueSet;
|
||||||
|
} codeActionKind;
|
||||||
|
} codeActionLiteralSupport;
|
||||||
|
} codeAction;
|
||||||
|
|
||||||
struct PublishDiagnostics {
|
struct PublishDiagnostics {
|
||||||
bool relatedInformation = false;
|
bool relatedInformation = false;
|
||||||
} publishDiagnostics;
|
} publishDiagnostics;
|
||||||
@ -173,9 +182,14 @@ REFLECT_STRUCT(TextDocumentClientCap::Completion, completionItem);
|
|||||||
REFLECT_STRUCT(TextDocumentClientCap::DocumentSymbol,
|
REFLECT_STRUCT(TextDocumentClientCap::DocumentSymbol,
|
||||||
hierarchicalDocumentSymbolSupport);
|
hierarchicalDocumentSymbolSupport);
|
||||||
REFLECT_STRUCT(TextDocumentClientCap::LinkSupport, linkSupport);
|
REFLECT_STRUCT(TextDocumentClientCap::LinkSupport, linkSupport);
|
||||||
|
REFLECT_STRUCT(TextDocumentClientCap::CodeAction::CodeActionLiteralSupport::CodeActionKind,
|
||||||
|
valueSet);
|
||||||
|
REFLECT_STRUCT(TextDocumentClientCap::CodeAction::CodeActionLiteralSupport, codeActionKind);
|
||||||
|
REFLECT_STRUCT(TextDocumentClientCap::CodeAction,
|
||||||
|
dynamicRegistration, codeActionLiteralSupport);
|
||||||
REFLECT_STRUCT(TextDocumentClientCap::PublishDiagnostics, relatedInformation);
|
REFLECT_STRUCT(TextDocumentClientCap::PublishDiagnostics, relatedInformation);
|
||||||
REFLECT_STRUCT(TextDocumentClientCap, completion, definition, documentSymbol,
|
REFLECT_STRUCT(TextDocumentClientCap, completion, definition, documentSymbol,
|
||||||
publishDiagnostics);
|
codeAction, publishDiagnostics);
|
||||||
|
|
||||||
struct ClientCap {
|
struct ClientCap {
|
||||||
WorkspaceClientCap workspace;
|
WorkspaceClientCap workspace;
|
||||||
@ -322,6 +336,10 @@ void do_initialize(MessageHandler *m, InitializeParam ¶m,
|
|||||||
if (!g_config->client.snippetSupport)
|
if (!g_config->client.snippetSupport)
|
||||||
g_config->completion.duplicateOptional = false;
|
g_config->completion.duplicateOptional = false;
|
||||||
|
|
||||||
|
g_config->client.codeActionKind =
|
||||||
|
capabilities.textDocument
|
||||||
|
.codeAction.codeActionLiteralSupport.codeActionKind.valueSet;
|
||||||
|
|
||||||
// Ensure there is a resource directory.
|
// Ensure there is a resource directory.
|
||||||
if (g_config->clang.resourceDir.empty())
|
if (g_config->clang.resourceDir.empty())
|
||||||
g_config->clang.resourceDir = getDefaultResourceDirectory();
|
g_config->clang.resourceDir = getDefaultResourceDirectory();
|
||||||
|
@ -21,12 +21,27 @@ struct CodeAction {
|
|||||||
};
|
};
|
||||||
REFLECT_STRUCT(CodeAction, title, kind, edit);
|
REFLECT_STRUCT(CodeAction, title, kind, edit);
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
template <typename T> bool vec_has(const std::vector<T> &vec, const T &key) {
|
||||||
|
return std::find(std::begin(vec), std::end(vec), key) != std::end(vec);
|
||||||
|
}
|
||||||
|
|
||||||
void MessageHandler::textDocument_codeAction(CodeActionParam ¶m,
|
void MessageHandler::textDocument_codeAction(CodeActionParam ¶m,
|
||||||
ReplyOnce &reply) {
|
ReplyOnce &reply) {
|
||||||
WorkingFile *wf = findOrFail(param.textDocument.uri.getPath(), reply).second;
|
WorkingFile *wf = findOrFail(param.textDocument.uri.getPath(), reply).second;
|
||||||
if (!wf)
|
if (!wf)
|
||||||
return;
|
return;
|
||||||
|
std::vector<std::string> only = param.context.only;
|
||||||
std::vector<CodeAction> result;
|
std::vector<CodeAction> result;
|
||||||
|
if (!only.empty() && !vec_has(only, std::string("quickfix"))) {
|
||||||
|
reply(result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto kinds = g_config->client.codeActionKind;
|
||||||
|
if (!kinds.empty() && !vec_has(kinds, std::string("quickfix"))) {
|
||||||
|
reply(result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::vector<Diagnostic> diagnostics;
|
std::vector<Diagnostic> diagnostics;
|
||||||
wfiles->withLock([&]() { diagnostics = wf->diagnostics; });
|
wfiles->withLock([&]() { diagnostics = wf->diagnostics; });
|
||||||
for (Diagnostic &diag : diagnostics)
|
for (Diagnostic &diag : diagnostics)
|
||||||
|
Loading…
Reference in New Issue
Block a user