diff --git a/src/code_completion.cc b/src/code_completion.cc index 5982cf5b..de0a57b1 100644 --- a/src/code_completion.cc +++ b/src/code_completion.cc @@ -324,7 +324,7 @@ void CompletionMain(CompletionManager* completion_manager) { } // namespace -CompletionSession::CompletionSession(const CompilationEntry& file, IndexerConfig* config, WorkingFiles* working_files) : file(file) { +CompletionSession::CompletionSession(const Project::Entry& file, IndexerConfig* config, WorkingFiles* working_files) : file(file) { std::vector unsaved = working_files->AsUnsavedFiles(); std::vector args = file.args; @@ -389,10 +389,10 @@ CompletionSession* CompletionManager::GetOrOpenSession(const std::string& filena // Create new session. Note that this will block. std::cerr << "Creating new code completion session for " << filename << std::endl; - optional entry = project->FindCompilationEntryForFile(filename); + optional entry = project->FindCompilationEntryForFile(filename); if (!entry) { std::cerr << "Unable to find compilation entry" << std::endl; - entry = CompilationEntry(); + entry = Project::Entry(); entry->filename = filename; } else { diff --git a/src/code_completion.h b/src/code_completion.h index 50b5c399..d767a0f2 100644 --- a/src/code_completion.h +++ b/src/code_completion.h @@ -11,7 +11,7 @@ #include struct CompletionSession { - CompilationEntry file; + Project::Entry file; // The active translation unit. std::unique_ptr active; @@ -24,7 +24,7 @@ struct CompletionSession { //std::unique_ptr updated; //std::unique_ptr updated_index; - CompletionSession(const CompilationEntry& file, IndexerConfig* config, WorkingFiles* working_files); + CompletionSession(const Project::Entry& file, IndexerConfig* config, WorkingFiles* working_files); ~CompletionSession(); // Refresh file index. diff --git a/src/command_line.cc b/src/command_line.cc index 31a4edc4..28f6d39a 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1108,7 +1108,7 @@ void QueryDbMainLoop( //for (int i = 0; i < 10; ++i) //std::cerr << project->entries[i].filename << std::endl; for (int i = 0; i < project->entries.size(); ++i) { - const CompilationEntry& entry = project->entries[i]; + const Project::Entry& entry = project->entries[i]; std::string filepath = entry.filename; @@ -1179,7 +1179,7 @@ void QueryDbMainLoop( // Send an index update request. Index_DoIndex request(Index_DoIndex::Type::Update); - optional entry = project->FindCompilationEntryForFile(msg->params.textDocument.uri.GetPath()); + optional entry = project->FindCompilationEntryForFile(msg->params.textDocument.uri.GetPath()); request.path = msg->params.textDocument.uri.GetPath(); if (entry) request.args = entry->args; diff --git a/src/project.cc b/src/project.cc index 7f06e08b..883dac05 100644 --- a/src/project.cc +++ b/src/project.cc @@ -100,8 +100,8 @@ static const char *kBlacklist[] = { "..", }; -CompilationEntry GetCompilationEntryFromCompileCommandEntry(const CompileCommandsEntry& entry) { - CompilationEntry result; +Project::Entry GetCompilationEntryFromCompileCommandEntry(const CompileCommandsEntry& entry) { + Project::Entry result; result.filename = NormalizePath(entry.file); size_t num_args = entry.args.size(); @@ -151,7 +151,7 @@ CompilationEntry GetCompilationEntryFromCompileCommandEntry(const CompileCommand return result; } -std::vector LoadFromCompileCommandsJson(const std::string& project_directory) { +std::vector LoadFromCompileCommandsJson(const std::string& project_directory) { optional compile_commands_content = ReadContent(project_directory + "/compile_commands.json"); if (!compile_commands_content) return {}; @@ -164,15 +164,15 @@ std::vector LoadFromCompileCommandsJson(const std::string& pro std::vector entries; Reflect(reader, entries); - std::vector result; + std::vector result; result.reserve(entries.size()); for (const auto& entry : entries) result.push_back(GetCompilationEntryFromCompileCommandEntry(entry)); return result; } -std::vector LoadFromDirectoryListing(const std::string& project_directory) { - std::vector result; +std::vector LoadFromDirectoryListing(const std::string& project_directory) { + std::vector result; std::vector args; std::cerr << "Using arguments: "; @@ -190,7 +190,7 @@ std::vector LoadFromDirectoryListing(const std::string& projec std::vector files = GetFilesInFolder(project_directory, true /*recursive*/, true /*add_folder_to_path*/); for (const std::string& file : files) { if (EndsWith(file, ".cc") || EndsWith(file, ".cpp") || EndsWith(file, ".c")) { - CompilationEntry entry; + Project::Entry entry; entry.filename = NormalizePath(file); entry.args = args; result.push_back(entry); @@ -200,7 +200,7 @@ std::vector LoadFromDirectoryListing(const std::string& projec return result; } -std::vector LoadCompilationEntriesFromDirectory(const std::string& project_directory) { +std::vector LoadCompilationEntriesFromDirectory(const std::string& project_directory) { // TODO: Figure out if this function or the clang one is faster. //return LoadFromCompileCommandsJson(project_directory); @@ -214,7 +214,7 @@ std::vector LoadCompilationEntriesFromDirectory(const std::str CXCompileCommands cx_commands = clang_CompilationDatabase_getAllCompileCommands(cx_db); unsigned int num_commands = clang_CompileCommands_getSize(cx_commands); - std::vector result; + std::vector result; for (unsigned int i = 0; i < num_commands; i++) { CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_commands, i); @@ -245,7 +245,7 @@ void Project::Load(const std::string& directory) { entries = LoadCompilationEntriesFromDirectory(directory); } -optional Project::FindCompilationEntryForFile(const std::string& filename) { +optional Project::FindCompilationEntryForFile(const std::string& filename) { for (auto& entry : entries) { if (filename == entry.filename) return entry; diff --git a/src/project.h b/src/project.h index 6e9ae891..8495d653 100644 --- a/src/project.h +++ b/src/project.h @@ -7,13 +7,14 @@ using std::experimental::optional; using std::experimental::nullopt; -struct CompilationEntry { - std::string filename; - std::vector args; -}; - struct Project { - std::vector entries; + struct Entry { + std::string filename; + std::vector args; + // optional last_modification_time; + }; + + std::vector entries; // Loads a project for the given |directory|. // @@ -24,6 +25,6 @@ struct Project { void Load(const std::string& directory); // Lookup the CompilationEntry for |filename|. - optional FindCompilationEntryForFile(const std::string& filename); + optional FindCompilationEntryForFile(const std::string& filename); };