mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 18:00:26 +00:00
Don't crash in completion if there is no working file.
This commit is contained in:
parent
beba312a5f
commit
cc1fbada4b
@ -209,9 +209,18 @@ struct TextDocumentCompletionHandler : MessageHandler {
|
|||||||
auto request = std::shared_ptr<Ipc_TextDocumentComplete>(
|
auto request = std::shared_ptr<Ipc_TextDocumentComplete>(
|
||||||
static_cast<Ipc_TextDocumentComplete*>(message.release()));
|
static_cast<Ipc_TextDocumentComplete*>(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();
|
std::string path = request->params.textDocument.uri.GetPath();
|
||||||
WorkingFile* file = working_files->GetFileByFilename(path);
|
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
|
// It shouldn't be possible, but sometimes vscode will send queries out
|
||||||
// of order, ie, we get completion request before buffer content update.
|
// of order, ie, we get completion request before buffer content update.
|
||||||
@ -246,9 +255,7 @@ struct TextDocumentCompletionHandler : MessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (did_fail_check) {
|
if (did_fail_check) {
|
||||||
Out_TextDocumentComplete out;
|
write_empty_result();
|
||||||
out.id = request->id;
|
|
||||||
QueueManager::WriteStdout(IpcId::TextDocumentCompletion, out);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user