From 385531521f9ad18faf51ac20574ac463878326cc Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 26 May 2017 23:51:32 -0700 Subject: [PATCH] Harden against bad language server method call in completion. --- src/command_line.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/command_line.cc b/src/command_line.cc index 399bbc99..ff147729 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -1972,7 +1972,11 @@ bool QueryDbMainLoop( // TODO: We should scan include directories to add any missing paths - std::string buffer_line = file->all_buffer_lines[msg->params.position.line]; + // It shouldn't be possible, but sometimes vscode will send queries out + // of order, ie, we get completion request before buffer content update. + std::string buffer_line; + if (msg->params.position.line >= 0 && msg->params.position.line < file->all_buffer_lines.size()) + buffer_line = file->all_buffer_lines[msg->params.position.line]; if (ShouldRunIncludeCompletion(buffer_line)) { Out_TextDocumentComplete complete_response;