mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Add textDocument/typeDefinition
This commit is contained in:
parent
e03a3a8e7c
commit
8fcf60e3bc
@ -137,6 +137,8 @@ struct lsServerCapabilities {
|
|||||||
lsSignatureHelpOptions signatureHelpProvider;
|
lsSignatureHelpOptions signatureHelpProvider;
|
||||||
// The server provides goto definition support.
|
// The server provides goto definition support.
|
||||||
bool definitionProvider = true;
|
bool definitionProvider = true;
|
||||||
|
// The server provides Goto Type Definition support.
|
||||||
|
bool typeDefinitionProvider = true;
|
||||||
// The server provides find references support.
|
// The server provides find references support.
|
||||||
bool referencesProvider = true;
|
bool referencesProvider = true;
|
||||||
// The server provides document highlight support.
|
// The server provides document highlight support.
|
||||||
|
@ -22,6 +22,44 @@ MAKE_REFLECT_STRUCT(Out_TextDocumentTypeDefinition, jsonrpc, id, result);
|
|||||||
struct TextDocumentTypeDefinitionHandler
|
struct TextDocumentTypeDefinitionHandler
|
||||||
: BaseMessageHandler<Ipc_TextDocumentTypeDefinition> {
|
: BaseMessageHandler<Ipc_TextDocumentTypeDefinition> {
|
||||||
void Run(Ipc_TextDocumentTypeDefinition* request) override {
|
void Run(Ipc_TextDocumentTypeDefinition* request) override {
|
||||||
|
QueryFile* file;
|
||||||
|
if (!FindFileOrFail(db, project, request->id,
|
||||||
|
request->params.textDocument.uri.GetPath(), &file,
|
||||||
|
nullptr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WorkingFile* working_file =
|
||||||
|
working_files->GetFileByFilename(file->def->path);
|
||||||
|
|
||||||
|
Out_TextDocumentTypeDefinition out;
|
||||||
|
out.id = request->id;
|
||||||
|
for (SymbolRef sym :
|
||||||
|
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||||
|
Id<void> id = sym.id;
|
||||||
|
switch (sym.kind) {
|
||||||
|
case SymbolKind::Var: {
|
||||||
|
const QueryVar::Def* def = db->GetVar(sym).AnyDef();
|
||||||
|
if (!def || !def->type)
|
||||||
|
continue;
|
||||||
|
id = *def->type;
|
||||||
|
}
|
||||||
|
// fallthrough
|
||||||
|
case SymbolKind::Type: {
|
||||||
|
QueryType& type = db->types[id.id];
|
||||||
|
for (const auto& def : type.def)
|
||||||
|
if (def.spell) {
|
||||||
|
if (auto ls_loc = GetLsLocationEx(db, working_files, *def.spell,
|
||||||
|
config->xref.container))
|
||||||
|
out.result.push_back(*ls_loc);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueManager::WriteStdout(IpcId::TextDocumentTypeDefinition, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
REGISTER_MESSAGE_HANDLER(TextDocumentTypeDefinitionHandler);
|
REGISTER_MESSAGE_HANDLER(TextDocumentTypeDefinitionHandler);
|
||||||
|
Loading…
Reference in New Issue
Block a user