mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-03 22:04:24 +00:00 
			
		
		
		
	More improvements to semantic highlighting. Still not done though.
This commit is contained in:
		
							parent
							
								
									8145a06534
								
							
						
					
					
						commit
						5fa7fbf0d2
					
				@ -161,29 +161,51 @@ void EmitSemanticHighlighting(QueryDatabase* db,
 | 
				
			|||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Group symbols together.
 | 
					  // Group symbols together.
 | 
				
			||||||
  std::unordered_map<SymbolIdx, NonElidedVector<lsRange>> grouped_symbols;
 | 
					  std::unordered_map<SymbolIdx, Out_CqueryPublishSemanticHighlighting::Symbol>
 | 
				
			||||||
 | 
					      grouped_symbols;
 | 
				
			||||||
  for (SymbolRef sym : file->def->all_symbols) {
 | 
					  for (SymbolRef sym : file->def->all_symbols) {
 | 
				
			||||||
    if (sym.idx.kind == SymbolKind::Var) {
 | 
					    bool is_type_member = false;
 | 
				
			||||||
 | 
					    switch (sym.idx.kind) {
 | 
				
			||||||
 | 
					      case SymbolKind::Func: {
 | 
				
			||||||
 | 
					        QueryFunc* func = &db->funcs[sym.idx.idx];
 | 
				
			||||||
 | 
					        if (!func->def)
 | 
				
			||||||
 | 
					          continue;  // applies to for loop
 | 
				
			||||||
 | 
					        is_type_member = func->def->declaring_type.has_value();
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      case SymbolKind::Var: {
 | 
				
			||||||
        QueryVar* var = &db->vars[sym.idx.idx];
 | 
					        QueryVar* var = &db->vars[sym.idx.idx];
 | 
				
			||||||
        if (!var->def)
 | 
					        if (!var->def)
 | 
				
			||||||
        continue;
 | 
					          continue;  // applies to for loop
 | 
				
			||||||
      if (!var->def->is_local)
 | 
					        if (!var->def->is_local && !var->def->declaring_type)
 | 
				
			||||||
        continue;
 | 
					          continue;  // applies to for loop
 | 
				
			||||||
 | 
					        is_type_member = var->def->declaring_type.has_value();
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      default:
 | 
				
			||||||
 | 
					        continue;  // applies to for loop
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    optional<lsRange> loc = GetLsRange(working_file, sym.loc.range);
 | 
					    optional<lsRange> loc = GetLsRange(working_file, sym.loc.range);
 | 
				
			||||||
    if (loc)
 | 
					    if (loc) {
 | 
				
			||||||
      grouped_symbols[sym.idx].push_back(*loc);
 | 
					      auto it = grouped_symbols.find(sym.idx);
 | 
				
			||||||
 | 
					      if (it != grouped_symbols.end()) {
 | 
				
			||||||
 | 
					        it->second.ranges.push_back(*loc);
 | 
				
			||||||
 | 
					      } else {
 | 
				
			||||||
 | 
					        Out_CqueryPublishSemanticHighlighting::Symbol symbol;
 | 
				
			||||||
 | 
					        symbol.type = map_symbol_kind_to_symbol_type(sym.idx.kind);
 | 
				
			||||||
 | 
					        symbol.is_type_member = is_type_member;
 | 
				
			||||||
 | 
					        symbol.ranges.push_back(*loc);
 | 
				
			||||||
 | 
					        grouped_symbols[sym.idx] = symbol;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Publish.
 | 
					  // Publish.
 | 
				
			||||||
  Out_CqueryPublishSemanticHighlighting out;
 | 
					  Out_CqueryPublishSemanticHighlighting out;
 | 
				
			||||||
  out.params.uri = lsDocumentUri::FromPath(working_file->filename);
 | 
					  out.params.uri = lsDocumentUri::FromPath(working_file->filename);
 | 
				
			||||||
  for (auto& entry : grouped_symbols) {
 | 
					  for (auto& entry : grouped_symbols)
 | 
				
			||||||
    Out_CqueryPublishSemanticHighlighting::Symbol symbol;
 | 
					    out.params.symbols.push_back(entry.second);
 | 
				
			||||||
    symbol.type = map_symbol_kind_to_symbol_type(entry.first.kind);
 | 
					 | 
				
			||||||
    symbol.ranges = entry.second;
 | 
					 | 
				
			||||||
    out.params.symbols.push_back(symbol);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  IpcManager::instance()->SendOutMessageToClient(
 | 
					  IpcManager::instance()->SendOutMessageToClient(
 | 
				
			||||||
      IpcId::CqueryPublishSemanticHighlighting, out);
 | 
					      IpcId::CqueryPublishSemanticHighlighting, out);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -373,10 +373,10 @@ struct VarDefDefinitionData {
 | 
				
			|||||||
  // Type of the variable.
 | 
					  // Type of the variable.
 | 
				
			||||||
  optional<TypeId> variable_type;
 | 
					  optional<TypeId> variable_type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Type which declares this one (ie, it is a method)
 | 
					  // Type which declares this one.
 | 
				
			||||||
  optional<TypeId> declaring_type;
 | 
					  optional<TypeId> declaring_type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Is this a "local" variable, ie, a parameter or function variable?
 | 
					  // Is this a parameter or function variable?
 | 
				
			||||||
  bool is_local = false;
 | 
					  bool is_local = false;
 | 
				
			||||||
  // Is this a macro, ie, #define FOO?
 | 
					  // Is this a macro, ie, #define FOO?
 | 
				
			||||||
  bool is_macro = false;
 | 
					  bool is_macro = false;
 | 
				
			||||||
 | 
				
			|||||||
@ -1484,7 +1484,8 @@ struct Out_CqueryPublishSemanticHighlighting
 | 
				
			|||||||
    : public lsOutMessage<Out_CqueryPublishSemanticHighlighting> {
 | 
					    : public lsOutMessage<Out_CqueryPublishSemanticHighlighting> {
 | 
				
			||||||
  enum class SymbolType { Type = 0, Function, Variable };
 | 
					  enum class SymbolType { Type = 0, Function, Variable };
 | 
				
			||||||
  struct Symbol {
 | 
					  struct Symbol {
 | 
				
			||||||
    SymbolType type;
 | 
					    SymbolType type = SymbolType::Type;
 | 
				
			||||||
 | 
					    bool is_type_member = false;
 | 
				
			||||||
    NonElidedVector<lsRange> ranges;
 | 
					    NonElidedVector<lsRange> ranges;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  struct Params {
 | 
					  struct Params {
 | 
				
			||||||
@ -1497,6 +1498,7 @@ struct Out_CqueryPublishSemanticHighlighting
 | 
				
			|||||||
MAKE_REFLECT_TYPE_PROXY(Out_CqueryPublishSemanticHighlighting::SymbolType, int);
 | 
					MAKE_REFLECT_TYPE_PROXY(Out_CqueryPublishSemanticHighlighting::SymbolType, int);
 | 
				
			||||||
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Symbol,
 | 
					MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Symbol,
 | 
				
			||||||
                    type,
 | 
					                    type,
 | 
				
			||||||
 | 
					                    is_type_member,
 | 
				
			||||||
                    ranges);
 | 
					                    ranges);
 | 
				
			||||||
MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Params,
 | 
					MAKE_REFLECT_STRUCT(Out_CqueryPublishSemanticHighlighting::Params,
 | 
				
			||||||
                    uri,
 | 
					                    uri,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user