Skip to content

Commit eb8a10d

Browse files
committed
Merge pull request #1640 from Hosch250/IHateTheCache
I hate the cache
2 parents dd8f43e + 33ca3c0 commit eb8a10d

File tree

3 files changed

+22
-47
lines changed

3 files changed

+22
-47
lines changed

RetailCoder.VBE/App.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProje
339339
}
340340

341341
_logger.Debug("Project '{0}' (ID {1}) was renamed to '{2}'.", e.OldName, e.Item.HelpFile, e.Item.Name);
342-
_parser.State.RemoveProject(e.Item.HelpFile);
342+
343+
// note: if a bug is discovered with renaming a project, it may just need to be removed and readded.
344+
343345
_parser.State.OnParseRequested(sender);
344346
}
345347

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private readonly IDictionary<VBComponent, IDictionary<Tuple<string, DeclarationT
4949
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
5050

5151
public RubberduckParser(
52-
VBE vbe,
52+
VBE vbe,
5353
RubberduckParserState state,
5454
IAttributeParser attributeParser,
5555
Func<IVBAPreprocessor> preprocessorFactory)

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public sealed class RubberduckParserState : IDisposable
6464
public event EventHandler<ParseRequestEventArgs> ParseRequest;
6565
public event EventHandler<RubberduckStatusMessageEventArgs> StatusMessageUpdate;
6666

67-
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
67+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
6868

6969
public void OnStatusMessageUpdate(string message)
7070
{
@@ -129,7 +129,7 @@ public IReadOnlyList<Tuple<VBComponent, SyntaxErrorException>> ModuleExceptions
129129
return _moduleStates.Select(kvp => Tuple.Create(kvp.Key.Component, kvp.Value.ModuleException))
130130
.Where(item => item.Item2 != null)
131131
.ToList();
132-
}
132+
}
133133
}
134134

135135
public event EventHandler<ParserStateEventArgs> StateChanged;
@@ -154,26 +154,12 @@ private void OnModuleStateChanged(VBComponent component, ParserState state)
154154
}
155155
}
156156

157-
public void SetModuleState(ParserState state)
158-
{
159-
var projects = Projects
160-
.Where(project => project.Protection == vbext_ProjectProtection.vbext_pp_none)
161-
.ToList();
162-
163-
var components = projects.SelectMany(p => p.VBComponents.Cast<VBComponent>()).ToList();
164-
foreach (var component in components)
165-
{
166-
SetModuleState(component, state);
167-
}
168-
}
169-
170157
public void SetModuleState(VBComponent component, ParserState state, SyntaxErrorException parserError = null)
171158
{
172159
if (AllUserDeclarations.Any())
173160
{
174161
var projectId = component.Collection.Parent.HelpFile;
175-
var project = AllUserDeclarations.SingleOrDefault(item =>
176-
item.DeclarationType == DeclarationType.Project && item.ProjectId == projectId);
162+
var project = _projects.SingleOrDefault(item => item.Value().HelpFile == projectId).Value();
177163

178164
if (project == null)
179165
{
@@ -187,7 +173,7 @@ public void SetModuleState(VBComponent component, ParserState state, SyntaxError
187173

188174
_moduleStates.AddOrUpdate(key, new ModuleState(state), (c, e) => e.SetState(state));
189175
_moduleStates.AddOrUpdate(key, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError));
190-
_logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", key.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
176+
Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", key.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
191177
OnModuleStateChanged(component, state);
192178
Status = EvaluateParserState();
193179
}
@@ -214,20 +200,20 @@ private ParserState EvaluateParserState()
214200
if (state != default(ParserState))
215201
{
216202
// if all modules are in the same state, we have our result.
217-
_logger.Debug("ParserState evaluates to '{0}' (thread {1})", state, Thread.CurrentThread.ManagedThreadId);
203+
Logger.Debug("ParserState evaluates to '{0}' (thread {1})", state, Thread.CurrentThread.ManagedThreadId);
218204
return state;
219205
}
220206

221207
// error state takes precedence over every other state
222208
if (moduleStates.Any(ms => ms == ParserState.Error))
223209
{
224-
_logger.Debug("ParserState evaluates to '{0}' (thread {1})", ParserState.Error,
210+
Logger.Debug("ParserState evaluates to '{0}' (thread {1})", ParserState.Error,
225211
Thread.CurrentThread.ManagedThreadId);
226212
return ParserState.Error;
227213
}
228214
if (moduleStates.Any(ms => ms == ParserState.ResolverError))
229215
{
230-
_logger.Debug("ParserState evaluates to '{0}' (thread {1})", ParserState.ResolverError,
216+
Logger.Debug("ParserState evaluates to '{0}' (thread {1})", ParserState.ResolverError,
231217
Thread.CurrentThread.ManagedThreadId);
232218
return ParserState.ResolverError;
233219
}
@@ -250,7 +236,7 @@ private ParserState EvaluateParserState()
250236

251237
Debug.Assert(result != ParserState.Ready || moduleStates.All(item => item == ParserState.Ready || item == ParserState.None));
252238

253-
_logger.Debug("ParserState evaluates to '{0}' (thread {1})", result,
239+
Logger.Debug("ParserState evaluates to '{0}' (thread {1})", result,
254240
Thread.CurrentThread.ManagedThreadId);
255241
return result;
256242
}
@@ -283,12 +269,12 @@ public ParserState GetModuleState(VBComponent component)
283269
public ParserState Status
284270
{
285271
get { return _status; }
286-
internal set
272+
private set
287273
{
288274
if (_status != value)
289275
{
290276
_status = value;
291-
_logger.Debug("ParserState changed to '{0}', raising OnStateChanged", value);
277+
Logger.Debug("ParserState changed to '{0}', raising OnStateChanged", value);
292278
OnStateChanged(_status);
293279
}
294280
}
@@ -401,12 +387,12 @@ public void AddDeclaration(Declaration declaration)
401387
byte _;
402388
while (!declarations.TryRemove(declaration, out _))
403389
{
404-
_logger.Debug("Could not remove existing declaration for '{0}' ({1}). Retrying.", declaration.IdentifierName, declaration.DeclarationType);
390+
Logger.Debug("Could not remove existing declaration for '{0}' ({1}). Retrying.", declaration.IdentifierName, declaration.DeclarationType);
405391
}
406392
}
407393
while (!declarations.TryAdd(declaration, 0) && !declarations.ContainsKey(declaration))
408394
{
409-
_logger.Debug("Could not add declaration '{0}' ({1}). Retrying.", declaration.IdentifierName, declaration.DeclarationType);
395+
Logger.Debug("Could not add declaration '{0}' ({1}). Retrying.", declaration.IdentifierName, declaration.DeclarationType);
410396
}
411397
}
412398

@@ -465,7 +451,7 @@ public bool ClearStateCache(VBComponent component, bool notifyStateChanged = fal
465451
}
466452

467453
_projects.Remove(projectId);
468-
_logger.Debug("Removed Project declaration for project Id {0}", projectId);
454+
Logger.Debug("Removed Project declaration for project Id {0}", projectId);
469455
}
470456

471457
if (notifyStateChanged)
@@ -610,7 +596,7 @@ public bool IsNewOrModified(QualifiedModuleName key)
610596

611597
private QualifiedSelection _lastSelection;
612598
private Declaration _selectedDeclaration;
613-
private List<Tuple<Declaration, Selection, QualifiedModuleName>> _declarationSelections = new List<Tuple<Declaration, Selection, QualifiedModuleName>>();
599+
private readonly List<Tuple<Declaration, Selection, QualifiedModuleName>> _declarationSelections = new List<Tuple<Declaration, Selection, QualifiedModuleName>>();
614600

615601
public void RebuildSelectionCache()
616602
{
@@ -625,7 +611,6 @@ public void RebuildSelectionCache()
625611

626612
public Declaration FindSelectedDeclaration(CodePane activeCodePane, bool procedureLevelOnly = false)
627613
{
628-
629614
var selection = activeCodePane.GetQualifiedSelection();
630615
if (selection.Equals(_lastSelection))
631616
{
@@ -642,7 +627,7 @@ public Declaration FindSelectedDeclaration(CodePane activeCodePane, bool procedu
642627

643628
if (!selection.Equals(default(QualifiedSelection)))
644629
{
645-
List<Tuple<Declaration, Selection, QualifiedModuleName>> matches = new List<Tuple<Declaration, Selection, QualifiedModuleName>>();
630+
List<Tuple<Declaration, Selection, QualifiedModuleName>> matches;
646631
lock (_declarationSelections)
647632
{
648633
matches = _declarationSelections.Where(t =>
@@ -694,30 +679,18 @@ public Declaration FindSelectedDeclaration(CodePane activeCodePane, bool procedu
694679
}
695680
catch (InvalidOperationException exception)
696681
{
697-
_logger.Error(exception);
682+
Logger.Error(exception);
698683
}
699684
}
700685

701686
if (_selectedDeclaration != null)
702687
{
703-
_logger.Debug("Current selection ({0}) is '{1}' ({2})", selection, _selectedDeclaration.IdentifierName, _selectedDeclaration.DeclarationType);
688+
Logger.Debug("Current selection ({0}) is '{1}' ({2})", selection, _selectedDeclaration.IdentifierName, _selectedDeclaration.DeclarationType);
704689
}
705690

706691
return _selectedDeclaration;
707692
}
708693

709-
private static bool IsSelectedDeclaration(QualifiedSelection selection, Declaration declaration)
710-
{
711-
return declaration.QualifiedSelection.QualifiedName.Equals(selection.QualifiedName)
712-
&& (declaration.QualifiedSelection.Selection.ContainsFirstCharacter(selection.Selection));
713-
}
714-
715-
private static bool IsSelectedReference(QualifiedSelection selection, IdentifierReference reference)
716-
{
717-
return reference.QualifiedModuleName.Equals(selection.QualifiedName)
718-
&& reference.Selection.ContainsFirstCharacter(selection.Selection);
719-
}
720-
721694
public void RemoveBuiltInDeclarations(Reference reference)
722695
{
723696
var projectName = reference.Name;
@@ -730,7 +703,7 @@ public void RemoveBuiltInDeclarations(Reference reference)
730703
moduleState.Dispose();
731704
}
732705

733-
_logger.Warn("Could not remove declarations for removed reference '{0}' ({1}).", reference.Name, QualifiedModuleName.GetProjectId(reference));
706+
Logger.Warn("Could not remove declarations for removed reference '{0}' ({1}).", reference.Name, QualifiedModuleName.GetProjectId(reference));
734707
}
735708
}
736709

0 commit comments

Comments
 (0)