Add textDocument/typeDefinition

This commit is contained in:
Fangrui Song 2018-03-01 20:19:38 -08:00
parent e03a3a8e7c
commit 8fcf60e3bc
2 changed files with 40 additions and 0 deletions

View File

@ -137,6 +137,8 @@ struct lsServerCapabilities {
lsSignatureHelpOptions signatureHelpProvider;
// The server provides goto definition support.
bool definitionProvider = true;
// The server provides Goto Type Definition support.
bool typeDefinitionProvider = true;
// The server provides find references support.
bool referencesProvider = true;
// The server provides document highlight support.

View File

@ -22,6 +22,44 @@ MAKE_REFLECT_STRUCT(Out_TextDocumentTypeDefinition, jsonrpc, id, result);
struct TextDocumentTypeDefinitionHandler
: BaseMessageHandler<Ipc_TextDocumentTypeDefinition> {
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);