mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-30 20:22:38 +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); | 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 | struct TextDocumentDefinitionHandler | ||||||
|     : BaseMessageHandler<Ipc_TextDocumentDefinition> { |     : BaseMessageHandler<Ipc_TextDocumentDefinition> { | ||||||
|   void Run(Ipc_TextDocumentDefinition* request) override { |   void Run(Ipc_TextDocumentDefinition* request) override { | ||||||
| @ -72,13 +95,13 @@ struct TextDocumentDefinitionHandler | |||||||
|                        def_loc->range.Contains(target_line, target_column))) { |                        def_loc->range.Contains(target_line, target_column))) { | ||||||
|         // Goto declaration.
 |         // Goto declaration.
 | ||||||
| 
 | 
 | ||||||
|         std::vector<QueryLocation> declarations = |         std::vector<QueryLocation> targets = | ||||||
|             GetDeclarationsOfSymbolForGotoDefinition(db, ref.idx); |             GetGotoDefinitionTargets(db, ref.idx); | ||||||
|         for (auto declaration : declarations) { |         for (QueryLocation target : targets) { | ||||||
|           optional<lsLocation> ls_declaration = |           optional<lsLocation> ls_target = | ||||||
|               GetLsLocation(db, working_files, declaration); |               GetLsLocation(db, working_files, target); | ||||||
|           if (ls_declaration) |           if (ls_target) | ||||||
|             out.result.push_back(*ls_declaration); |             out.result.push_back(*ls_target); | ||||||
|         } |         } | ||||||
|         // We found some declarations. Break so we don't add the definition
 |         // We found some declarations. Break so we don't add the definition
 | ||||||
|         // location.
 |         // location.
 | ||||||
| @ -110,4 +133,4 @@ struct TextDocumentDefinitionHandler | |||||||
|   } |   } | ||||||
| }; | }; | ||||||
| REGISTER_MESSAGE_HANDLER(TextDocumentDefinitionHandler); | REGISTER_MESSAGE_HANDLER(TextDocumentDefinitionHandler); | ||||||
| }  // namespace
 | }  // namespace
 | ||||||
|  | |||||||
| @ -556,4 +556,4 @@ std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file, | |||||||
|             }); |             }); | ||||||
| 
 | 
 | ||||||
|   return symbols; |   return symbols; | ||||||
| } | } | ||||||
|  | |||||||
| @ -33,6 +33,7 @@ std::vector<QueryLocation> GetUsesOfSymbol(QueryDatabase* db, | |||||||
| std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition( | std::vector<QueryLocation> GetDeclarationsOfSymbolForGotoDefinition( | ||||||
|     QueryDatabase* db, |     QueryDatabase* db, | ||||||
|     const SymbolIdx& symbol); |     const SymbolIdx& symbol); | ||||||
|  | 
 | ||||||
| bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root); | bool HasCallersOnSelfOrBaseOrDerived(QueryDatabase* db, QueryFunc& root); | ||||||
| std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, | std::vector<QueryFuncRef> GetCallersForAllBaseFunctions(QueryDatabase* db, | ||||||
|                                                         QueryFunc& root); |                                                         QueryFunc& root); | ||||||
| @ -65,4 +66,4 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db, | |||||||
| 
 | 
 | ||||||
| std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file, | std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file, | ||||||
|                                              QueryFile* file, |                                              QueryFile* file, | ||||||
|                                              lsPosition position); |                                              lsPosition position); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user