Skip to content

Commit 424b943

Browse files
committed
stabilized parser a bit; no more systematic AccessViolationException, but RubberduckParserState._projects is still not right.
1 parent f8b657b commit 424b943

File tree

11 files changed

+54
-19
lines changed

11 files changed

+54
-19
lines changed

RetailCoder.VBE/App.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProje
274274
return;
275275
}
276276

277-
Debug.WriteLine(string.Format("Project '{0}' was renamed.", e.Item.Name));
278-
_parser.State.ClearDeclarations(e.Item);
277+
Debug.WriteLine("Project '{0}' was renamed to '{1}'.", e.OldName, e.Item.Name);
278+
_parser.State.RemoveProject(e.OldName);
279279
_parser.State.OnParseRequested(sender);
280280
}
281281

Rubberduck.Parsing/Symbols/Declaration.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ public Declaration(
101101
result = value;
102102
}
103103
_customFolder = result;
104-
_isArray = IsArray();
105-
_hasTypeHint = HasTypeHint();
106-
_isTypeSpecified = IsTypeSpecified();
107104
}
108105

109106
private readonly bool _isBuiltIn;

Rubberduck.Parsing/Symbols/ReferencedDeclarationsCollector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ private enum REGKIND
4242
REGKIND_NONE = 2
4343
}
4444

45+
4546
[DllImport("oleaut32.dll", CharSet = CharSet.Unicode)]
46-
private static extern void LoadTypeLibEx(string strTypeLibName, REGKIND regKind, out ITypeLib TypeLib);
47+
private static extern Int32 LoadTypeLibEx(string strTypeLibName, REGKIND regKind, out ITypeLib TypeLib);
4748

4849
private static readonly IDictionary<VarEnum, string> TypeNames = new Dictionary<VarEnum, string>
4950
{

Rubberduck.Parsing/VBA/RubberduckParserState.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public sealed class RubberduckParserState
4747
public event EventHandler<ParseRequestEventArgs> ParseRequest;
4848

4949
// circumvents VBIDE API's tendency to return a new instance at every parse, which breaks reference equality checks everywhere
50-
private readonly IDictionary<string,VBProject> _projects = new Dictionary<string,VBProject>();
50+
private readonly IDictionary<string,Func<VBProject>> _projects = new Dictionary<string,Func<VBProject>>();
5151

5252
private readonly ConcurrentDictionary<QualifiedModuleName, ConcurrentDictionary<Declaration, byte>> _declarations =
5353
new ConcurrentDictionary<QualifiedModuleName, ConcurrentDictionary<Declaration, byte>>();
@@ -81,20 +81,35 @@ public void AddProject(VBProject project)
8181
var name = project.ProjectName();
8282
if (!_projects.ContainsKey(name))
8383
{
84-
_projects.Add(name, project);
84+
_projects.Add(name, () => project);
8585
}
8686
}
8787

88-
public void RemoveProject(VBProject project)
88+
public void RemoveProject(string name)
8989
{
90-
var name = project.ProjectName();
9190
if (_projects.ContainsKey(name))
9291
{
9392
_projects.Remove(name);
9493
}
9594
}
9695

97-
public IReadOnlyList<VBProject> Projects { get { return _projects.Values.ToList(); } }
96+
public void RemoveProject(VBProject project)
97+
{
98+
var name = project.ProjectName();
99+
RemoveProject(name);
100+
101+
// note: attempt to fix ghost projects
102+
name = project.Name;
103+
RemoveProject(name);
104+
}
105+
106+
public IEnumerable<VBProject> Projects
107+
{
108+
get
109+
{
110+
return _projects.Values.Select(project => project.Invoke());
111+
}
112+
}
98113

99114
public IReadOnlyList<Tuple<VBComponent, SyntaxErrorException>> ModuleExceptions
100115
{

Rubberduck.SourceControl/GitProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Rubberduck.SourceControl
1212
{
13-
public class GitProvider : SourceControlProviderBase
13+
public class GitProvider : SourceControlProviderBase // note: why not : IDisposable?
1414
{
1515
private readonly LibGit2Sharp.Repository _repo;
1616
private readonly LibGit2Sharp.Credentials _credentials;

Rubberduck.VBEEditor/NativeWindowMethods.cs renamed to Rubberduck.VBEEditor/NativeMethods.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ namespace Rubberduck.VBEditor
88
/// <summary>
99
/// Collection of WinAPI methods and extensions to handle native windows.
1010
/// </summary>
11-
// Special Thank You to Carlos Quintero for supplying the project with the original code this file is based on.
12-
public static class NativeWindowMethods
11+
/// <remarks>
12+
/// **Special Thanks** to Carlos Quintero for supplying the project with the original code this file is based on.
13+
/// </remarks>
14+
public static class NativeMethods
1315
{
1416
/// <summary> Sends a message to the OS. </summary>
1517
///

Rubberduck.VBEEditor/QualifiedSelection.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public override int GetHashCode()
3030
}
3131
}
3232

33+
public static bool operator ==(QualifiedSelection selection1, QualifiedSelection selection2)
34+
{
35+
return selection1.Equals(selection2);
36+
}
37+
38+
public static bool operator !=(QualifiedSelection selection1, QualifiedSelection selection2)
39+
{
40+
return !(selection1 == selection2);
41+
}
42+
3343
public override bool Equals(object obj)
3444
{
3545
var other = (QualifiedSelection) obj;

Rubberduck.VBEEditor/Rubberduck.VBEditor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
<Compile Include="Extensions\CodeModuleExtensions.cs" />
9494
<Compile Include="CodeModuleSelection.cs" />
9595
<Compile Include="IActiveCodePaneEditor.cs" />
96-
<Compile Include="NativeWindowMethods.cs" />
96+
<Compile Include="NativeMethods.cs" />
9797
<Compile Include="QualifiedMemberName.cs" />
9898
<Compile Include="QualifiedModuleName.cs" />
9999
<Compile Include="QualifiedSelection.cs" />

Rubberduck.VBEEditor/Selection.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ public override string ToString()
8282
: string.Format("L{0}C{1} - L{2}C{3}", _startLine, _startColumn, _endLine, _endColumn);
8383
}
8484

85+
public static bool operator ==(Selection selection1, Selection selection2)
86+
{
87+
return selection1.Equals(selection2);
88+
}
89+
90+
public static bool operator !=(Selection selection1, Selection selection2)
91+
{
92+
return !(selection1 == selection2);
93+
}
94+
8595
public override bool Equals(object obj)
8696
{
8797
return Equals((Selection) obj);

Rubberduck.VBEEditor/VBEHost/FallbackApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Rubberduck.VBEditor.VBEHost
88
{
9-
public class FallbackApp : IHostApplication
9+
public sealed class FallbackApp : IHostApplication
1010
{
1111
private readonly VBE _vbe;
1212
private readonly CommandBarButton _runButton;

0 commit comments

Comments
 (0)