mirror of
https://github.com/MaskRay/ccls.git
synced 2025-04-15 21:32:13 +00:00
FileNeedsParse is a separate function
This commit is contained in:
parent
4c1ee74b27
commit
bc2521382d
@ -83,45 +83,16 @@ struct ActiveThread {
|
|||||||
|
|
||||||
enum class FileParseQuery { NeedsParse, DoesNotNeedParse, NoSuchFile };
|
enum class FileParseQuery { NeedsParse, DoesNotNeedParse, NoSuchFile };
|
||||||
|
|
||||||
|
|
||||||
std::vector<Index_DoIdMap> ParseFile(
|
|
||||||
Config* config,
|
|
||||||
WorkingFiles* working_files,
|
|
||||||
FileConsumerSharedState* file_consumer_shared,
|
|
||||||
TimestampManager* timestamp_manager,
|
|
||||||
ImportManager* import_manager,
|
|
||||||
ICacheManager* cache_manager,
|
|
||||||
IIndexer* indexer,
|
|
||||||
bool is_interactive,
|
|
||||||
const Project::Entry& entry,
|
|
||||||
const std::string& entry_contents) {
|
|
||||||
|
|
||||||
FileContents contents(entry.filename, entry_contents);
|
|
||||||
|
|
||||||
// If the file is inferred, we may not actually be able to parse that file
|
|
||||||
// directly (ie, a header file, which are not listed in the project). If this
|
|
||||||
// file is inferred, then try to use the file which originally imported it.
|
|
||||||
std::string path = entry.filename;
|
|
||||||
if (entry.is_inferred) {
|
|
||||||
IndexFile* entry_cache = cache_manager->TryLoad(entry.filename);
|
|
||||||
if (entry_cache)
|
|
||||||
path = entry_cache->import_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Index_DoIdMap> result;
|
|
||||||
|
|
||||||
// Always run this block, even if we are interactive, so we can check
|
|
||||||
// dependencies and reset files in |file_consumer_shared|.
|
|
||||||
IndexFile* previous_index = cache_manager->TryLoad(path);
|
|
||||||
if (previous_index) {
|
|
||||||
// If none of the dependencies have changed and the index is not
|
|
||||||
// interactive (ie, requested by a file save), skip parsing and just load
|
|
||||||
// from cache.
|
|
||||||
|
|
||||||
// Checks if |path| needs to be reparsed. This will modify cached state
|
// Checks if |path| needs to be reparsed. This will modify cached state
|
||||||
// such that calling this function twice with the same path may return true
|
// such that calling this function twice with the same path may return true
|
||||||
// the first time but will return false the second.
|
// the first time but will return false the second.
|
||||||
auto file_needs_parse = [&](const std::string& path, bool is_dependency) {
|
FileParseQuery FileNeedsParse(bool is_interactive,
|
||||||
|
TimestampManager* timestamp_manager,
|
||||||
|
ImportManager* import_manager,
|
||||||
|
ICacheManager* cache_manager,
|
||||||
|
FileConsumerSharedState* file_consumer_shared,
|
||||||
|
const std::string& path,
|
||||||
|
bool is_dependency) {
|
||||||
// If the file is a dependency but another file as already imported it,
|
// If the file is a dependency but another file as already imported it,
|
||||||
// don't bother.
|
// don't bother.
|
||||||
if (!is_interactive && is_dependency &&
|
if (!is_interactive && is_dependency &&
|
||||||
@ -149,8 +120,43 @@ std::vector<Index_DoIdMap> ParseFile(
|
|||||||
return FileParseQuery::DoesNotNeedParse;
|
return FileParseQuery::DoesNotNeedParse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<Index_DoIdMap> ParseFile(
|
||||||
|
Config* config,
|
||||||
|
WorkingFiles* working_files,
|
||||||
|
FileConsumerSharedState* file_consumer_shared,
|
||||||
|
TimestampManager* timestamp_manager,
|
||||||
|
ImportManager* import_manager,
|
||||||
|
ICacheManager* cache_manager,
|
||||||
|
IIndexer* indexer,
|
||||||
|
bool is_interactive,
|
||||||
|
const Project::Entry& entry,
|
||||||
|
const std::string& entry_contents) {
|
||||||
|
FileContents contents(entry.filename, entry_contents);
|
||||||
|
|
||||||
|
// If the file is inferred, we may not actually be able to parse that file
|
||||||
|
// directly (ie, a header file, which are not listed in the project). If this
|
||||||
|
// file is inferred, then try to use the file which originally imported it.
|
||||||
|
std::string path = entry.filename;
|
||||||
|
if (entry.is_inferred) {
|
||||||
|
IndexFile* entry_cache = cache_manager->TryLoad(entry.filename);
|
||||||
|
if (entry_cache)
|
||||||
|
path = entry_cache->import_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Index_DoIdMap> result;
|
||||||
|
|
||||||
|
// Always run this block, even if we are interactive, so we can check
|
||||||
|
// dependencies and reset files in |file_consumer_shared|.
|
||||||
|
IndexFile* previous_index = cache_manager->TryLoad(path);
|
||||||
|
if (previous_index) {
|
||||||
|
// If none of the dependencies have changed and the index is not
|
||||||
|
// interactive (ie, requested by a file save), skip parsing and just load
|
||||||
|
// from cache.
|
||||||
|
|
||||||
// Check timestamps and update |file_consumer_shared|.
|
// Check timestamps and update |file_consumer_shared|.
|
||||||
FileParseQuery path_state = file_needs_parse(path, false /*is_dependency*/);
|
FileParseQuery path_state = FileNeedsParse(
|
||||||
|
is_interactive, timestamp_manager, import_manager, cache_manager,
|
||||||
|
file_consumer_shared, path, false /*is_dependency*/);
|
||||||
|
|
||||||
// Target file does not exist on disk, do not emit any indexes.
|
// Target file does not exist on disk, do not emit any indexes.
|
||||||
// TODO: Dependencies should be reassigned to other files. We can do this by
|
// TODO: Dependencies should be reassigned to other files. We can do this by
|
||||||
@ -166,7 +172,9 @@ std::vector<Index_DoIdMap> ParseFile(
|
|||||||
assert(!dependency.empty());
|
assert(!dependency.empty());
|
||||||
|
|
||||||
// note: Use != as there are multiple failure results for FileParseQuery.
|
// note: Use != as there are multiple failure results for FileParseQuery.
|
||||||
if (file_needs_parse(dependency, true /*is_dependency*/) !=
|
if (FileNeedsParse(is_interactive, timestamp_manager, import_manager,
|
||||||
|
cache_manager, file_consumer_shared, dependency,
|
||||||
|
true /*is_dependency*/) !=
|
||||||
FileParseQuery::DoesNotNeedParse) {
|
FileParseQuery::DoesNotNeedParse) {
|
||||||
LOG_S(INFO) << "Timestamp has changed for " << dependency << " (via "
|
LOG_S(INFO) << "Timestamp has changed for " << dependency << " (via "
|
||||||
<< previous_index->path << ")";
|
<< previous_index->path << ")";
|
||||||
@ -609,7 +617,8 @@ bool QueryDb_ImportMain(Config* config,
|
|||||||
WorkingFile* working_file =
|
WorkingFile* working_file =
|
||||||
working_files->GetFileByFilename(updated_file.path);
|
working_files->GetFileByFilename(updated_file.path);
|
||||||
if (working_file) {
|
if (working_file) {
|
||||||
QueryFileId file_id = db->usr_to_file[LowerPathIfCaseInsensitive(working_file->filename)];
|
QueryFileId file_id =
|
||||||
|
db->usr_to_file[LowerPathIfCaseInsensitive(working_file->filename)];
|
||||||
QueryFile* file = &db->files[file_id.id];
|
QueryFile* file = &db->files[file_id.id];
|
||||||
EmitSemanticHighlighting(db, semantic_cache, working_file, file);
|
EmitSemanticHighlighting(db, semantic_cache, working_file, file);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user