From cc1fbada4bc8b6c5a6bbf81b42926e89d8187c19 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Thu, 11 Jan 2018 00:32:45 -0800 Subject: [PATCH] Don't crash in completion if there is no working file. --- src/messages/text_document_completion.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index 3d923591..463f6b07 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -209,9 +209,18 @@ struct TextDocumentCompletionHandler : MessageHandler { auto request = std::shared_ptr( static_cast(message.release())); + auto write_empty_result = [request]() { + Out_TextDocumentComplete out; + out.id = request->id; + QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); + }; + std::string path = request->params.textDocument.uri.GetPath(); WorkingFile* file = working_files->GetFileByFilename(path); - assert(file); + if (!file) { + write_empty_result(); + return; + } // It shouldn't be possible, but sometimes vscode will send queries out // of order, ie, we get completion request before buffer content update. @@ -246,9 +255,7 @@ struct TextDocumentCompletionHandler : MessageHandler { } if (did_fail_check) { - Out_TextDocumentComplete out; - out.id = request->id; - QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out); + write_empty_result(); return; } }