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.
|
||||
// TextDocumentClientCapabilities.completion.completionItem.snippetSupport
|
||||
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;
|
||||
|
||||
struct CodeLens {
|
||||
|
@ -19,7 +19,7 @@ using namespace clang;
|
||||
MAKE_HASHABLE(ccls::SymbolIdx, t.usr, t.kind);
|
||||
|
||||
namespace ccls {
|
||||
REFLECT_STRUCT(CodeActionParam::Context, diagnostics);
|
||||
REFLECT_STRUCT(CodeActionParam::Context, diagnostics, only);
|
||||
REFLECT_STRUCT(CodeActionParam, textDocument, range, context);
|
||||
void reflect(JsonReader &, EmptyParam &) {}
|
||||
REFLECT_STRUCT(TextDocumentParam, textDocument);
|
||||
|
@ -30,6 +30,7 @@ struct CodeActionParam {
|
||||
lsRange range;
|
||||
struct Context {
|
||||
std::vector<Diagnostic> diagnostics;
|
||||
std::vector<std::string> only;
|
||||
} context;
|
||||
};
|
||||
struct EmptyParam {};
|
||||
|
@ -162,6 +162,15 @@ struct TextDocumentClientCap {
|
||||
bool hierarchicalDocumentSymbolSupport = false;
|
||||
} documentSymbol;
|
||||
|
||||
struct CodeAction {
|
||||
bool dynamicRegistration = false;
|
||||
struct CodeActionLiteralSupport {
|
||||
struct CodeActionKind {
|
||||
std::vector<std::string> valueSet;
|
||||
} codeActionKind;
|
||||
} codeActionLiteralSupport;
|
||||
} codeAction;
|
||||
|
||||
struct PublishDiagnostics {
|
||||
bool relatedInformation = false;
|
||||
} publishDiagnostics;
|
||||
@ -173,9 +182,14 @@ REFLECT_STRUCT(TextDocumentClientCap::Completion, completionItem);
|
||||
REFLECT_STRUCT(TextDocumentClientCap::DocumentSymbol,
|
||||
hierarchicalDocumentSymbolSupport);
|
||||
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, completion, definition, documentSymbol,
|
||||
publishDiagnostics);
|
||||
codeAction, publishDiagnostics);
|
||||
|
||||
struct ClientCap {
|
||||
WorkspaceClientCap workspace;
|
||||
@ -322,6 +336,10 @@ void do_initialize(MessageHandler *m, InitializeParam ¶m,
|
||||
if (!g_config->client.snippetSupport)
|
||||
g_config->completion.duplicateOptional = false;
|
||||
|
||||
g_config->client.codeActionKind =
|
||||
capabilities.textDocument
|
||||
.codeAction.codeActionLiteralSupport.codeActionKind.valueSet;
|
||||
|
||||
// Ensure there is a resource directory.
|
||||
if (g_config->clang.resourceDir.empty())
|
||||
g_config->clang.resourceDir = getDefaultResourceDirectory();
|
||||
|
@ -21,12 +21,27 @@ struct CodeAction {
|
||||
};
|
||||
REFLECT_STRUCT(CodeAction, title, kind, edit);
|
||||
} // 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,
|
||||
ReplyOnce &reply) {
|
||||
WorkingFile *wf = findOrFail(param.textDocument.uri.getPath(), reply).second;
|
||||
if (!wf)
|
||||
return;
|
||||
std::vector<std::string> only = param.context.only;
|
||||
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;
|
||||
wfiles->withLock([&]() { diagnostics = wf->diagnostics; });
|
||||
for (Diagnostic &diag : diagnostics)
|
||||
|
Loading…
Reference in New Issue
Block a user