Make overridden flags persistent

didOpen can override flags from compilation database.
didSave was able to reset the flags back.
This makes sure that the overridden flags persist.
This commit is contained in:
Boris Staletic 2018-03-21 20:49:28 +01:00 committed by Jacob Dufault
parent 7e6965afe3
commit bdabb7596c
3 changed files with 28 additions and 1 deletions

View File

@ -61,7 +61,7 @@ struct TextDocumentDidOpenHandler
clang_complete->NotifyView(path);
// Submit new index request.
const Project::Entry& entry = project->FindCompilationEntryForFile(path);
Project::Entry entry = project->FindCompilationEntryForFile(path);
QueueManager::instance()->index_request.PushBack(
Index_Request(
entry.filename, params.args.size() ? params.args : entry.args,
@ -70,6 +70,9 @@ struct TextDocumentDidOpenHandler
clang_complete->FlushSession(entry.filename);
LOG_S(INFO) << "Flushed clang complete sessions for " << entry.filename;
if (params.args.size()) {
project->SetFlagsForFile(params.args, path);
}
}
};
REGISTER_MESSAGE_HANDLER(TextDocumentDidOpenHandler);

View File

@ -569,6 +569,23 @@ void Project::Load(Config* config, const std::string& root_directory) {
absolute_path_to_entry_index_[entries[i].filename] = i;
}
void Project::SetFlagsForFile(
const std::vector<std::string>& flags,
const std::string& path) {
auto it = absolute_path_to_entry_index_.find(path);
if (it != absolute_path_to_entry_index_.end()) {
// The entry already exists in the project, just set the flags.
this->entries[it->second].args = flags;
} else {
// Entry wasn't found, so we create a new one.
Entry entry;
entry.is_inferred = false;
entry.filename = path;
entry.args = flags;
this->entries.emplace_back(entry);
}
}
Project::Entry Project::FindCompilationEntryForFile(
const std::string& filename) {
auto it = absolute_path_to_entry_index_.find(filename);

View File

@ -48,6 +48,13 @@ struct Project {
// will infer one based on existing project structure.
Entry FindCompilationEntryForFile(const std::string& filename);
// If the client has overridden the flags, or specified them for a file
// that is not in the compilation_database.json make sure those changes
// are permanent.
void SetFlagsForFile(
const std::vector<std::string>& flags,
const std::string& path);
// Run |action| on every file in the project.
void ForAllFilteredFiles(
Config* config,