mirror of
https://github.com/MaskRay/ccls.git
synced 2025-02-21 07:59:27 +00:00
Add config->extension.referenceContainer
This commit is contained in:
parent
d79a7a3fa1
commit
3ba9209eea
@ -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:
|
||||
@ -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,
|
||||
@ -218,6 +225,7 @@ MAKE_REFLECT_STRUCT(Config,
|
||||
|
||||
client,
|
||||
completion,
|
||||
extension,
|
||||
index,
|
||||
|
||||
dumpAST);
|
||||
|
@ -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, ¶m);
|
||||
return param.result;
|
||||
}
|
||||
|
||||
ClangCursor::VisitResult FindTypeVisitor(ClangCursor cursor,
|
||||
ClangCursor parent,
|
||||
optional<ClangCursor>* result) {
|
||||
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user