diff --git a/common/src/dcd/common/messages.d b/common/src/dcd/common/messages.d index a4e6913..b14373e 100644 --- a/common/src/dcd/common/messages.d +++ b/common/src/dcd/common/messages.d @@ -78,6 +78,10 @@ enum RequestKind : ushort localUse = 0b00000010_00000000, /// Remove import directory from server removeImport = 0b00000100_00000000, + + /// These request kinds require source code and won't be executed if there + /// is no source sent + requiresSourceCode = autocomplete | doc | symbolLocation | search | localUse, // dfmt on } diff --git a/src/dcd/server/main.d b/src/dcd/server/main.d index a8254fa..6ab9b8f 100644 --- a/src/dcd/server/main.d +++ b/src/dcd/server/main.d @@ -281,22 +281,33 @@ int runServer(string[] args) info("Returning import path list"); s.sendResponse(response); } - else if (request.kind & RequestKind.autocomplete) + else { - info("Getting completions"); - s.sendResponse(complete(request, cache)); + // these requests operate on and require source code + + if ((request.kind & RequestKind.requiresSourceCode) + && !request.sourceCode.length) + { + warning("Received a ", request.kind, " request without source code"); + s.sendResponse(AutocompleteResponse.init); + } + else if (request.kind & RequestKind.autocomplete) + { + info("Getting completions"); + s.sendResponse(complete(request, cache)); + } + else if (request.kind & RequestKind.doc) + { + info("Getting doc comment"); + s.trySendResponse(getDoc(request, cache), "Could not get DDoc information"); + } + else if (request.kind & RequestKind.symbolLocation) + s.trySendResponse(findDeclaration(request, cache), "Could not get symbol location"); + else if (request.kind & RequestKind.search) + s.sendResponse(symbolSearch(request, cache)); + else if (request.kind & RequestKind.localUse) + s.trySendResponse(findLocalUse(request, cache), "Couldnot find local usage"); } - else if (request.kind & RequestKind.doc) - { - info("Getting doc comment"); - s.trySendResponse(getDoc(request, cache), "Could not get DDoc information"); - } - else if (request.kind & RequestKind.symbolLocation) - s.trySendResponse(findDeclaration(request, cache), "Could not get symbol location"); - else if (request.kind & RequestKind.search) - s.sendResponse(symbolSearch(request, cache)); - else if (request.kind & RequestKind.localUse) - s.trySendResponse(findLocalUse(request, cache), "Couldnot find local usage"); sw.stop(); info("Request processed in ", sw.peek().total!"msecs"(), " milliseconds"); diff --git a/tests/tc_empty_requests/run.sh b/tests/tc_empty_requests/run.sh new file mode 100755 index 0000000..3095748 --- /dev/null +++ b/tests/tc_empty_requests/run.sh @@ -0,0 +1,7 @@ +set -e +set -u + +../../bin/dcd-client $1 -s foo < /dev/null +../../bin/dcd-client $1 -c 1 < /dev/null +../../bin/dcd-client $1 -d -c 1 < /dev/null +../../bin/dcd-client $1 -u -c 1 < /dev/null