Use string_view for lsSymbolInformation

This commit is contained in:
Fangrui Song 2018-01-31 21:40:40 -08:00
parent 6d6c1639d0
commit e259bb91d3
3 changed files with 21 additions and 14 deletions

View File

@ -1821,19 +1821,19 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
//
// To attribute the use of `x` in `e.x`, we use cursor extent `e.x`
// minus cursor spelling `e` minus the period.
void CheckTypeDependentMemberRefExpr(Range& spell,
void CheckTypeDependentMemberRefExpr(Range* spell,
const ClangCursor& cursor,
IndexParam* param,
const IndexFile* db) {
if (cursor.get_kind() == CXCursor_MemberRefExpr &&
cursor.get_spelling().empty()) {
spell = cursor.get_extent().RemovePrefix(spell.end);
*spell = cursor.get_extent().RemovePrefix(spell->end);
const FileContents& fc = param->file_contents[db->path];
optional<int> maybe_period = fc.ToOffset(spell.start);
optional<int> maybe_period = fc.ToOffset(spell->start);
if (maybe_period) {
int i = *maybe_period;
if (fc.content[i] == '.')
spell.start.column++;
spell->start.column++;
// -> is likely unexposed.
}
}
@ -1868,7 +1868,7 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
case CXIdxEntity_Field: {
ClangCursor ref_cursor(ref->cursor);
Range loc = ref_cursor.get_spelling_range();
CheckTypeDependentMemberRefExpr(loc, ref_cursor, param, db);
CheckTypeDependentMemberRefExpr(&loc, ref_cursor, param, db);
ClangCursor referenced = ref->referencedEntity->cursor;
referenced = referenced.template_specialization_to_template_definition();
@ -1942,12 +1942,12 @@ void OnIndexReference(CXClientData client_data, const CXIdxEntityRefInfo* ref) {
// Extents have larger ranges and thus less specific, and will be
// overriden by other functions if exist.
//
// Type-dependent member ref expressions do not have useful spelling
// Type-dependent member access expressions do not have useful spelling
// ranges. See the comment above for the CXIdxEntity_Field case.
if (is_implicit)
loc = ref_cursor.get_extent();
else
CheckTypeDependentMemberRefExpr(loc, ref_cursor, param, db);
CheckTypeDependentMemberRefExpr(&loc, ref_cursor, param, db);
OnIndexReference_Function(db, loc, ref->container->cursor, called_id,
called, is_implicit);

View File

@ -202,10 +202,10 @@ enum class lsSymbolKind : int {
MAKE_REFLECT_TYPE_PROXY(lsSymbolKind);
struct lsSymbolInformation {
std::string name;
std::string_view name;
lsSymbolKind kind;
lsLocation location;
std::string containerName;
std::string_view containerName;
};
MAKE_REFLECT_STRUCT(lsSymbolInformation, name, kind, location, containerName);

View File

@ -439,8 +439,10 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
return nullopt;
lsSymbolInformation info;
info.name =
use_short_name ? std::string(type.def->ShortName()) : type.def->detailed_name;
if (use_short_name)
info.name = type.def->ShortName();
else
info.name = type.def->detailed_name;
if (type.def->detailed_name != type.def->ShortName())
info.containerName = type.def->detailed_name;
// TODO ClangSymbolKind -> lsSymbolKind
@ -460,8 +462,10 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
return nullopt;
lsSymbolInformation info;
info.name =
use_short_name ? std::string(func.def->ShortName()) : func.def->detailed_name;
if (use_short_name)
info.name = func.def->ShortName();
else
info.name = func.def->detailed_name;
info.containerName = func.def->detailed_name;
info.kind = lsSymbolKind::Function;
@ -479,7 +483,10 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
return nullopt;
lsSymbolInformation info;
info.name = use_short_name ? std::string(var.def->ShortName()) : var.def->detailed_name;
if (use_short_name)
info.name = var.def->ShortName();
else
info.name = var.def->detailed_name;
info.containerName = var.def->detailed_name;
info.kind = lsSymbolKind::Variable;
return info;