mirror of
				https://github.com/MaskRay/ccls.git
				synced 2025-11-04 14:17:07 +00:00 
			
		
		
		
	CompilationEntry -> Project::Entry
This commit is contained in:
		
							parent
							
								
									b4fb350140
								
							
						
					
					
						commit
						2780e18040
					
				@ -324,7 +324,7 @@ void CompletionMain(CompletionManager* completion_manager) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}  // namespace
 | 
					}  // 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<CXUnsavedFile> unsaved = working_files->AsUnsavedFiles();
 | 
					  std::vector<CXUnsavedFile> unsaved = working_files->AsUnsavedFiles();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<std::string> args = file.args;
 | 
					  std::vector<std::string> args = file.args;
 | 
				
			||||||
@ -389,10 +389,10 @@ CompletionSession* CompletionManager::GetOrOpenSession(const std::string& filena
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // Create new session. Note that this will block.
 | 
					  // Create new session. Note that this will block.
 | 
				
			||||||
  std::cerr << "Creating new code completion session for " << filename << std::endl;
 | 
					  std::cerr << "Creating new code completion session for " << filename << std::endl;
 | 
				
			||||||
  optional<CompilationEntry> entry = project->FindCompilationEntryForFile(filename);
 | 
					  optional<Project::Entry> entry = project->FindCompilationEntryForFile(filename);
 | 
				
			||||||
  if (!entry) {
 | 
					  if (!entry) {
 | 
				
			||||||
    std::cerr << "Unable to find compilation entry" << std::endl;
 | 
					    std::cerr << "Unable to find compilation entry" << std::endl;
 | 
				
			||||||
    entry = CompilationEntry();
 | 
					    entry = Project::Entry();
 | 
				
			||||||
    entry->filename = filename;
 | 
					    entry->filename = filename;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  else {
 | 
					  else {
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@
 | 
				
			|||||||
#include <functional>
 | 
					#include <functional>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct CompletionSession {
 | 
					struct CompletionSession {
 | 
				
			||||||
  CompilationEntry file;
 | 
					  Project::Entry file;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // The active translation unit.
 | 
					  // The active translation unit.
 | 
				
			||||||
  std::unique_ptr<clang::TranslationUnit> active;
 | 
					  std::unique_ptr<clang::TranslationUnit> active;
 | 
				
			||||||
@ -24,7 +24,7 @@ struct CompletionSession {
 | 
				
			|||||||
  //std::unique_ptr<clang::TranslationUnit> updated;
 | 
					  //std::unique_ptr<clang::TranslationUnit> updated;
 | 
				
			||||||
  //std::unique_ptr<clang::Index> updated_index;
 | 
					  //std::unique_ptr<clang::Index> updated_index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  CompletionSession(const CompilationEntry& file, IndexerConfig* config, WorkingFiles* working_files);
 | 
					  CompletionSession(const Project::Entry& file, IndexerConfig* config, WorkingFiles* working_files);
 | 
				
			||||||
  ~CompletionSession();
 | 
					  ~CompletionSession();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Refresh file index.
 | 
					  // Refresh file index.
 | 
				
			||||||
 | 
				
			|||||||
@ -1108,7 +1108,7 @@ void QueryDbMainLoop(
 | 
				
			|||||||
      //for (int i = 0; i < 10; ++i)
 | 
					      //for (int i = 0; i < 10; ++i)
 | 
				
			||||||
        //std::cerr << project->entries[i].filename << std::endl;
 | 
					        //std::cerr << project->entries[i].filename << std::endl;
 | 
				
			||||||
      for (int i = 0; i < project->entries.size(); ++i) {
 | 
					      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;
 | 
					        std::string filepath = entry.filename;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1179,7 +1179,7 @@ void QueryDbMainLoop(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      // Send an index update request.
 | 
					      // Send an index update request.
 | 
				
			||||||
      Index_DoIndex request(Index_DoIndex::Type::Update);
 | 
					      Index_DoIndex request(Index_DoIndex::Type::Update);
 | 
				
			||||||
      optional<CompilationEntry> entry = project->FindCompilationEntryForFile(msg->params.textDocument.uri.GetPath());
 | 
					      optional<Project::Entry> entry = project->FindCompilationEntryForFile(msg->params.textDocument.uri.GetPath());
 | 
				
			||||||
      request.path = msg->params.textDocument.uri.GetPath();
 | 
					      request.path = msg->params.textDocument.uri.GetPath();
 | 
				
			||||||
      if (entry)
 | 
					      if (entry)
 | 
				
			||||||
        request.args = entry->args;
 | 
					        request.args = entry->args;
 | 
				
			||||||
 | 
				
			|||||||
@ -100,8 +100,8 @@ static const char *kBlacklist[] = {
 | 
				
			|||||||
  "..",
 | 
					  "..",
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CompilationEntry GetCompilationEntryFromCompileCommandEntry(const CompileCommandsEntry& entry) {
 | 
					Project::Entry GetCompilationEntryFromCompileCommandEntry(const CompileCommandsEntry& entry) {
 | 
				
			||||||
  CompilationEntry result;
 | 
					  Project::Entry result;
 | 
				
			||||||
  result.filename = NormalizePath(entry.file);
 | 
					  result.filename = NormalizePath(entry.file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  size_t num_args = entry.args.size();
 | 
					  size_t num_args = entry.args.size();
 | 
				
			||||||
@ -151,7 +151,7 @@ CompilationEntry GetCompilationEntryFromCompileCommandEntry(const CompileCommand
 | 
				
			|||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::vector<CompilationEntry> LoadFromCompileCommandsJson(const std::string& project_directory) {
 | 
					std::vector<Project::Entry> LoadFromCompileCommandsJson(const std::string& project_directory) {
 | 
				
			||||||
  optional<std::string> compile_commands_content = ReadContent(project_directory + "/compile_commands.json");
 | 
					  optional<std::string> compile_commands_content = ReadContent(project_directory + "/compile_commands.json");
 | 
				
			||||||
  if (!compile_commands_content)
 | 
					  if (!compile_commands_content)
 | 
				
			||||||
    return {};
 | 
					    return {};
 | 
				
			||||||
@ -164,15 +164,15 @@ std::vector<CompilationEntry> LoadFromCompileCommandsJson(const std::string& pro
 | 
				
			|||||||
  std::vector<CompileCommandsEntry> entries;
 | 
					  std::vector<CompileCommandsEntry> entries;
 | 
				
			||||||
  Reflect(reader, entries);
 | 
					  Reflect(reader, entries);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<CompilationEntry> result;
 | 
					  std::vector<Project::Entry> result;
 | 
				
			||||||
  result.reserve(entries.size());
 | 
					  result.reserve(entries.size());
 | 
				
			||||||
  for (const auto& entry : entries)
 | 
					  for (const auto& entry : entries)
 | 
				
			||||||
    result.push_back(GetCompilationEntryFromCompileCommandEntry(entry));
 | 
					    result.push_back(GetCompilationEntryFromCompileCommandEntry(entry));
 | 
				
			||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::vector<CompilationEntry> LoadFromDirectoryListing(const std::string& project_directory) {
 | 
					std::vector<Project::Entry> LoadFromDirectoryListing(const std::string& project_directory) {
 | 
				
			||||||
  std::vector<CompilationEntry> result;
 | 
					  std::vector<Project::Entry> result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<std::string> args;
 | 
					  std::vector<std::string> args;
 | 
				
			||||||
  std::cerr << "Using arguments: ";
 | 
					  std::cerr << "Using arguments: ";
 | 
				
			||||||
@ -190,7 +190,7 @@ std::vector<CompilationEntry> LoadFromDirectoryListing(const std::string& projec
 | 
				
			|||||||
  std::vector<std::string> files = GetFilesInFolder(project_directory, true /*recursive*/, true /*add_folder_to_path*/);
 | 
					  std::vector<std::string> files = GetFilesInFolder(project_directory, true /*recursive*/, true /*add_folder_to_path*/);
 | 
				
			||||||
  for (const std::string& file : files) {
 | 
					  for (const std::string& file : files) {
 | 
				
			||||||
    if (EndsWith(file, ".cc") || EndsWith(file, ".cpp") || EndsWith(file, ".c")) {
 | 
					    if (EndsWith(file, ".cc") || EndsWith(file, ".cpp") || EndsWith(file, ".c")) {
 | 
				
			||||||
      CompilationEntry entry;
 | 
					      Project::Entry entry;
 | 
				
			||||||
      entry.filename = NormalizePath(file);
 | 
					      entry.filename = NormalizePath(file);
 | 
				
			||||||
      entry.args = args;
 | 
					      entry.args = args;
 | 
				
			||||||
      result.push_back(entry);
 | 
					      result.push_back(entry);
 | 
				
			||||||
@ -200,7 +200,7 @@ std::vector<CompilationEntry> LoadFromDirectoryListing(const std::string& projec
 | 
				
			|||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::string& project_directory) {
 | 
					std::vector<Project::Entry> LoadCompilationEntriesFromDirectory(const std::string& project_directory) {
 | 
				
			||||||
  // TODO: Figure out if this function or the clang one is faster.
 | 
					  // TODO: Figure out if this function or the clang one is faster.
 | 
				
			||||||
  //return LoadFromCompileCommandsJson(project_directory);
 | 
					  //return LoadFromCompileCommandsJson(project_directory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -214,7 +214,7 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
 | 
				
			|||||||
  CXCompileCommands cx_commands = clang_CompilationDatabase_getAllCompileCommands(cx_db);
 | 
					  CXCompileCommands cx_commands = clang_CompilationDatabase_getAllCompileCommands(cx_db);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unsigned int num_commands = clang_CompileCommands_getSize(cx_commands);
 | 
					  unsigned int num_commands = clang_CompileCommands_getSize(cx_commands);
 | 
				
			||||||
  std::vector<CompilationEntry> result;
 | 
					  std::vector<Project::Entry> result;
 | 
				
			||||||
  for (unsigned int i = 0; i < num_commands; i++) {
 | 
					  for (unsigned int i = 0; i < num_commands; i++) {
 | 
				
			||||||
    CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_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);
 | 
					  entries = LoadCompilationEntriesFromDirectory(directory);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
optional<CompilationEntry> Project::FindCompilationEntryForFile(const std::string& filename) {
 | 
					optional<Project::Entry> Project::FindCompilationEntryForFile(const std::string& filename) {
 | 
				
			||||||
  for (auto& entry : entries) {
 | 
					  for (auto& entry : entries) {
 | 
				
			||||||
    if (filename == entry.filename)
 | 
					    if (filename == entry.filename)
 | 
				
			||||||
      return entry;
 | 
					      return entry;
 | 
				
			||||||
 | 
				
			|||||||
@ -7,13 +7,14 @@
 | 
				
			|||||||
using std::experimental::optional;
 | 
					using std::experimental::optional;
 | 
				
			||||||
using std::experimental::nullopt;
 | 
					using std::experimental::nullopt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct CompilationEntry {
 | 
					struct Project {
 | 
				
			||||||
 | 
					  struct Entry {
 | 
				
			||||||
    std::string filename;
 | 
					    std::string filename;
 | 
				
			||||||
    std::vector<std::string> args;
 | 
					    std::vector<std::string> args;
 | 
				
			||||||
};
 | 
					    // optional<uint64_t> last_modification_time;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct Project {
 | 
					  std::vector<Entry> entries;
 | 
				
			||||||
  std::vector<CompilationEntry> entries;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Loads a project for the given |directory|.
 | 
					  // Loads a project for the given |directory|.
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
@ -24,6 +25,6 @@ struct Project {
 | 
				
			|||||||
  void Load(const std::string& directory);
 | 
					  void Load(const std::string& directory);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Lookup the CompilationEntry for |filename|.
 | 
					  // Lookup the CompilationEntry for |filename|.
 | 
				
			||||||
  optional<CompilationEntry> FindCompilationEntryForFile(const std::string& filename);
 | 
					  optional<Entry> FindCompilationEntryForFile(const std::string& filename);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user