Skip to content

Commit 650d563

Browse files
committed
Change the document module supertype behaviour to adding supertypes without underscore
This seems safer in case we actually have a declaration for the interface with an underscore.
1 parent 105cbdd commit 650d563

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

Rubberduck.Parsing/VBA/ReferenceManagement/ReferenceResolveRunnerBase.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,7 @@ private void AddSuperTypeNamesForDocumentModules(IReadOnlyCollection<QualifiedMo
182182
continue;
183183
}
184184

185-
var inheritedInterfaces = comModule is ComCoClass documentCoClass
186-
? documentCoClass.ImplementedInterfaces
187-
: (comModule as ComInterface)?.InheritedInterfaces;
188-
189-
//todo: Find a way to deal with the VBE's document type assignment behaviour not relying on an assumption about an interface naming convention.
190-
var superTypeNames = inheritedInterfaces?
191-
.Where(i => !i.IsRestricted && !IgnoredComInterfaces.Contains(i.Name))
192-
.Select(i => i.Name)
193-
.Select(name => name.StartsWith("_") ? name.Substring(1) : name) //This emulates the VBE's behaviour to allow assignment to the coclass type instead on the interface.
194-
?? Enumerable.Empty<string>();
185+
var superTypeNames = SuperTypeNamesForDocumentFromComType(comModule);
195186

196187
foreach (var superTypeName in superTypeNames)
197188
{
@@ -201,6 +192,29 @@ private void AddSuperTypeNamesForDocumentModules(IReadOnlyCollection<QualifiedMo
201192
}
202193
}
203194

195+
private static IEnumerable<string> SuperTypeNamesForDocumentFromComType(IComType comModule)
196+
{
197+
var inheritedInterfaces = comModule is ComCoClass documentCoClass
198+
? documentCoClass.ImplementedInterfaces
199+
: (comModule as ComInterface)?.InheritedInterfaces;
200+
201+
//todo: Find a way to deal with the VBE's document type assignment behaviour not relying on an assumption about an interface naming convention.
202+
var superTypeNames = (inheritedInterfaces?
203+
.Where(i => !i.IsRestricted && !IgnoredComInterfaces.Contains(i.Name))
204+
.Select(i => i.Name)
205+
?? Enumerable.Empty<string>())
206+
.ToList();
207+
208+
//This emulates the VBE's behaviour to allow assignment to the coclass type instead on the interface.
209+
var additionalSuperTypes = superTypeNames
210+
.Where(name => name.StartsWith("_"))
211+
.Select(name => name.Substring(1))
212+
.ToList();
213+
214+
superTypeNames.AddRange(additionalSuperTypes);
215+
return superTypeNames;
216+
}
217+
204218
protected void ResolveReferences(DeclarationFinder finder, QualifiedModuleName module, IParseTree tree, CancellationToken token)
205219
{
206220
token.ThrowIfCancellationRequested();

0 commit comments

Comments
 (0)