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

Commit

Permalink
Add config->extension.referenceContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Feb 11, 2018
1 parent 2f24cfe commit 360a4ca
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 40 deletions.
8 changes: 8 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ struct Config {
};
Completion completion;

struct Extension {
// If true, reference results will include "containerName".
bool referenceContainer = false;
};
Extension extension;

struct Index {
// 0: none, 1: doxygen, 2: all comments
// Plugin support for clients:
Expand All @@ -182,6 +188,7 @@ struct Config {
};
MAKE_REFLECT_STRUCT(Config::ClientCapability, snippetSupport);
MAKE_REFLECT_STRUCT(Config::Completion, filterAndSort, detailedLabel);
MAKE_REFLECT_STRUCT(Config::Extension, referenceContainer);
MAKE_REFLECT_STRUCT(Config::Index, comments, attributeMakeCallsToCtor);
MAKE_REFLECT_STRUCT(Config,
compilationDatabaseDirectory,
Expand Down Expand Up @@ -218,6 +225,7 @@ MAKE_REFLECT_STRUCT(Config,

client,
completion,
extension,
index,

dumpAST);
Expand Down
30 changes: 0 additions & 30 deletions src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -835,23 +835,6 @@ struct FindChildOfKindParam {
FindChildOfKindParam(CXCursorKind target_kind) : target_kind(target_kind) {}
};

ClangCursor::VisitResult FindChildOfKindVisitor(ClangCursor cursor,
ClangCursor parent,
FindChildOfKindParam* param) {
if (cursor.get_kind() == param->target_kind) {
param->result = cursor;
return ClangCursor::VisitResult::Break;
}

return ClangCursor::VisitResult::Recurse;
}

optional<ClangCursor> FindChildOfKind(ClangCursor cursor, CXCursorKind kind) {
FindChildOfKindParam param(kind);
cursor.VisitChildren(&FindChildOfKindVisitor, &param);
return param.result;
}

ClangCursor::VisitResult FindTypeVisitor(ClangCursor cursor,
ClangCursor parent,
optional<ClangCursor>* result) {
Expand All @@ -873,19 +856,6 @@ optional<ClangCursor> FindType(ClangCursor cursor) {
return result;
}

bool IsGlobalContainer(const CXIdxContainerInfo* container) {
if (!container)
return false;

switch (container->cursor.kind) {
case CXCursor_Namespace:
case CXCursor_TranslationUnit:
return true;
default:
return false;
}
}

bool IsTypeDefinition(const CXIdxContainerInfo* container) {
if (!container)
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/language_server_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ struct lsLocation {
MAKE_HASHABLE(lsLocation, t.uri, t.range);
MAKE_REFLECT_STRUCT(lsLocation, uri, range);

// cquery extension
struct lsLocationEx : lsLocation {
optional<std::string> containerName;
};
MAKE_REFLECT_STRUCT(lsLocationEx, uri, range, containerName);

enum class lsSymbolKind : int {
File = 1,
Module = 2,
Expand Down
13 changes: 7 additions & 6 deletions src/messages/text_document_references.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ REGISTER_IPC_MESSAGE(Ipc_TextDocumentReferences);
struct Out_TextDocumentReferences
: public lsOutMessage<Out_TextDocumentReferences> {
lsRequestId id;
std::vector<lsLocation> result;
std::vector<lsLocationEx> result;
};
MAKE_REFLECT_STRUCT(Out_TextDocumentReferences, jsonrpc, id, result);

Expand All @@ -58,10 +58,11 @@ struct TextDocumentReferencesHandler
db, sym, request->params.context.includeDeclaration);
out.result.reserve(uses.size());
for (Use use : uses) {
optional<lsLocation> ls_location =
GetLsLocation(db, working_files, use);
if (ls_location)
out.result.push_back(*ls_location);
optional<lsLocationEx> ls_loc = GetLsLocationEx(
db, working_files, use, config->extension.referenceContainer);
if (ls_loc) {
out.result.push_back(*ls_loc);
}
}
break;
}
Expand All @@ -75,7 +76,7 @@ struct TextDocumentReferencesHandler
for (const IndexInclude& include1 : file1.def->includes)
if (include1.resolved_path == include.resolved_path) {
// Another file |file1| has the same include line.
lsLocation result;
lsLocationEx result;
result.uri = lsDocumentUri::FromPath(file1.def->path);
result.range.start.line = result.range.end.line =
include1.line;
Expand Down
35 changes: 35 additions & 0 deletions src/query_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,41 @@ optional<lsLocation> GetLsLocation(QueryDatabase* db,
return lsLocation(uri, *range);
}

optional<lsLocationEx> GetLsLocationEx(QueryDatabase* db,
WorkingFiles* working_files,
Use use,
bool extension) {
optional<lsLocation> ls_loc = GetLsLocation(db, working_files, use);
if (!ls_loc)
return nullopt;
lsLocationEx ret;
ret.lsLocation::operator=(*ls_loc);
if (extension)
switch (use.kind) {
default:
break;
case SymbolKind::Func: {
QueryFunc& func = db->GetFunc(use);
if (func.def)
ret.containerName = func.def->detailed_name;
break;
}
case SymbolKind::Type: {
QueryType& type = db->GetType(use);
if (type.def)
ret.containerName = type.def->detailed_name;
break;
}
case SymbolKind::Var: {
QueryVar& var = db->GetVar(use);
if (var.def)
ret.containerName = var.def->detailed_name;
break;
}
}
return ret;
}

std::vector<lsLocation> GetLsLocations(
QueryDatabase* db,
WorkingFiles* working_files,
Expand Down
11 changes: 7 additions & 4 deletions src/query_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ lsDocumentUri GetLsDocumentUri(QueryDatabase* db, QueryFileId file_id);
optional<lsLocation> GetLsLocation(QueryDatabase* db,
WorkingFiles* working_files,
Reference location);
std::vector<lsLocation> GetLsLocations(
QueryDatabase* db,
WorkingFiles* working_files,
const std::vector<Use>& refs);
optional<lsLocationEx> GetLsLocationEx(QueryDatabase* db,
WorkingFiles* working_files,
Use use,
bool extension);
std::vector<lsLocation> GetLsLocations(QueryDatabase* db,
WorkingFiles* working_files,
const std::vector<Use>& refs);
// Returns a symbol. The symbol will have *NOT* have a location assigned.
optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
WorkingFiles* working_files,
Expand Down

0 comments on commit 360a4ca

Please sign in to comment.