mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-04 06:15:20 +00:00 
			
		
		
		
	Better inline code lens location for functions
This commit is contained in:
		
							parent
							
								
									3f4866208f
								
							
						
					
					
						commit
						61efdcc721
					
				@ -171,28 +171,41 @@ struct TextDocumentCodeLensHandler
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
          int16_t offset = 0;
 | 
					          int16_t offset = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // For functions, the outline will report a location that is using the extent since that is better for outline. This tries to convert the extent location to the spelling location.
 | 
				
			||||||
 | 
					          auto try_ensure_spelling = [&](SymbolRef sym) {
 | 
				
			||||||
 | 
					            optional<QueryLocation> def = GetDefinitionSpellingOfSymbol(db, sym.idx);
 | 
				
			||||||
 | 
					            if (!def ||
 | 
				
			||||||
 | 
					                def->path != sym.loc.path ||
 | 
				
			||||||
 | 
					                def->range.start.line != sym.loc.range.start.line) {
 | 
				
			||||||
 | 
					              return sym.loc;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return *def;
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          std::vector<QueryFuncRef> base_callers =
 | 
					          std::vector<QueryFuncRef> base_callers =
 | 
				
			||||||
              GetCallersForAllBaseFunctions(db, func);
 | 
					              GetCallersForAllBaseFunctions(db, func);
 | 
				
			||||||
          std::vector<QueryFuncRef> derived_callers =
 | 
					          std::vector<QueryFuncRef> derived_callers =
 | 
				
			||||||
              GetCallersForAllDerivedFunctions(db, func);
 | 
					              GetCallersForAllDerivedFunctions(db, func);
 | 
				
			||||||
          if (base_callers.empty() && derived_callers.empty()) {
 | 
					          if (base_callers.empty() && derived_callers.empty()) {
 | 
				
			||||||
 | 
					            QueryLocation loc = try_ensure_spelling(ref);
 | 
				
			||||||
            AddCodeLens("call", "calls", &common,
 | 
					            AddCodeLens("call", "calls", &common,
 | 
				
			||||||
                        ref.loc.OffsetStartColumn(offset++),
 | 
					                        loc.OffsetStartColumn(offset++),
 | 
				
			||||||
                        ToQueryLocation(db, func.callers), nullopt,
 | 
					                        ToQueryLocation(db, func.callers), nullopt,
 | 
				
			||||||
                        true /*force_display*/);
 | 
					                        true /*force_display*/);
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
 | 
					            QueryLocation loc = try_ensure_spelling(ref);
 | 
				
			||||||
            AddCodeLens("direct call", "direct calls", &common,
 | 
					            AddCodeLens("direct call", "direct calls", &common,
 | 
				
			||||||
                        ref.loc.OffsetStartColumn(offset++),
 | 
					                        loc.OffsetStartColumn(offset++),
 | 
				
			||||||
                        ToQueryLocation(db, func.callers), nullopt,
 | 
					                        ToQueryLocation(db, func.callers), nullopt,
 | 
				
			||||||
                        false /*force_display*/);
 | 
					                        false /*force_display*/);
 | 
				
			||||||
            if (!base_callers.empty())
 | 
					            if (!base_callers.empty())
 | 
				
			||||||
              AddCodeLens("base call", "base calls", &common,
 | 
					              AddCodeLens("base call", "base calls", &common,
 | 
				
			||||||
                          ref.loc.OffsetStartColumn(offset++),
 | 
					                          loc.OffsetStartColumn(offset++),
 | 
				
			||||||
                          ToQueryLocation(db, base_callers), nullopt,
 | 
					                          ToQueryLocation(db, base_callers), nullopt,
 | 
				
			||||||
                          false /*force_display*/);
 | 
					                          false /*force_display*/);
 | 
				
			||||||
            if (!derived_callers.empty())
 | 
					            if (!derived_callers.empty())
 | 
				
			||||||
              AddCodeLens("derived call", "derived calls", &common,
 | 
					              AddCodeLens("derived call", "derived calls", &common,
 | 
				
			||||||
                          ref.loc.OffsetStartColumn(offset++),
 | 
					                          loc.OffsetStartColumn(offset++),
 | 
				
			||||||
                          ToQueryLocation(db, derived_callers), nullopt,
 | 
					                          ToQueryLocation(db, derived_callers), nullopt,
 | 
				
			||||||
                          false /*force_display*/);
 | 
					                          false /*force_display*/);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user