Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Add textDocument/typeDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Mar 2, 2018
1 parent 3761eeb commit 324aac3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/messages/initialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions src/messages/text_document_type_definition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 324aac3

Please sign in to comment.