Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Jan 24, 2017
2 parents 6ac2b02 + c9dd5fc commit 0f5d369
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 30 deletions.
31 changes: 5 additions & 26 deletions Rubberduck.Parsing/Preprocessing/LivelinessExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,23 @@ public LivelinessExpression(IExpression isAlive, IExpression code)

public override IValue Evaluate()
{
bool isAlive = _isAlive.Evaluate().AsBool;
var isAlive = _isAlive.Evaluate().AsBool;
var code = _code.Evaluate().AsString;
if (isAlive)
{
return new StringValue(code);
}
else
{
return new StringValue(MarkAsDead(code));
}
return isAlive ? new StringValue(code) : new StringValue(MarkAsDead(code));
}

private string MarkAsDead(string code)
{
bool hasNewLine = false;
if (code.EndsWith(Environment.NewLine))
{
hasNewLine = true;
}
var hasNewLine = code.EndsWith(Environment.NewLine);
// Remove parsed new line.
code = code.TrimEnd('\r', '\n');
var lines = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
code = code.Substring(0, code.Length - Environment.NewLine.Length);
var lines = code.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var result = string.Join(Environment.NewLine, lines.Select(_ => string.Empty));
if (hasNewLine)
{
result += Environment.NewLine;
}
return result;
}

private string MarkLineAsDead(string line)
{
var result = string.Empty;
if (line.EndsWith(Environment.NewLine))
{
result += Environment.NewLine;
}
return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public IReadOnlyList<Declaration> Load()

private IReadOnlyList<Declaration> AddAliasDeclarations()
{
var finder = new DeclarationFinder(_state.AllDeclarations, new IAnnotation[] { });
var finder = _state.DeclarationFinder;;

if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DebugDeclarations(RubberduckParserState state)

public IReadOnlyList<Declaration> Load()
{
var finder = new DeclarationFinder(_state.AllDeclarations, new IAnnotation[] { });
var finder = _state.DeclarationFinder;;

if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IReadOnlyList<Declaration> Load()

private static Declaration FormsClassModuleFromParserState(RubberduckParserState state)
{
var finder = new DeclarationFinder(state.AllDeclarations, new IAnnotation[] { });
var finder = state.DeclarationFinder;

var msForms = finder.FindProject("MSForms");
if (msForms == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public SpecialFormDeclarations(RubberduckParserState state)

public IReadOnlyList<Declaration> Load()
{
var finder = new DeclarationFinder(_state.AllDeclarations, new IAnnotation[] { });
var finder = _state.DeclarationFinder;

if (WeHaveAlreadyLoadedTheDeclarationsBefore(finder))
{
Expand Down
6 changes: 6 additions & 0 deletions Rubberduck.Parsing/VBA/ParseCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ public void Parse(CancellationTokenSource token)
}

SyncComReferences(State.Projects);
State.RefreshFinder(_hostApp);

AddBuiltInDeclarations();
State.RefreshFinder(_hostApp);

foreach (var component in components)
{
Expand Down Expand Up @@ -229,7 +232,10 @@ private void ParseAll(object requestor, CancellationTokenSource token)
}

SyncComReferences(State.Projects);
State.RefreshFinder(_hostApp);

AddBuiltInDeclarations();
State.RefreshFinder(_hostApp);

// invalidation cleanup should go into ParseAsync?
foreach (var key in _componentAttributes.Keys)
Expand Down

0 comments on commit 0f5d369

Please sign in to comment.