Fix issue with function parameter autocomplete being screwed up when contracts are present

This commit is contained in:
Hackerpilot 2014-08-11 11:19:53 -07:00
parent 59dec3d4aa
commit 93f7c0eddf
3 changed files with 31 additions and 12 deletions

View File

@ -128,9 +128,33 @@ final class FirstPass : ASTVisitor
currentSymbol.addChild(symbol);
if (dec.functionBody !is null)
{
import std.algorithm;
size_t scopeBegin = min(
dec.functionBody.inStatement is null ? size_t.max : dec.functionBody.inStatement.blockStatement.startLocation,
dec.functionBody.outStatement is null ? size_t.max : dec.functionBody.outStatement.blockStatement.startLocation,
dec.functionBody.blockStatement is null ? size_t.max : dec.functionBody.blockStatement.startLocation,
dec.functionBody.bodyStatement is null ? size_t.max : dec.functionBody.bodyStatement.blockStatement.startLocation);
size_t scopeEnd = max(
dec.functionBody.inStatement is null ? 0 : dec.functionBody.inStatement.blockStatement.endLocation,
dec.functionBody.outStatement is null ? 0 : dec.functionBody.outStatement.blockStatement.endLocation,
dec.functionBody.blockStatement is null ? 0 : dec.functionBody.blockStatement.endLocation,
dec.functionBody.bodyStatement is null ? 0 : dec.functionBody.bodyStatement.blockStatement.endLocation);
foreach (child; symbol.children)
{
if (child.acSymbol.location == size_t.max)
{
// Log.trace("Reassigning location of ", child.acSymbol.name);
child.acSymbol.location = scopeBegin + 1;
}
}
Scope* s = allocate!Scope(semanticAllocator, scopeBegin, scopeEnd);
currentScope.children.insert(s);
s.parent = currentScope;
currentScope = s;
currentSymbol = symbol;
dec.functionBody.accept(this);
currentSymbol = symbol.parent;
currentScope = s.parent;
}
}
@ -377,17 +401,6 @@ final class FirstPass : ASTVisitor
s.parent = currentScope;
currentScope.children.insert(s);
if (currentSymbol.acSymbol.kind == CompletionKind.functionName)
{
foreach (child; currentSymbol.children)
{
if (child.acSymbol.location == size_t.max)
{
// Log.trace("Reassigning location of ", child.acSymbol.name);
child.acSymbol.location = s.startLocation + 1;
}
}
}
if (blockStatement.declarationsAndStatements !is null)
{
currentScope = s;

View File

@ -59,6 +59,12 @@ private:
void assignToScopes(ACSymbol* currentSymbol)
{
Scope* s = moduleScope.getScopeByCursor(currentSymbol.location);
// Look for a parent scope whose start location equals this scope's
// start location. This only happens in the case of functions with
// contracts. Use this outer scope that covers the in, out, and body
// instead of the smaller scope found by getScopeByCursor.
if (s.parent !is null && s.parent.startLocation == s.startLocation)
s = s.parent;
if (currentSymbol.kind != CompletionKind.moduleName)
s.symbols.insert(currentSymbol);
foreach (part; currentSymbol.parts[])

@ -1 +1 @@
Subproject commit 5a39c333a1264753b067d4ba34ebfa1e7a2f04fa
Subproject commit d9fb61d666304a4fcede0b583202fde3e0498785