Skip to content

Commit bde616d

Browse files
authored
Merge pull request #4559 from MDoerner/FixSomeScwDisposal
Fix some scw disposal
2 parents b25e5be + 2d0dfc2 commit bde616d

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

Rubberduck.CodeAnalysis/Inspections/Concrete/SheetAccessedUsingStringInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private IVBComponent GetVBComponentMatchingSheetName(IdentifierReferenceInspecti
9696

9797
var sheetArgumentContext = indexExprContext.argumentList().argument(0);
9898
var sheetName = FormatSheetName(sheetArgumentContext.GetText());
99-
var project = State.Projects.First(p => p.ProjectId == reference.QualifiedName.ProjectId);
99+
var project = State.ProjectsProvider.Project(reference.QualifiedName.ProjectId);
100100

101101
using (var components = project.VBComponents)
102102
{

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ private bool CanExecuteCopyResultsCommand(object parameter)
620620
return !IsBusy && _resultsAll != null && _resultsAll.Any();
621621
}
622622

623-
public Visibility EmptyUIRefreshVisibility => _state.Projects.Count > 0 ? Visibility.Hidden : Visibility.Visible;
623+
public Visibility EmptyUIRefreshVisibility => _state.ProjectsProvider.Projects().Any() ? Visibility.Hidden : Visibility.Visible;
624624

625625
public Visibility EmptyUIRefreshMessageVisibility => IsBusy ? Visibility.Hidden : Visibility.Visible;
626626

Rubberduck.Core/UI/UnitTesting/Commands/AddTestModuleCommand.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ private string DeclarationFormatFor(string declarationFormat, string type, IUnit
125125

126126
private IVBProject GetProject()
127127
{
128-
using (var activeProject = _vbe.ActiveVBProject)
128+
//No using because the wrapper gets returned potentially.
129+
var activeProject = _vbe.ActiveVBProject;
130+
if (!activeProject.IsWrappingNullReference)
129131
{
130-
if (!activeProject.IsWrappingNullReference)
131-
{
132-
return activeProject;
133-
}
132+
return activeProject;
134133
}
134+
activeProject.Dispose();
135135

136136
using (var projects = _vbe.VBProjects)
137137
{
@@ -143,10 +143,13 @@ private IVBProject GetProject()
143143

144144
protected override bool EvaluateCanExecute(object parameter)
145145
{
146+
bool canExecute;
146147
using (var project = GetProject())
147148
{
148-
return project != null && !project.IsWrappingNullReference && CanExecuteCode(project);
149+
canExecute = project != null && !project.IsWrappingNullReference && CanExecuteCode(project);
149150
}
151+
152+
return canExecute;
150153
}
151154

152155
private bool CanExecuteCode(IVBProject project)

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public void SetModuleState(QualifiedModuleName module, ParserState state, Cancel
423423
if (AllUserDeclarations.Any())
424424
{
425425
var projectId = module.ProjectId;
426-
IVBProject project = GetProject(projectId);
426+
var project = GetProject(projectId);
427427

428428
if (project == null)
429429
{

Rubberduck.Parsing/VBA/StateProjectManagerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class StateProjectManagerBase : IProjectManager
1111
private readonly RubberduckParserState _state;
1212
private readonly IVBE _vbe;
1313

14-
public StateProjectManagerBase(
14+
protected StateProjectManagerBase(
1515
RubberduckParserState state,
1616
IVBE vbe)
1717
{

Rubberduck.VBEEditor/SourceCodeHandling/CodePaneSourceCodeHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ public CodeString GetCurrentLogicalLine(QualifiedModuleName module)
283283

284284
public Selection GetSelection(QualifiedModuleName module)
285285
{
286-
using (var component = _projectsProvider.Component(module))
286+
var component = _projectsProvider.Component(module);
287+
287288
using (var codeModule = component.CodeModule)
288289
using (var pane = codeModule.CodePane)
289290
{

0 commit comments

Comments
 (0)