mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-10-30 20:22:38 +00:00 
			
		
		
		
	Index language as enum instead of string
This commit is contained in:
		
							parent
							
								
									e6bcd05a7e
								
							
						
					
					
						commit
						4e153784f6
					
				| @ -996,21 +996,23 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { | ||||
|     return; | ||||
| 
 | ||||
| 
 | ||||
|   // update the file language
 | ||||
|   // TODO: only do this when |is_first_ownership| in ConsumeFile is true
 | ||||
|   // The language of this declaration
 | ||||
|   LanguageId declLang = [decl] () { | ||||
|       switch (clang_getCursorLanguage(decl->cursor)) { | ||||
|       case CXLanguage_C: | ||||
|     db->language = "c"; | ||||
|     break; | ||||
|         return LanguageId::C; | ||||
|       case CXLanguage_CPlusPlus: | ||||
|     db->language = "cpp"; | ||||
|     break; | ||||
|         return LanguageId::Cpp; | ||||
|       case CXLanguage_ObjC: | ||||
|     db->language = "objectivec"; | ||||
|     break; | ||||
|   case CXLanguage_Invalid: | ||||
|     db->language = "invalid"; | ||||
|     break; | ||||
|         return LanguageId::ObjC; | ||||
|       default: | ||||
|         return LanguageId::Unknown; | ||||
|       }; | ||||
|   } (); | ||||
| 
 | ||||
|   // Only update the file language if the new language is "greater" than the old
 | ||||
|   if (declLang > db->language) { | ||||
|     db->language = declLang; | ||||
|   } | ||||
| 
 | ||||
|   NamespaceHelper* ns = ¶m->ns; | ||||
|  | ||||
| @ -464,6 +464,18 @@ struct IndexInclude { | ||||
|   std::string resolved_path; | ||||
| }; | ||||
| 
 | ||||
| // Used to identify the language at a file level. The ordering is important, as
 | ||||
| // a file previously identified as `C`, will be changed to `Cpp` if it
 | ||||
| // encounters a c++ declaration.
 | ||||
| enum class LanguageId { | ||||
|   Unknown = 0, | ||||
|   C = 1, | ||||
|   Cpp = 2, | ||||
|   ObjC = 3 | ||||
| }; | ||||
| 
 | ||||
| MAKE_REFLECT_TYPE_PROXY(LanguageId, std::underlying_type<LanguageId>::type); | ||||
| 
 | ||||
| struct IndexFile { | ||||
|   IdCache id_cache; | ||||
| 
 | ||||
| @ -473,9 +485,7 @@ struct IndexFile { | ||||
|   std::string path; | ||||
|   std::vector<std::string> args; | ||||
|   int64_t last_modification_time = 0; | ||||
|   // markdown compatible language identifier.
 | ||||
|   // "cpp", "c", "objectivec", or invalid"
 | ||||
|   std::string language; | ||||
|   LanguageId language = LanguageId::Unknown; | ||||
| 
 | ||||
|   // The path to the translation unit cc file which caused the creation of this
 | ||||
|   // IndexFile. When parsing a translation unit we generate many IndexFile
 | ||||
|  | ||||
							
								
								
									
										15
									
								
								src/query.cc
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/query.cc
									
									
									
									
									
								
							| @ -171,10 +171,23 @@ void CompareGroups(std::vector<T>& previous_data, | ||||
| QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) { | ||||
|   QueryFile::Def def; | ||||
|   def.path = indexed.path; | ||||
|   def.language = indexed.language; | ||||
|   def.includes = indexed.includes; | ||||
|   def.inactive_regions = indexed.skipped_by_preprocessor; | ||||
| 
 | ||||
|   // Convert enum to markdown compatible strings
 | ||||
|   def.language = [indexed] () { | ||||
|       switch (indexed.language) { | ||||
|       case LanguageId::C: | ||||
|         return "c"; | ||||
|       case LanguageId::Cpp: | ||||
|         return "cpp"; | ||||
|       case LanguageId::ObjC: | ||||
|         return "objectivec"; | ||||
|       default: | ||||
|         return ""; | ||||
|       } | ||||
|     } (); | ||||
| 
 | ||||
|   auto add_outline = [&def, &id_map](SymbolIdx idx, Range range) { | ||||
|     def.outline.push_back(SymbolRef(idx, id_map.ToQuery(range))); | ||||
|   }; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user