Index language as enum instead of string

This commit is contained in:
topisani 2017-11-30 22:56:55 +01:00 committed by Jacob Dufault
parent e6bcd05a7e
commit 4e153784f6
3 changed files with 44 additions and 19 deletions

View File

@ -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 = &param->ns;

View File

@ -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

View File

@ -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)));
};