[clangd] Don't crash on empty textDocument/didChange.

Found by clangd-fuzzer.

llvm-svn: 316652
This commit is contained in:
Benjamin Kramer 2017-10-26 10:36:20 +00:00
parent 56a02ce91a
commit b560a9a1b8
2 changed files with 6 additions and 0 deletions

View File

@ -73,6 +73,8 @@ void ClangdLSPServer::onDocumentDidOpen(Ctx C,
void ClangdLSPServer::onDocumentDidChange(Ctx C,
DidChangeTextDocumentParams &Params) {
if (Params.contentChanges.size() != 1)
return C.replyError(-32602, "can only apply one change at a time");
// We only support full syncing right now.
Server.addDocument(Params.textDocument.uri.file,
Params.contentChanges[0].text);

View File

@ -26,6 +26,10 @@ Content-Length: 246
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n fake f;\n f.\n}\n"}}}
Content-Length: 104
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///main.cpp"}}}
Content-Type: application/vscode-jsonrpc; charset-utf-8
Content-Length: 146