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,7 +40,12 @@ 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);
LOG_S(INFO) << "Unable to find file \"" << absolute_path << "\""; 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) << "Files (size=" << db->usr_to_file.size() << "): " LOG_S(INFO) << "Files (size=" << db->usr_to_file.size() << "): "
<< StringJoinMap(db->usr_to_file, << StringJoinMap(db->usr_to_file,
@ -51,8 +57,13 @@ bool FindFileOrFail(QueryDatabase* db,
if (id) { if (id) {
Out_Error out; Out_Error out;
out.id = *id; out.id = *id;
out.error.code = lsErrorCodes::InternalError; if (indexing) {
out.error.message = "Unable to find file " + absolute_path; out.error.code = lsErrorCodes::ServerNotInitialized;
out.error.message = absolute_path + " is being indexed.";
} else {
out.error.code = lsErrorCodes::InternalError;
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;
} }
@ -44,4 +44,4 @@ struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryBaseHandler); REGISTER_MESSAGE_HANDLER(CqueryBaseHandler);
} // namespace } // namespace

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;
} }
@ -217,4 +217,4 @@ struct CqueryCallTreeExpandHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryCallTreeExpandHandler); REGISTER_MESSAGE_HANDLER(CqueryCallTreeExpandHandler);
} // namespace } // namespace

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;
} }
@ -42,4 +42,4 @@ struct CqueryCallersHandler : BaseMessageHandler<Ipc_CqueryCallers> {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryCallersHandler); REGISTER_MESSAGE_HANDLER(CqueryCallersHandler);
} // namespace } // namespace

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;
} }
@ -42,4 +42,4 @@ struct CqueryDerivedHandler : BaseMessageHandler<Ipc_CqueryDerived> {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryDerivedHandler); REGISTER_MESSAGE_HANDLER(CqueryDerivedHandler);
} // namespace } // namespace

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);
@ -36,4 +36,4 @@ struct CqueryDidViewHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryDidViewHandler); REGISTER_MESSAGE_HANDLER(CqueryDidViewHandler);
} // namespace } // namespace

View File

@ -61,4 +61,4 @@ struct CqueryFreshenIndexHandler : MessageHandler {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryFreshenIndexHandler); REGISTER_MESSAGE_HANDLER(CqueryFreshenIndexHandler);
} // namespace } // namespace

View File

@ -33,4 +33,4 @@ struct CqueryIndexFileHandler : BaseMessageHandler<Ipc_CqueryIndexFile> {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryIndexFileHandler); REGISTER_MESSAGE_HANDLER(CqueryIndexFileHandler);
} // namespace } // namespace

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;
@ -195,4 +195,4 @@ struct CqueryTypeHierarchyTreeHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryTypeHierarchyTreeHandler); REGISTER_MESSAGE_HANDLER(CqueryTypeHierarchyTreeHandler);
} // namespace } // namespace

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;
} }
@ -37,4 +37,4 @@ struct CqueryVarsHandler : BaseMessageHandler<Ipc_CqueryVars> {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryVarsHandler); REGISTER_MESSAGE_HANDLER(CqueryVarsHandler);
} // namespace } // namespace

View File

@ -41,4 +41,4 @@ struct CqueryWaitHandler : MessageHandler {
} }
}; };
REGISTER_MESSAGE_HANDLER(CqueryWaitHandler); REGISTER_MESSAGE_HANDLER(CqueryWaitHandler);
} // namespace } // namespace

View File

@ -18,4 +18,4 @@ struct ExitHandler : MessageHandler {
} }
}; };
REGISTER_MESSAGE_HANDLER(ExitHandler); REGISTER_MESSAGE_HANDLER(ExitHandler);
} // namespace } // namespace

View File

@ -209,4 +209,4 @@ struct InitializeHandler : BaseMessageHandler<Ipc_InitializeRequest> {
} }
}; };
REGISTER_MESSAGE_HANDLER(InitializeHandler); REGISTER_MESSAGE_HANDLER(InitializeHandler);
} // namespace } // namespace

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;
@ -593,4 +593,4 @@ TEST_SUITE("FindIncludeLine") {
REQUIRE(FindIncludeLine(lines, "#include <e>") == 7); REQUIRE(FindIncludeLine(lines, "#include <e>") == 7);
} }
} }
} // namespace } // namespace

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

@ -23,4 +23,4 @@ struct TextDocumentDidChangeHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentDidChangeHandler); REGISTER_MESSAGE_HANDLER(TextDocumentDidChangeHandler);
} // namespace } // namespace

View File

@ -32,4 +32,4 @@ struct TextDocumentDidCloseHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentDidCloseHandler); REGISTER_MESSAGE_HANDLER(TextDocumentDidCloseHandler);
} // namespace } // namespace

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;
} }
@ -86,4 +86,4 @@ struct TextDocumentDocumentLinkHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentDocumentLinkHandler); REGISTER_MESSAGE_HANDLER(TextDocumentDocumentLinkHandler);
} // namespace } // namespace

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;
} }
@ -54,4 +54,4 @@ struct TextDocumentDocumentSymbolHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentDocumentSymbolHandler); REGISTER_MESSAGE_HANDLER(TextDocumentDocumentSymbolHandler);
} // namespace } // namespace

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;
@ -63,4 +63,4 @@ struct TextDocumentDocumentHighlightHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentDocumentHighlightHandler); REGISTER_MESSAGE_HANDLER(TextDocumentDocumentHighlightHandler);
} // namespace } // namespace

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;
} }
@ -80,4 +80,4 @@ struct TextDocumentReferencesHandler
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentReferencesHandler); REGISTER_MESSAGE_HANDLER(TextDocumentReferencesHandler);
} // namespace } // namespace

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;
@ -109,4 +109,4 @@ struct TextDocumentRenameHandler : BaseMessageHandler<Ipc_TextDocumentRename> {
} }
}; };
REGISTER_MESSAGE_HANDLER(TextDocumentRenameHandler); REGISTER_MESSAGE_HANDLER(TextDocumentRenameHandler);
} // namespace } // namespace