mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
Index_Request::contents is no longer optional
This commit is contained in:
parent
a10bb50f51
commit
71591d7805
@ -49,7 +49,7 @@ std::vector<Index_DoIdMap> DoParseFile(
|
||||
bool is_interactive,
|
||||
const std::string& path,
|
||||
const std::vector<std::string>& args,
|
||||
const optional<FileContents>& contents) {
|
||||
const FileContents& contents) {
|
||||
std::vector<Index_DoIdMap> result;
|
||||
|
||||
// Always run this block, even if we are interactive, so we can check
|
||||
@ -168,17 +168,13 @@ std::vector<Index_DoIdMap> DoParseFile(
|
||||
// TODO: We might be able to optimize perf by only copying for files in
|
||||
// working_files. We can pass that same set of files to the indexer as
|
||||
// well. We then default to a fast file-copy if not in working set.
|
||||
bool loaded_primary = false;
|
||||
std::vector<FileContents> file_contents;
|
||||
if (contents) {
|
||||
loaded_primary = loaded_primary || contents->path == path;
|
||||
file_contents.push_back(*contents);
|
||||
}
|
||||
bool loaded_primary = contents.path == path;
|
||||
std::vector<FileContents> file_contents = {contents};
|
||||
cache_manager->IterateLoadedCaches([&](IndexFile* index) {
|
||||
// FIXME: ReadContent should go through |cache_manager|.
|
||||
optional<std::string> index_content = ReadContent(index->path);
|
||||
if (!index_content) {
|
||||
LOG_S(ERROR) << "Failed to preload index content for " << index->path;
|
||||
LOG_S(ERROR) << "Failed to load index content for " << index->path;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -226,10 +222,8 @@ std::vector<Index_DoIdMap> ParseFile(
|
||||
ImportManager* import_manager,
|
||||
bool is_interactive,
|
||||
const Project::Entry& entry,
|
||||
const optional<std::string>& contents) {
|
||||
optional<FileContents> file_contents;
|
||||
if (contents)
|
||||
file_contents = FileContents(entry.filename, *contents);
|
||||
const std::string& contents) {
|
||||
FileContents file_contents(entry.filename, contents);
|
||||
|
||||
std::unique_ptr<ICacheManager> cache_manager = ICacheManager::Make(config);
|
||||
|
||||
|
@ -45,15 +45,19 @@ struct CqueryFreshenIndexHandler : MessageHandler {
|
||||
auto* queue = QueueManager::instance();
|
||||
|
||||
// Send index requests for every file.
|
||||
project->ForAllFilteredFiles(config, [&](int i,
|
||||
const Project::Entry& entry) {
|
||||
LOG_S(INFO) << "[" << i << "/" << (project->entries.size() - 1)
|
||||
<< "] Dispatching index request for file " << entry.filename;
|
||||
bool is_interactive =
|
||||
working_files->GetFileByFilename(entry.filename) != nullptr;
|
||||
queue->index_request.Enqueue(
|
||||
Index_Request(entry.filename, entry.args, is_interactive, nullopt));
|
||||
});
|
||||
project->ForAllFilteredFiles(
|
||||
config, [&](int i, const Project::Entry& entry) {
|
||||
optional<std::string> content = ReadContent(entry.filename);
|
||||
if (!content) {
|
||||
LOG_S(ERROR) << "When freshening index, cannot read file "
|
||||
<< entry.filename;
|
||||
return;
|
||||
}
|
||||
bool is_interactive =
|
||||
working_files->GetFileByFilename(entry.filename) != nullptr;
|
||||
queue->index_request.Enqueue(Index_Request(entry.filename, entry.args,
|
||||
is_interactive, *content));
|
||||
});
|
||||
}
|
||||
};
|
||||
REGISTER_MESSAGE_HANDLER(CqueryFreshenIndexHandler);
|
||||
|
@ -191,10 +191,16 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
|
||||
time.Reset();
|
||||
project->ForAllFilteredFiles(
|
||||
config, [&](int i, const Project::Entry& entry) {
|
||||
optional<std::string> content = ReadContent(entry.filename);
|
||||
if (!content) {
|
||||
LOG_S(ERROR) << "When loading project, canont read file "
|
||||
<< entry.filename;
|
||||
return;
|
||||
}
|
||||
bool is_interactive =
|
||||
working_files->GetFileByFilename(entry.filename) != nullptr;
|
||||
queue->index_request.Enqueue(Index_Request(
|
||||
entry.filename, entry.args, is_interactive, nullopt));
|
||||
entry.filename, entry.args, is_interactive, *content));
|
||||
});
|
||||
|
||||
// We need to support multiple concurrent index processes.
|
||||
|
@ -57,8 +57,9 @@ struct TextDocumentDidOpenHandler
|
||||
|
||||
// Submit new index request.
|
||||
const Project::Entry& entry = project->FindCompilationEntryForFile(path);
|
||||
QueueManager::instance()->index_request.PriorityEnqueue(Index_Request(
|
||||
entry.filename, entry.args, true /*is_interactive*/, nullopt));
|
||||
QueueManager::instance()->index_request.PriorityEnqueue(
|
||||
Index_Request(entry.filename, entry.args, true /*is_interactive*/,
|
||||
request->params.textDocument.text));
|
||||
}
|
||||
};
|
||||
REGISTER_MESSAGE_HANDLER(TextDocumentDidOpenHandler);
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "project.h"
|
||||
#include "queue_manager.h"
|
||||
|
||||
#include <loguru/loguru.hpp>
|
||||
|
||||
namespace {
|
||||
struct Ipc_TextDocumentDidSave : public IpcMessage<Ipc_TextDocumentDidSave> {
|
||||
struct Params {
|
||||
@ -41,9 +43,14 @@ struct TextDocumentDidSaveHandler
|
||||
// mutex and check to see if we should skip the current request.
|
||||
// if so, ignore that index response.
|
||||
// TODO: send as priority request
|
||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
||||
QueueManager::instance()->index_request.Enqueue(Index_Request(
|
||||
entry.filename, entry.args, true /*is_interactive*/, nullopt));
|
||||
optional<std::string> content = ReadContent(path);
|
||||
if (!content) {
|
||||
LOG_S(ERROR) << "Unable to read file content after saving " << path;
|
||||
} else {
|
||||
Project::Entry entry = project->FindCompilationEntryForFile(path);
|
||||
QueueManager::instance()->index_request.Enqueue(Index_Request(
|
||||
entry.filename, entry.args, true /*is_interactive*/, *content));
|
||||
}
|
||||
|
||||
clang_complete->NotifySave(path);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
Index_Request::Index_Request(const std::string& path,
|
||||
const std::vector<std::string>& args,
|
||||
bool is_interactive,
|
||||
optional<std::string> contents)
|
||||
const std::string& contents)
|
||||
: path(path),
|
||||
args(args),
|
||||
is_interactive(is_interactive),
|
||||
|
@ -19,12 +19,12 @@ struct Index_Request {
|
||||
// TODO: make |args| a string that is parsed lazily.
|
||||
std::vector<std::string> args;
|
||||
bool is_interactive;
|
||||
optional<std::string> contents; // Preloaded contents. Useful for tests.
|
||||
std::string contents; // Preloaded contents. Useful for tests.
|
||||
|
||||
Index_Request(const std::string& path,
|
||||
const std::vector<std::string>& args,
|
||||
bool is_interactive,
|
||||
optional<std::string> contents);
|
||||
const std::string& contents);
|
||||
};
|
||||
|
||||
struct Index_DoIdMap {
|
||||
|
@ -71,6 +71,7 @@ void EnsureEndsInSlash(std::string& path);
|
||||
// e.g. foo/bar.c => foo_bar.c
|
||||
std::string EscapeFileName(std::string path);
|
||||
|
||||
// FIXME: Move ReadContent into ICacheManager?
|
||||
optional<std::string> ReadContent(const std::string& filename);
|
||||
std::vector<std::string> ReadLinesWithEnding(std::string filename);
|
||||
std::vector<std::string> ToLines(const std::string& content,
|
||||
|
Loading…
Reference in New Issue
Block a user