mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-31 12:42:34 +00:00 
			
		
		
		
	textDocument/definitions: on a variable definition, get both declarations and variable_type definition.
This commit is contained in:
		
							parent
							
								
									519abd1090
								
							
						
					
					
						commit
						3410f9769c
					
				| @ -24,6 +24,29 @@ struct Out_TextDocumentDefinition | ||||
| }; | ||||
| MAKE_REFLECT_STRUCT(Out_TextDocumentDefinition, jsonrpc, id, result); | ||||
| 
 | ||||
| std::vector<QueryLocation> GetGotoDefinitionTargets( | ||||
|     QueryDatabase* db, | ||||
|     const SymbolIdx& symbol) { | ||||
|   switch (symbol.kind) { | ||||
|     // Returns GetDeclarationsOfSymbolForGotoDefinition and
 | ||||
|     // variable type definition.
 | ||||
|     case SymbolKind::Var: { | ||||
|       std::vector<QueryLocation> ret = | ||||
|           GetDeclarationsOfSymbolForGotoDefinition(db, symbol); | ||||
|       QueryVar& var = db->vars[symbol.idx]; | ||||
|       if (var.def && var.def->variable_type) { | ||||
|         std::vector<QueryLocation> types = | ||||
|             GetDeclarationsOfSymbolForGotoDefinition( | ||||
|                 db, SymbolIdx(SymbolKind::Type, var.def->variable_type->id)); | ||||
|         ret.insert(ret.end(), types.begin(), types.end()); | ||||
|       } | ||||
|       return ret; | ||||
|     } | ||||
|     default: | ||||
|       return GetDeclarationsOfSymbolForGotoDefinition(db, symbol); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| struct TextDocumentDefinitionHandler | ||||
|     : BaseMessageHandler<Ipc_TextDocumentDefinition> { | ||||
|   void Run(Ipc_TextDocumentDefinition* request) override { | ||||
| @ -72,13 +95,13 @@ struct TextDocumentDefinitionHandler | ||||
|                        def_loc->range.Contains(target_line, target_column))) { | ||||
|         // Goto declaration.
 | ||||
| 
 | ||||
|         std::vector<QueryLocation> declarations = | ||||
|             GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx); | ||||
|         for (auto declaration : declarations) { | ||||
|           optional<lsLocation> ls_declaration = | ||||
|               GetLsLocation(db, working_files, declaration); | ||||
|           if (ls_declaration) | ||||
|             out.result.push_back(*ls_declaration); | ||||
|         std::vector<QueryLocation> targets = | ||||
|             GetGotoDefinitionTargets(db, ref.idx); | ||||
|         for (QueryLocation target : targets) { | ||||
|           optional<lsLocation> ls_target = | ||||
|               GetLsLocation(db, working_files, target); | ||||
|           if (ls_target) | ||||
|             out.result.push_back(*ls_target); | ||||
|         } | ||||
|         // We found some declarations. Break so we don't add the definition
 | ||||
|         // location.
 | ||||
|  | ||||
| @ -33,6 +33,7 @@ std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db, | ||||
| std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition( | ||||
|     QueryDatabase* db, | ||||
|     const SymbolIdx& symbol); | ||||
| 
 | ||||
| bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root); | ||||
| std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, | ||||
|                                                         QueryFunc& root); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user