add RequestKind.requiresSourceCode, fix #617
this is a or-combined mask of the request kinds which operate on `request.sourceCode`. Before if a client sent a request without source code (with empty source) to one of these commands, the server would crash with an assertion failure, now the server returns an empty response.
This commit is contained in:
parent
8e44bf8a3e
commit
8c53181ffd
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue