diff --git a/src/message_handler.cc b/src/message_handler.cc index 6e9266e6..498a72de 100644 --- a/src/message_handler.cc +++ b/src/message_handler.cc @@ -252,9 +252,9 @@ QueryFile *MessageHandler::findFile(const std::string &path, int *out_file_id) { std::pair MessageHandler::findOrFail(const std::string &path, ReplyOnce &reply, - int *out_file_id) { + int *out_file_id, bool allow_unopened) { WorkingFile *wf = wfiles->getFile(path); - if (!wf) { + if (!wf && !allow_unopened) { reply.notOpened(path); return {nullptr, nullptr}; } diff --git a/src/message_handler.hh b/src/message_handler.hh index 02084b60..038b5bdd 100644 --- a/src/message_handler.hh +++ b/src/message_handler.hh @@ -236,7 +236,8 @@ struct MessageHandler { QueryFile *findFile(const std::string &path, int *out_file_id = nullptr); std::pair findOrFail(const std::string &path, ReplyOnce &reply, - int *out_file_id = nullptr); + int *out_file_id = nullptr, + bool allow_unopened = false); private: void bind(const char *method, void (MessageHandler::*handler)(JsonReader &)); diff --git a/src/messages/textDocument_document.cc b/src/messages/textDocument_document.cc index 1a977a5a..a1ce9494 100644 --- a/src/messages/textDocument_document.cc +++ b/src/messages/textDocument_document.cc @@ -147,8 +147,8 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader, int file_id; auto [file, wf] = - findOrFail(param.textDocument.uri.getPath(), reply, &file_id); - if (!wf) + findOrFail(param.textDocument.uri.getPath(), reply, &file_id, true); + if (!file) return; auto allows = [&](SymbolRef sym) { return !(sym.role & param.excludeRole); };