19
19
using Rubberduck . Parsing . Grammar ;
20
20
using IMPLTYPEFLAGS = System . Runtime . InteropServices . ComTypes . IMPLTYPEFLAGS ;
21
21
using System . Linq ;
22
- using Rubberduck . VBEditor . SafeComWrappers ;
23
22
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
24
- using Rubberduck . VBEditor . SafeComWrappers . VBA ;
25
23
26
24
namespace Rubberduck . Parsing . Symbols
27
25
{
@@ -148,7 +146,7 @@ private string GetTypeName(ITypeInfo info)
148
146
return typeName . Equals ( "LONG_PTR" ) ? "LongPtr" : typeName ; //Quickfix for http://chat.stackexchange.com/transcript/message/30119269#30119269
149
147
}
150
148
151
- public List < Declaration > GetDeclarationsForReference ( IReference reference )
149
+ public List < Declaration > GetDeclarationsForReference ( IReference reference , out SerializableDeclarationTree tree )
152
150
{
153
151
var output = new List < Declaration > ( ) ;
154
152
var projectName = reference . Name ;
@@ -158,12 +156,14 @@ public List<Declaration> GetDeclarationsForReference(IReference reference)
158
156
LoadTypeLibEx ( path , REGKIND . REGKIND_NONE , out typeLibrary ) ;
159
157
if ( typeLibrary == null )
160
158
{
159
+ tree = null ;
161
160
return output ;
162
161
}
163
162
var projectQualifiedModuleName = new QualifiedModuleName ( projectName , path , projectName ) ;
164
163
var projectQualifiedMemberName = new QualifiedMemberName ( projectQualifiedModuleName , projectName ) ;
165
164
var projectDeclaration = new ProjectDeclaration ( projectQualifiedMemberName , projectName , isBuiltIn : true ) ;
166
165
output . Add ( projectDeclaration ) ;
166
+ var moduleTrees = new List < SerializableDeclarationTree > ( ) ;
167
167
168
168
var typeCount = typeLibrary . GetTypeInfoCount ( ) ;
169
169
for ( var i = 0 ; i < typeCount ; i ++ )
@@ -175,6 +175,7 @@ public List<Declaration> GetDeclarationsForReference(IReference reference)
175
175
}
176
176
catch ( NullReferenceException )
177
177
{
178
+ tree = null ;
178
179
return output ;
179
180
}
180
181
@@ -265,16 +266,14 @@ public List<Declaration> GetDeclarationsForReference(IReference reference)
265
266
break ;
266
267
}
267
268
269
+ ComInformation comInfo ;
268
270
if ( typeAttributes . guid == Guid . Empty )
269
271
{
270
- LoadDeclarationsInModule ( output ,
271
- new ComInformation ( typeAttributes , 0 , info , typeName , typeQualifiedModuleName ,
272
- moduleDeclaration ,
273
- typeDeclarationType ) ) ;
272
+ comInfo = new ComInformation ( typeAttributes , 0 , info , typeName , typeQualifiedModuleName , moduleDeclaration , typeDeclarationType ) ;
273
+ LoadDeclarationsInModule ( output , comInfo ) ;
274
274
}
275
275
else
276
276
{
277
- ComInformation comInfo ;
278
277
if ( _comInformation . TryGetValue ( typeAttributes . guid , out comInfo ) )
279
278
{
280
279
comInfo . TypeQualifiedModuleName = typeQualifiedModuleName ;
@@ -283,26 +282,33 @@ public List<Declaration> GetDeclarationsForReference(IReference reference)
283
282
}
284
283
else
285
284
{
286
- _comInformation . Add ( typeAttributes . guid ,
287
- new ComInformation ( typeAttributes , 0 , info , typeName , typeQualifiedModuleName ,
288
- moduleDeclaration ,
289
- typeDeclarationType ) ) ;
285
+ comInfo = new ComInformation ( typeAttributes , 0 , info , typeName , typeQualifiedModuleName , moduleDeclaration , typeDeclarationType ) ;
286
+ _comInformation . Add ( typeAttributes . guid , comInfo ) ;
290
287
}
291
288
}
292
289
293
290
info . ReleaseTypeAttr ( typeAttributesPointer ) ;
294
291
295
292
output . Add ( moduleDeclaration ) ;
293
+ var moduleTree = new SerializableDeclarationTree ( new SerializableDeclaration ( moduleDeclaration ) , comInfo . MemberTrees ) ;
294
+ moduleTrees . Add ( moduleTree ) ;
296
295
}
297
296
298
297
foreach ( var member in _comInformation . Values )
299
298
{
300
299
LoadDeclarationsInModule ( output , member ) ;
301
300
}
302
301
302
+ tree = new SerializableDeclarationTree ( new SerializableDeclaration ( projectDeclaration ) , moduleTrees ) ;
303
303
return output ;
304
304
}
305
305
306
+ public List < Declaration > GetDeclarationsForReference ( IReference reference )
307
+ {
308
+ SerializableDeclarationTree tree ;
309
+ return GetDeclarationsForReference ( reference , out tree ) ;
310
+ }
311
+
306
312
private void LoadDeclarationsInModule ( List < Declaration > output , ComInformation member )
307
313
{
308
314
if ( member . TypeAttributes . typekind == TYPEKIND . TKIND_COCLASS )
@@ -353,12 +359,17 @@ memberDeclaration is ICanBeDefaultMember &&
353
359
{
354
360
parameters . Last ( ) . IsParamArray = true ;
355
361
}
362
+
363
+ var parameterTrees = parameters . Select ( p => new SerializableDeclarationTree ( p ) ) ;
364
+ var tree = new SerializableDeclarationTree ( new SerializableDeclaration ( memberDeclaration ) , parameterTrees ) ;
365
+ member . MemberTrees . Add ( tree ) ;
356
366
}
357
367
358
368
for ( var fieldIndex = 0 ; fieldIndex < member . TypeAttributes . cVars ; fieldIndex ++ )
359
369
{
360
- output . Add ( CreateFieldDeclaration ( member . TypeInfo , fieldIndex , member . TypeDeclarationType , member . TypeQualifiedModuleName ,
361
- member . ModuleDeclaration ) ) ;
370
+ var declaration = CreateFieldDeclaration ( member . TypeInfo , fieldIndex , member . TypeDeclarationType , member . TypeQualifiedModuleName , member . ModuleDeclaration ) ;
371
+ output . Add ( declaration ) ;
372
+ member . MemberTrees . Add ( new SerializableDeclarationTree ( declaration ) ) ;
362
373
}
363
374
}
364
375
0 commit comments