Fix autocomplete on foreach expressions

This commit is contained in:
Hackerpilot 2015-02-07 00:42:18 -08:00
parent 81e652c4c8
commit 5964940d41
6 changed files with 57 additions and 5 deletions

View File

@ -453,11 +453,7 @@ final class FirstPass : ASTVisitor
feType.identifier.text, CompletionKind.variableName,
symbolFile, feType.identifier.index, feType.type);
if (symbol.type is null && feExpression !is null)
{
// Log.trace("Populating initializer");
populateInitializer(symbol, feExpression, true);
// Log.trace(symbol.initializer[]);
}
symbol.parent = currentSymbol;
currentSymbol.addChild(symbol);
}
@ -888,6 +884,15 @@ class InitializerVisitor : ASTVisitor
on = false;
}
override void visit(const ExpressionNode expression)
{
on = true;
expression.accept(this);
if (appendForeach)
semanticSymbol.initializer.insert(internString("foreach"));
on = false;
}
SemanticSymbol* semanticSymbol;
bool on = false;
const bool appendForeach;

View File

@ -26,6 +26,7 @@ import actypes;
import messages;
import std.allocator;
import string_interning;
import stupidlog;
/**
* Third pass handles the following:
@ -95,7 +96,6 @@ private:
void thirdPass(SemanticSymbol* currentSymbol)
{
// Log.trace("third pass on ", currentSymbol.acSymbol.name);
with (CompletionKind) final switch (currentSymbol.acSymbol.kind)
{
case className:
@ -242,6 +242,7 @@ private:
s = s.type;
if (slice.front == "foreach")
{
// Log.trace("foreach");
if (s.qualifier == SymbolQualifier.array)
s = s.type;
else
@ -252,6 +253,7 @@ private:
else
s = null;
}
slice.popFront();
}
else if (slice.front == "[]")
s = s.type;

12
tests/tc007/expected1.txt Normal file
View File

@ -0,0 +1,12 @@
identifiers
alignof k
dup k
idup k
init k
length k
mangleof k
ptr k
reverse k
sizeof k
sort k
stringof k

View File

@ -0,0 +1,8 @@
identifiers
alignof k
init k
mangleof k
max k
min k
sizeof k
stringof k

17
tests/tc007/file.d Normal file
View File

@ -0,0 +1,17 @@
struct R { int front() { return 1; } }
void main(string[] args)
{
foreach (arg; args)
{
arg.
}
R r;
foreach (i; r)
{
i.
}
}

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

@ -0,0 +1,8 @@
set -e
set -u
dcd-client file.d -c97 > actual1.txt
diff actual1.txt expected1.txt
dcd-client file.d -c130 > actual2.txt
diff actual2.txt expected2.txt