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