mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
CompilationEntry -> Project::Entry
This commit is contained in:
parent
b4fb350140
commit
2780e18040
@ -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<CXUnsavedFile> unsaved = working_files->AsUnsavedFiles();
|
||||
|
||||
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.
|
||||
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) {
|
||||
std::cerr << "Unable to find compilation entry" << std::endl;
|
||||
entry = CompilationEntry();
|
||||
entry = Project::Entry();
|
||||
entry->filename = filename;
|
||||
}
|
||||
else {
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <functional>
|
||||
|
||||
struct CompletionSession {
|
||||
CompilationEntry file;
|
||||
Project::Entry file;
|
||||
|
||||
// The active translation unit.
|
||||
std::unique_ptr<clang::TranslationUnit> active;
|
||||
@ -24,7 +24,7 @@ struct CompletionSession {
|
||||
//std::unique_ptr<clang::TranslationUnit> updated;
|
||||
//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();
|
||||
|
||||
// Refresh file index.
|
||||
|
@ -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<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();
|
||||
if (entry)
|
||||
request.args = entry->args;
|
||||
|
@ -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<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");
|
||||
if (!compile_commands_content)
|
||||
return {};
|
||||
@ -164,15 +164,15 @@ std::vector<CompilationEntry> LoadFromCompileCommandsJson(const std::string& pro
|
||||
std::vector<CompileCommandsEntry> entries;
|
||||
Reflect(reader, entries);
|
||||
|
||||
std::vector<CompilationEntry> result;
|
||||
std::vector<Project::Entry> result;
|
||||
result.reserve(entries.size());
|
||||
for (const auto& entry : entries)
|
||||
result.push_back(GetCompilationEntryFromCompileCommandEntry(entry));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<CompilationEntry> LoadFromDirectoryListing(const std::string& project_directory) {
|
||||
std::vector<CompilationEntry> result;
|
||||
std::vector<Project::Entry> LoadFromDirectoryListing(const std::string& project_directory) {
|
||||
std::vector<Project::Entry> result;
|
||||
|
||||
std::vector<std::string> args;
|
||||
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*/);
|
||||
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<CompilationEntry> LoadFromDirectoryListing(const std::string& projec
|
||||
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.
|
||||
//return LoadFromCompileCommandsJson(project_directory);
|
||||
|
||||
@ -214,7 +214,7 @@ std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::str
|
||||
CXCompileCommands cx_commands = clang_CompilationDatabase_getAllCompileCommands(cx_db);
|
||||
|
||||
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++) {
|
||||
CXCompileCommand cx_command = clang_CompileCommands_getCommand(cx_commands, i);
|
||||
|
||||
@ -245,7 +245,7 @@ void Project::Load(const std::string& 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) {
|
||||
if (filename == entry.filename)
|
||||
return entry;
|
||||
|
@ -7,13 +7,14 @@
|
||||
using std::experimental::optional;
|
||||
using std::experimental::nullopt;
|
||||
|
||||
struct CompilationEntry {
|
||||
std::string filename;
|
||||
std::vector<std::string> args;
|
||||
};
|
||||
|
||||
struct Project {
|
||||
std::vector<CompilationEntry> entries;
|
||||
struct Entry {
|
||||
std::string filename;
|
||||
std::vector<std::string> args;
|
||||
// optional<uint64_t> last_modification_time;
|
||||
};
|
||||
|
||||
std::vector<Entry> 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<CompilationEntry> FindCompilationEntryForFile(const std::string& filename);
|
||||
optional<Entry> FindCompilationEntryForFile(const std::string& filename);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user