@@ -72,10 +72,8 @@ internal SetCodeItems RetrieveAllCodeItems(Document document)
72
72
{
73
73
var codeItems = new SetCodeItems ( ) ;
74
74
75
- if ( document . ProjectItem != null )
76
- {
77
- RetrieveCodeItems ( codeItems , document . ProjectItem . FileCodeModel ) ;
78
- }
75
+ var fileCodeModel = RetrieveFileCodeModel ( document . ProjectItem ) ;
76
+ RetrieveCodeItems ( codeItems , fileCodeModel ) ;
79
77
80
78
codeItems . AddRange ( _codeModelHelper . RetrieveCodeRegions ( document . GetTextDocument ( ) ) ) ;
81
79
@@ -86,6 +84,39 @@ internal SetCodeItems RetrieveAllCodeItems(Document document)
86
84
87
85
#region Private Methods
88
86
87
+ /// <summary>
88
+ /// Attempts to return the FileCodeModel associated with the specified project item.
89
+ /// </summary>
90
+ /// <param name="projectItem">The project item.</param>
91
+ /// <returns>The associated FileCodeModel, otherwise null.</returns>
92
+ private FileCodeModel RetrieveFileCodeModel ( ProjectItem projectItem )
93
+ {
94
+ if ( projectItem == null )
95
+ {
96
+ return null ;
97
+ }
98
+
99
+ if ( projectItem . FileCodeModel != null )
100
+ {
101
+ return projectItem . FileCodeModel ;
102
+ }
103
+
104
+ // If this project item is part of a shared project, retrieve the FileCodeModel via a similar platform project item.
105
+ const string sharedProjectTypeGUID = "{d954291e-2a0b-460d-934e-dc6b0785db48}" ;
106
+ var containingProject = projectItem . ContainingProject ;
107
+
108
+ if ( containingProject != null && containingProject . Kind != null &&
109
+ containingProject . Kind . ToLowerInvariant ( ) == sharedProjectTypeGUID )
110
+ {
111
+ var similarProjectItems = SolutionHelper . GetSimilarProjectItems ( _package , projectItem ) ;
112
+ var fileCodeModel = similarProjectItems . Select ( x => x . FileCodeModel ) . FirstOrDefault ( y => y != null ) ;
113
+
114
+ return fileCodeModel ;
115
+ }
116
+
117
+ return null ;
118
+ }
119
+
89
120
/// <summary>
90
121
/// Walks the given FileCodeModel, turning CodeElements into code items within the specified
91
122
/// code items set.
0 commit comments