Response "being indexed" instead of "not found".

This commit is contained in:
scturtle 2017-12-31 11:18:33 +08:00 committed by Fangrui Song
parent 77e9ea1b77
commit 4c2dff39ef
26 changed files with 53 additions and 41 deletions

View File

@ -19,6 +19,7 @@ MessageHandler::MessageHandler() {
std::vector<MessageHandler*>* MessageHandler::message_handlers = nullptr; std::vector<MessageHandler*>* MessageHandler::message_handlers = nullptr;
bool FindFileOrFail(QueryDatabase* db, bool FindFileOrFail(QueryDatabase* db,
const Project *project,
optional<lsRequestId> id, optional<lsRequestId> id,
const std::string& absolute_path, const std::string& absolute_path,
QueryFile** out_query_file, QueryFile** out_query_file,
@ -39,6 +40,11 @@ bool FindFileOrFail(QueryDatabase* db,
if (out_file_id) if (out_file_id)
*out_file_id = QueryFileId((size_t)-1); *out_file_id = QueryFileId((size_t)-1);
bool indexing = project->absolute_path_to_entry_index_.find(absolute_path) !=
project->absolute_path_to_entry_index_.end();
if (indexing)
LOG_S(INFO) << "\"" << absolute_path << "\" is being indexed.";
else
LOG_S(INFO) << "Unable to find file \"" << absolute_path << "\""; LOG_S(INFO) << "Unable to find file \"" << absolute_path << "\"";
/* /*
LOG_S(INFO) << "Files (size=" << db->usr_to_file.size() << "): " LOG_S(INFO) << "Files (size=" << db->usr_to_file.size() << "): "
@ -51,8 +57,13 @@ bool FindFileOrFail(QueryDatabase* db,
if (id) { if (id) {
Out_Error out; Out_Error out;
out.id = *id; out.id = *id;
if (indexing) {
out.error.code = lsErrorCodes::ServerNotInitialized;
out.error.message = absolute_path + " is being indexed.";
} else {
out.error.code = lsErrorCodes::InternalError; out.error.code = lsErrorCodes::InternalError;
out.error.message = "Unable to find file " + absolute_path; out.error.message = "Unable to find file " + absolute_path;
}
QueueManager::WriteStdout(IpcId::Unknown, out); QueueManager::WriteStdout(IpcId::Unknown, out);
} }

View File

@ -3,6 +3,7 @@
#include "ipc.h" #include "ipc.h"
#include "language_server_api.h" #include "language_server_api.h"
#include "query.h" #include "query.h"
#include "project.h"
#include <optional.h> #include <optional.h>
@ -17,7 +18,6 @@ struct ImportManager;
struct ImportPipelineStatus; struct ImportPipelineStatus;
struct IncludeComplete; struct IncludeComplete;
struct MultiQueueWaiter; struct MultiQueueWaiter;
struct Project;
struct QueryDatabase; struct QueryDatabase;
struct SemanticHighlightSymbolCache; struct SemanticHighlightSymbolCache;
struct TimestampManager; struct TimestampManager;
@ -75,6 +75,7 @@ struct BaseMessageHandler : MessageHandler {
}; };
bool FindFileOrFail(QueryDatabase* db, bool FindFileOrFail(QueryDatabase* db,
const Project *project,
optional<lsRequestId> id, optional<lsRequestId> id,
const std::string& absolute_path, const std::string& absolute_path,
QueryFile** out_query_file, QueryFile** out_query_file,

View File

@ -14,7 +14,7 @@ REGISTER_IPC_MESSAGE(Ipc_CqueryBase);
struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> { struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> {
void Run(Ipc_CqueryBase* request) override { void Run(Ipc_CqueryBase* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -178,7 +178,7 @@ struct CqueryCallTreeInitialHandler
: BaseMessageHandler<Ipc_CqueryCallTreeInitial> { : BaseMessageHandler<Ipc_CqueryCallTreeInitial> {
void Run(Ipc_CqueryCallTreeInitial* request) override { void Run(Ipc_CqueryCallTreeInitial* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -14,7 +14,7 @@ REGISTER_IPC_MESSAGE(Ipc_CqueryCallers);
struct CqueryCallersHandler : BaseMessageHandler<Ipc_CqueryCallers> { struct CqueryCallersHandler : BaseMessageHandler<Ipc_CqueryCallers> {
void Run(Ipc_CqueryCallers* request) override { void Run(Ipc_CqueryCallers* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -14,7 +14,7 @@ REGISTER_IPC_MESSAGE(Ipc_CqueryDerived);
struct CqueryDerivedHandler : BaseMessageHandler<Ipc_CqueryDerived> { struct CqueryDerivedHandler : BaseMessageHandler<Ipc_CqueryDerived> {
void Run(Ipc_CqueryDerived* request) override { void Run(Ipc_CqueryDerived* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -25,7 +25,7 @@ struct CqueryDidViewHandler
if (!working_file) if (!working_file)
return; return;
QueryFile* file = nullptr; QueryFile* file = nullptr;
if (!FindFileOrFail(db, nullopt, path, &file)) if (!FindFileOrFail(db, project, nullopt, path, &file))
return; return;
clang_complete->NotifyView(path); clang_complete->NotifyView(path);

View File

@ -167,7 +167,7 @@ struct CqueryTypeHierarchyTreeHandler
: BaseMessageHandler<Ipc_CqueryTypeHierarchyTree> { : BaseMessageHandler<Ipc_CqueryTypeHierarchyTree> {
void Run(Ipc_CqueryTypeHierarchyTree* request) override { void Run(Ipc_CqueryTypeHierarchyTree* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) request->params.textDocument.uri.GetPath(), &file))
return; return;

View File

@ -14,7 +14,7 @@ REGISTER_IPC_MESSAGE(Ipc_CqueryVars);
struct CqueryVarsHandler : BaseMessageHandler<Ipc_CqueryVars> { struct CqueryVarsHandler : BaseMessageHandler<Ipc_CqueryVars> {
void Run(Ipc_CqueryVars* request) override { void Run(Ipc_CqueryVars* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -312,7 +312,7 @@ struct TextDocumentCodeActionHandler
QueryFileId file_id; QueryFileId file_id;
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file, request->params.textDocument.uri.GetPath(), &file,
&file_id)) { &file_id)) {
return; return;

View File

@ -131,7 +131,7 @@ struct TextDocumentCodeLensHandler
clang_complete->NotifyView(path); clang_complete->NotifyView(path);
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -52,7 +52,7 @@ struct TextDocumentDefinitionHandler
void Run(Ipc_TextDocumentDefinition* request) override { void Run(Ipc_TextDocumentDefinition* request) override {
QueryFileId file_id; QueryFileId file_id;
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file, request->params.textDocument.uri.GetPath(), &file,
&file_id)) { &file_id)) {
return; return;

View File

@ -43,7 +43,7 @@ struct TextDocumentDidOpenHandler
working_file->SetIndexContent(working_file->buffer_content); working_file->SetIndexContent(working_file->buffer_content);
QueryFile* file = nullptr; QueryFile* file = nullptr;
FindFileOrFail(db, nullopt, path, &file); FindFileOrFail(db, project, nullopt, path, &file);
if (file && file->def) { if (file && file->def) {
EmitInactiveLines(working_file, file->def->inactive_regions); EmitInactiveLines(working_file, file->def->inactive_regions);
EmitSemanticHighlighting(db, semantic_cache, working_file, file); EmitSemanticHighlighting(db, semantic_cache, working_file, file);

View File

@ -48,7 +48,7 @@ struct TextDocumentDocumentLinkHandler
if (config->showDocumentLinksOnIncludes) { if (config->showDocumentLinksOnIncludes) {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -32,7 +32,7 @@ struct TextDocumentDocumentSymbolHandler
out.id = request->id; out.id = request->id;
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -25,7 +25,7 @@ struct TextDocumentDocumentHighlightHandler
void Run(Ipc_TextDocumentDocumentHighlight* request) override { void Run(Ipc_TextDocumentDocumentHighlight* request) override {
QueryFileId file_id; QueryFileId file_id;
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file, request->params.textDocument.uri.GetPath(), &file,
&file_id)) { &file_id)) {
return; return;

View File

@ -75,7 +75,7 @@ void Reflect(Writer& visitor, Out_TextDocumentHover& value) {
struct TextDocumentHoverHandler : BaseMessageHandler<Ipc_TextDocumentHover> { struct TextDocumentHoverHandler : BaseMessageHandler<Ipc_TextDocumentHover> {
void Run(Ipc_TextDocumentHover* request) override { void Run(Ipc_TextDocumentHover* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -42,7 +42,7 @@ struct TextDocumentReferencesHandler
: BaseMessageHandler<Ipc_TextDocumentReferences> { : BaseMessageHandler<Ipc_TextDocumentReferences> {
void Run(Ipc_TextDocumentReferences* request) override { void Run(Ipc_TextDocumentReferences* request) override {
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file)) { request->params.textDocument.uri.GetPath(), &file)) {
return; return;
} }

View File

@ -84,7 +84,7 @@ struct TextDocumentRenameHandler : BaseMessageHandler<Ipc_TextDocumentRename> {
void Run(Ipc_TextDocumentRename* request) override { void Run(Ipc_TextDocumentRename* request) override {
QueryFileId file_id; QueryFileId file_id;
QueryFile* file; QueryFile* file;
if (!FindFileOrFail(db, request->id, if (!FindFileOrFail(db, project, request->id,
request->params.textDocument.uri.GetPath(), &file, request->params.textDocument.uri.GetPath(), &file,
&file_id)) { &file_id)) {
return; return;