Browse Source

textDocument/documentSymbol: support unopened files (#548)

Jan Lahoda 5 years ago
committed by Fangrui Song
parent
commit
a2ecd9a8f0
  1. 4
      src/message_handler.cc
  2. 3
      src/message_handler.hh
  3. 4
      src/messages/textDocument_document.cc

4
src/message_handler.cc

@ -252,9 +252,9 @@ QueryFile *MessageHandler::findFile(const std::string &path, int *out_file_id) {
std::pair<QueryFile *, WorkingFile *> std::pair<QueryFile *, WorkingFile *>
MessageHandler::findOrFail(const std::string &path, ReplyOnce &reply, MessageHandler::findOrFail(const std::string &path, ReplyOnce &reply,
int *out_file_id) { int *out_file_id, bool allow_unopened) {
WorkingFile *wf = wfiles->getFile(path); WorkingFile *wf = wfiles->getFile(path);
if (!wf) { if (!wf && !allow_unopened) {
reply.notOpened(path); reply.notOpened(path);
return {nullptr, nullptr}; return {nullptr, nullptr};
} }

3
src/message_handler.hh

@ -236,7 +236,8 @@ struct MessageHandler {
QueryFile *findFile(const std::string &path, int *out_file_id = nullptr); QueryFile *findFile(const std::string &path, int *out_file_id = nullptr);
std::pair<QueryFile *, WorkingFile *> findOrFail(const std::string &path, std::pair<QueryFile *, WorkingFile *> findOrFail(const std::string &path,
ReplyOnce &reply, ReplyOnce &reply,
int *out_file_id = nullptr); int *out_file_id = nullptr,
bool allow_unopened = false);
private: private:
void bind(const char *method, void (MessageHandler::*handler)(JsonReader &)); void bind(const char *method, void (MessageHandler::*handler)(JsonReader &));

4
src/messages/textDocument_document.cc

@ -147,8 +147,8 @@ void MessageHandler::textDocument_documentSymbol(JsonReader &reader,
int file_id; int file_id;
auto [file, wf] = auto [file, wf] =
findOrFail(param.textDocument.uri.getPath(), reply, &file_id); findOrFail(param.textDocument.uri.getPath(), reply, &file_id, true);
if (!wf) if (!file)
return; return;
auto allows = [&](SymbolRef sym) { return !(sym.role & param.excludeRole); }; auto allows = [&](SymbolRef sym) { return !(sym.role & param.excludeRole); };

Loading…
Cancel
Save