mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-04 06:15:20 +00:00 
			
		
		
		
	Add Query*::file_id to allow textDocument/hover on declarations
Also change StorageClass storage to uint8_t
This commit is contained in:
		
							parent
							
								
									31fac4d496
								
							
						
					
					
						commit
						c50f0c5900
					
				@ -44,7 +44,7 @@ OUTPUT:
 | 
			
		||||
      "bases": [],
 | 
			
		||||
      "derived": [],
 | 
			
		||||
      "vars": [],
 | 
			
		||||
      "uses": ["12:5-12:10|0|1|16420"],
 | 
			
		||||
      "uses": ["12:5-12:10|0|1|16420", "12:5-12:10|0|1|64|0"],
 | 
			
		||||
      "callees": []
 | 
			
		||||
    }],
 | 
			
		||||
  "usr2type": [{
 | 
			
		||||
@ -73,7 +73,7 @@ OUTPUT:
 | 
			
		||||
      "spell": "9:11-9:16|0|1|2",
 | 
			
		||||
      "extent": "9:1-9:20|0|1|0",
 | 
			
		||||
      "type": 53,
 | 
			
		||||
      "uses": ["12:14-12:19|0|1|12"],
 | 
			
		||||
      "uses": ["12:14-12:19|0|1|12", "12:14-12:19|0|1|64|0"],
 | 
			
		||||
      "kind": 13,
 | 
			
		||||
      "storage": 0
 | 
			
		||||
    }, {
 | 
			
		||||
 | 
			
		||||
@ -59,7 +59,7 @@ OUTPUT:
 | 
			
		||||
      "funcs": [13788753348312146871],
 | 
			
		||||
      "vars": [],
 | 
			
		||||
      "instances": [],
 | 
			
		||||
      "uses": ["5:12-5:15|0|1|4"]
 | 
			
		||||
      "uses": ["5:12-5:15|0|1|4", "5:12-5:15|0|1|64|0"]
 | 
			
		||||
    }],
 | 
			
		||||
  "usr2var": [{
 | 
			
		||||
      "usr": 1569772797058982873,
 | 
			
		||||
 | 
			
		||||
@ -58,7 +58,7 @@ OUTPUT:
 | 
			
		||||
      "declarations": ["1:11-1:14|0|1|1"],
 | 
			
		||||
      "alias_of": 0,
 | 
			
		||||
      "bases": [],
 | 
			
		||||
      "derived": [],
 | 
			
		||||
      "derived": [17805385787823406700],
 | 
			
		||||
      "types": [17805385787823406700],
 | 
			
		||||
      "funcs": [],
 | 
			
		||||
      "vars": [],
 | 
			
		||||
@ -87,7 +87,7 @@ OUTPUT:
 | 
			
		||||
      "kind": 3,
 | 
			
		||||
      "declarations": ["3:20-3:23|17805385787823406700|2|1025"],
 | 
			
		||||
      "alias_of": 0,
 | 
			
		||||
      "bases": [],
 | 
			
		||||
      "bases": [17805385787823406700, 17805385787823406700, 17805385787823406700, 17805385787823406700],
 | 
			
		||||
      "derived": [],
 | 
			
		||||
      "types": [],
 | 
			
		||||
      "funcs": [],
 | 
			
		||||
@ -105,8 +105,8 @@ OUTPUT:
 | 
			
		||||
      "kind": 3,
 | 
			
		||||
      "declarations": ["2:15-2:18|926793467007732869|2|1025"],
 | 
			
		||||
      "alias_of": 0,
 | 
			
		||||
      "bases": [],
 | 
			
		||||
      "derived": [],
 | 
			
		||||
      "bases": [926793467007732869, 926793467007732869, 926793467007732869, 926793467007732869],
 | 
			
		||||
      "derived": [14450849931009540802],
 | 
			
		||||
      "types": [14450849931009540802],
 | 
			
		||||
      "funcs": [],
 | 
			
		||||
      "vars": [],
 | 
			
		||||
 | 
			
		||||
@ -22,7 +22,7 @@ OUTPUT:
 | 
			
		||||
      "bases": [],
 | 
			
		||||
      "derived": [],
 | 
			
		||||
      "vars": [],
 | 
			
		||||
      "uses": ["6:14-6:20|0|1|16420"],
 | 
			
		||||
      "uses": ["6:14-6:20|0|1|16420", "6:14-6:20|0|1|64|0"],
 | 
			
		||||
      "callees": []
 | 
			
		||||
    }, {
 | 
			
		||||
      "usr": 11404881820527069090,
 | 
			
		||||
 | 
			
		||||
@ -71,8 +71,6 @@ void Reflect(Writer& visitor, Reference& value);
 | 
			
		||||
void Reflect(Reader& visitor, Use& value);
 | 
			
		||||
void Reflect(Writer& visitor, Use& value);
 | 
			
		||||
 | 
			
		||||
MAKE_REFLECT_TYPE_PROXY2(clang::StorageClass, uint8_t);
 | 
			
		||||
 | 
			
		||||
template <typename D>
 | 
			
		||||
struct NameMixin {
 | 
			
		||||
  std::string_view Name(bool qualified) const {
 | 
			
		||||
@ -104,11 +102,12 @@ struct FuncDef : NameMixin<FuncDef> {
 | 
			
		||||
  // Functions that this function calls.
 | 
			
		||||
  std::vector<SymbolRef> callees;
 | 
			
		||||
 | 
			
		||||
  int file_id = -1;
 | 
			
		||||
  int16_t qual_name_offset = 0;
 | 
			
		||||
  int16_t short_name_offset = 0;
 | 
			
		||||
  int16_t short_name_size = 0;
 | 
			
		||||
  lsSymbolKind kind = lsSymbolKind::Unknown;
 | 
			
		||||
  clang::StorageClass storage = clang::SC_None;
 | 
			
		||||
  uint8_t storage = clang::SC_None;
 | 
			
		||||
 | 
			
		||||
  std::vector<Usr> GetBases() const { return bases; }
 | 
			
		||||
};
 | 
			
		||||
@ -155,6 +154,7 @@ struct TypeDef : NameMixin<TypeDef> {
 | 
			
		||||
  // type comes from a using or typedef statement).
 | 
			
		||||
  Usr alias_of = 0;
 | 
			
		||||
 | 
			
		||||
  int file_id = -1;
 | 
			
		||||
  int16_t qual_name_offset = 0;
 | 
			
		||||
  int16_t short_name_offset = 0;
 | 
			
		||||
  int16_t short_name_size = 0;
 | 
			
		||||
@ -199,6 +199,7 @@ struct VarDef : NameMixin<VarDef> {
 | 
			
		||||
  // Type of the variable.
 | 
			
		||||
  Usr type = 0;
 | 
			
		||||
 | 
			
		||||
  int file_id = -1;
 | 
			
		||||
  int16_t qual_name_offset = 0;
 | 
			
		||||
  int16_t short_name_offset = 0;
 | 
			
		||||
  int16_t short_name_size = 0;
 | 
			
		||||
@ -206,7 +207,7 @@ struct VarDef : NameMixin<VarDef> {
 | 
			
		||||
  lsSymbolKind kind = lsSymbolKind::Unknown;
 | 
			
		||||
  // Note a variable may have instances of both |None| and |Extern|
 | 
			
		||||
  // (declaration).
 | 
			
		||||
  clang::StorageClass storage = clang::SC_None;
 | 
			
		||||
  uint8_t storage = clang::SC_None;
 | 
			
		||||
 | 
			
		||||
  bool is_local() const {
 | 
			
		||||
    return spell && spell->kind != SymbolKind::File &&
 | 
			
		||||
 | 
			
		||||
@ -198,7 +198,7 @@ void EmitSemanticHighlighting(DB *db,
 | 
			
		||||
    std::string_view detailed_name;
 | 
			
		||||
    lsSymbolKind parent_kind = lsSymbolKind::Unknown;
 | 
			
		||||
    lsSymbolKind kind = lsSymbolKind::Unknown;
 | 
			
		||||
    StorageClass storage = SC_None;
 | 
			
		||||
    uint8_t storage = SC_None;
 | 
			
		||||
    // This switch statement also filters out symbols that are not highlighted.
 | 
			
		||||
    switch (sym.kind) {
 | 
			
		||||
    case SymbolKind::Func: {
 | 
			
		||||
 | 
			
		||||
@ -63,7 +63,7 @@ struct Out_CclsPublishSemanticHighlighting
 | 
			
		||||
    int stableId = 0;
 | 
			
		||||
    lsSymbolKind parentKind;
 | 
			
		||||
    lsSymbolKind kind;
 | 
			
		||||
    clang::StorageClass storage;
 | 
			
		||||
    uint8_t storage;
 | 
			
		||||
    std::vector<std::pair<int, int>> ranges;
 | 
			
		||||
 | 
			
		||||
    // `lsRanges` is used to compute `ranges`.
 | 
			
		||||
 | 
			
		||||
@ -114,7 +114,7 @@ bool Expand(MessageHandler* m,
 | 
			
		||||
        for (SymbolRef ref : def->callees)
 | 
			
		||||
          if (ref.kind == SymbolKind::Func)
 | 
			
		||||
            handle(Use{{ref.range, ref.usr, ref.kind, ref.role},
 | 
			
		||||
                       def->spell->file_id},
 | 
			
		||||
                       def->file_id},
 | 
			
		||||
                   call_type);
 | 
			
		||||
    } else {
 | 
			
		||||
      for (Use use : func.uses)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										23
									
								
								src/query.cc
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								src/query.cc
									
									
									
									
									
								
							@ -158,7 +158,7 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IndexFile& indexed) {
 | 
			
		||||
template <typename Q>
 | 
			
		||||
bool TryReplaceDef(llvm::SmallVectorImpl<Q>& def_list, Q&& def) {
 | 
			
		||||
  for (auto& def1 : def_list)
 | 
			
		||||
    if (def1.spell->file_id == def.spell->file_id) {
 | 
			
		||||
    if (def1.file_id == def.file_id) {
 | 
			
		||||
      def1 = std::move(def);
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
@ -182,7 +182,7 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
 | 
			
		||||
  r.funcs_hint = int(current->usr2func.size() - previous->usr2func.size());
 | 
			
		||||
  for (auto& it : previous->usr2func) {
 | 
			
		||||
    auto& func = it.second;
 | 
			
		||||
    if (func.def.spell)
 | 
			
		||||
    if (func.def.detailed_name[0])
 | 
			
		||||
      r.funcs_removed.push_back(func.usr);
 | 
			
		||||
    r.funcs_declarations[func.usr].first = std::move(func.declarations);
 | 
			
		||||
    r.funcs_uses[func.usr].first = std::move(func.uses);
 | 
			
		||||
@ -190,7 +190,7 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
 | 
			
		||||
  }
 | 
			
		||||
  for (auto& it : current->usr2func) {
 | 
			
		||||
    auto& func = it.second;
 | 
			
		||||
    if (func.def.spell && func.def.detailed_name[0])
 | 
			
		||||
    if (func.def.detailed_name[0])
 | 
			
		||||
      r.funcs_def_update.emplace_back(it.first, func.def);
 | 
			
		||||
    r.funcs_declarations[func.usr].second = std::move(func.declarations);
 | 
			
		||||
    r.funcs_uses[func.usr].second = std::move(func.uses);
 | 
			
		||||
@ -200,7 +200,7 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
 | 
			
		||||
  r.types_hint = int(current->usr2type.size() - previous->usr2type.size());
 | 
			
		||||
  for (auto& it : previous->usr2type) {
 | 
			
		||||
    auto& type = it.second;
 | 
			
		||||
    if (type.def.spell)
 | 
			
		||||
    if (type.def.detailed_name[0])
 | 
			
		||||
      r.types_removed.push_back(type.usr);
 | 
			
		||||
    r.types_declarations[type.usr].first = std::move(type.declarations);
 | 
			
		||||
    r.types_uses[type.usr].first = std::move(type.uses);
 | 
			
		||||
@ -209,7 +209,7 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
 | 
			
		||||
  };
 | 
			
		||||
  for (auto& it : current->usr2type) {
 | 
			
		||||
    auto& type = it.second;
 | 
			
		||||
    if (type.def.spell && type.def.detailed_name[0])
 | 
			
		||||
    if (type.def.detailed_name[0])
 | 
			
		||||
      r.types_def_update.emplace_back(it.first, type.def);
 | 
			
		||||
    r.types_declarations[type.usr].second = std::move(type.declarations);
 | 
			
		||||
    r.types_uses[type.usr].second = std::move(type.uses);
 | 
			
		||||
@ -220,14 +220,14 @@ IndexUpdate IndexUpdate::CreateDelta(IndexFile* previous,
 | 
			
		||||
  r.vars_hint = int(current->usr2var.size() - previous->usr2var.size());
 | 
			
		||||
  for (auto& it : previous->usr2var) {
 | 
			
		||||
    auto& var = it.second;
 | 
			
		||||
    if (var.def.spell)
 | 
			
		||||
    if (var.def.detailed_name[0])
 | 
			
		||||
      r.vars_removed.push_back(var.usr);
 | 
			
		||||
    r.vars_declarations[var.usr].first = std::move(var.declarations);
 | 
			
		||||
    r.vars_uses[var.usr].first = std::move(var.uses);
 | 
			
		||||
  }
 | 
			
		||||
  for (auto& it : current->usr2var) {
 | 
			
		||||
    auto& var = it.second;
 | 
			
		||||
    if (var.def.spell && var.def.detailed_name[0])
 | 
			
		||||
    if (var.def.detailed_name[0])
 | 
			
		||||
      r.vars_def_update.emplace_back(it.first, var.def);
 | 
			
		||||
    r.vars_declarations[var.usr].second = std::move(var.declarations);
 | 
			
		||||
    r.vars_uses[var.usr].second = std::move(var.uses);
 | 
			
		||||
@ -246,7 +246,7 @@ void DB::RemoveUsrs(SymbolKind kind,
 | 
			
		||||
        if (!HasFunc(usr)) continue;
 | 
			
		||||
        QueryFunc& func = Func(usr);
 | 
			
		||||
        auto it = llvm::find_if(func.def, [=](const QueryFunc::Def& def) {
 | 
			
		||||
          return def.spell->file_id == file_id;
 | 
			
		||||
          return def.file_id == file_id;
 | 
			
		||||
        });
 | 
			
		||||
        if (it != func.def.end())
 | 
			
		||||
          func.def.erase(it);
 | 
			
		||||
@ -259,7 +259,7 @@ void DB::RemoveUsrs(SymbolKind kind,
 | 
			
		||||
        if (!HasType(usr)) continue;
 | 
			
		||||
        QueryType& type = Type(usr);
 | 
			
		||||
        auto it = llvm::find_if(type.def, [=](const QueryType::Def& def) {
 | 
			
		||||
          return def.spell->file_id == file_id;
 | 
			
		||||
          return def.file_id == file_id;
 | 
			
		||||
        });
 | 
			
		||||
        if (it != type.def.end())
 | 
			
		||||
          type.def.erase(it);
 | 
			
		||||
@ -272,7 +272,7 @@ void DB::RemoveUsrs(SymbolKind kind,
 | 
			
		||||
        if (!HasVar(usr)) continue;
 | 
			
		||||
        QueryVar& var = Var(usr);
 | 
			
		||||
        auto it = llvm::find_if(var.def, [=](const QueryVar::Def& def) {
 | 
			
		||||
          return def.spell->file_id == file_id;
 | 
			
		||||
          return def.file_id == file_id;
 | 
			
		||||
        });
 | 
			
		||||
        if (it != var.def.end())
 | 
			
		||||
          var.def.erase(it);
 | 
			
		||||
@ -400,6 +400,7 @@ void DB::Update(const Lid2file_id &lid2file_id, int file_id,
 | 
			
		||||
  for (auto &u : us) {
 | 
			
		||||
    auto& def = u.second;
 | 
			
		||||
    assert(def.detailed_name[0]);
 | 
			
		||||
    u.second.file_id = file_id;
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.spell);
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.extent);
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.callees);
 | 
			
		||||
@ -418,6 +419,7 @@ void DB::Update(const Lid2file_id &lid2file_id, int file_id,
 | 
			
		||||
  for (auto &u : us) {
 | 
			
		||||
    auto& def = u.second;
 | 
			
		||||
    assert(def.detailed_name[0]);
 | 
			
		||||
    u.second.file_id = file_id;
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.spell);
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.extent);
 | 
			
		||||
    auto R = type_usr.try_emplace({u.first}, type_usr.size());
 | 
			
		||||
@ -435,6 +437,7 @@ void DB::Update(const Lid2file_id &lid2file_id, int file_id,
 | 
			
		||||
  for (auto &u : us) {
 | 
			
		||||
    auto& def = u.second;
 | 
			
		||||
    assert(def.detailed_name[0]);
 | 
			
		||||
    u.second.file_id = file_id;
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.spell);
 | 
			
		||||
    AssignFileId(lid2file_id, file_id, def.extent);
 | 
			
		||||
    auto R = var_usr.try_emplace({u.first}, var_usr.size());
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user