dlang-community / DCD

The D Completion Daemon is an auto-complete program for the D programming language
GNU General Public License v3.0
349 stars 71 forks source link

Fix ArraySliceError in complete.d when there is no paren. #754

Closed drpriver closed 1 year ago

drpriver commented 1 year ago

goBackToOpenParen can return size_t.max, which the calling code in getCalltipHint did not handle (and accidentally returns via an out parameter).

Check for this case so we don't get an array slice error.

Before this patch I would get a crash after typing the comma in code like this:

enum Foo {
    X,
}
src/dcd/server/autocomplete/complete.d:366 pure nothrow @nogc @safe dcd.server.autocomplete.complete.CalltipHint dcd.server.autocomplete.complete.getCalltipHint!(std.range.SortedRange!(const(std.experimental.lexer.TokenStructure!(ubyte, "import dparse.lexer:TokenTriviaFields,TriviaToken; mixin TokenTriviaFields;").TokenStructure)[], "a < b", 0).SortedRange).getCalltipHint(std.range.SortedRange!(const(std.experimental.lexer.TokenStructure!(ubyte, "import dparse.lexer:TokenTriviaFields,TriviaToken; mixin TokenTriviaFields;").TokenStructure)[], "a < b", 0).SortedRange, out ulong) [0x1006ebf3f]
src/dcd/server/autocomplete/complete.d:140 dcd.common.messages.AutocompleteResponse dcd.server.autocomplete.complete.complete(const(dcd.common.messages.AutocompleteRequest), ref dsymbol.modulecache.ModuleCache) [0x1006a812b]
src/dcd/server/main.d:337 pure @nogc @safe dcd.common.messages.AutocompleteResponse dcd.server.main.runServer(immutable(char)[][]).__dgliteral66() [0x1006a777b]
src/dcd/server/main.d:362 void dcd.server.main.trySendResponse(std.socket.Socket, lazy dcd.common.messages.AutocompleteResponse, lazy immutable(char)[]) [0x1006a6ecb]
src/dcd/server/main.d:337 int dcd.server.main.runServer(immutable(char)[][]) [0x1006a46f3]
src/dcd/server/main.d:63 _Dmain [0x1006a06a3]
github-actions[bot] commented 1 year ago

Thanks for your Pull Request and making D better!

This comment will automatically be updated to summarize some statistics in a few minutes.

vushu commented 1 year ago

thanks! :)