fix #382 - No completion when current string is a keyword

This commit is contained in:
Basile Burg 2018-04-24 23:58:31 +02:00
parent 24d415a537
commit 5a8b2f7838
5 changed files with 21 additions and 0 deletions

View File

@ -57,6 +57,15 @@ public AutocompleteResponse complete(const AutocompleteRequest request,
auto stringCache = StringCache(StringCache.defaultBucketCount);
auto beforeTokens = getTokensBeforeCursor(request.sourceCode,
request.cursorPosition, stringCache, tokenArray);
// allows to get completion on keyword, typically "is"
if (beforeTokens.length && isKeyword(beforeTokens[$-1].type))
{
Token* fakeIdent = cast(Token*) (&beforeTokens[$-1]);
fakeIdent.text = str(fakeIdent.type);
fakeIdent.type = tok!"identifier";
}
if (beforeTokens.length >= 2)
{
if (beforeTokens[$ - 1] == tok!"(" || beforeTokens[$ - 1] == tok!"["

View File

@ -0,0 +1,2 @@
identifiers
isBig v

View File

@ -0,0 +1 @@
bool isBig; void foo(){is}

View File

@ -0,0 +1 @@
struct F{bool isBig;} void foo(){F f; f.is}

8
tests/tc_complete_kw/run.sh Executable file
View File

@ -0,0 +1,8 @@
set -e
set -u
../../bin/dcd-client $1 file1.d -c25 > actual1.txt
diff actual1.txt expected1.txt
../../bin/dcd-client $1 file2.d -c42 > actual2.txt
diff actual2.txt expected1.txt