155
173
node = ((IdentifierExpression)node).IdentifierToken;
158
var region = new DomRegion (fileName, node.StartLocation, node.EndLocation);
176
var region = new DomRegion (fileName, node.StartLocation, node.EndLocation);
160
178
var length = node is PrimitiveType ? keywordName.Length : node.EndLocation.Column - node.StartLocation.Column;
161
return new MemberReference (valid, region, editor.LocationToOffset (region.Begin), length);
179
return new CSharpMemberReference (project, originalNode, syntaxTree, valid, region, editor.LocationToOffset (region.Begin), length);
182
public class CSharpMemberReference : MemberReference
184
public SyntaxTree SyntaxTree {
189
public AstNode AstNode {
194
public Project Project {
199
public CSharpMemberReference (Project project, AstNode astNode, SyntaxTree syntaxTree, object entity, DomRegion region, int offset, int length) : base (entity, region, offset, length)
201
this.Project = project;
202
this.AstNode = astNode;
203
this.SyntaxTree = syntaxTree;
164
207
bool IsNodeValid (object searchedMember, AstNode node)
176
219
var parsedDocument = doc.ParsedDocument;
177
220
if (parsedDocument == null)
178
221
return Enumerable.Empty<MemberReference> ();
179
var unit = parsedDocument.GetAst<CompilationUnit> ();
180
var file = parsedDocument.ParsedFile as CSharpParsedFile;
222
var unit = parsedDocument.GetAst<SyntaxTree> ();
223
var file = parsedDocument.ParsedFile as CSharpUnresolvedFile;
181
224
var result = new List<MemberReference> ();
183
226
foreach (var obj in searchedMembers) {
184
227
if (obj is IEntity) {
185
refFinder.FindReferencesInFile (refFinder.GetSearchScopes ((IEntity)obj), file, unit, doc.Compilation, (astNode, r) => {
228
var entity = (IEntity)obj;
230
// May happen for anonymous types since empty constructors are always generated.
231
// But there is no declaring type definition for them - we filter out this case.
232
if (entity.EntityType == EntityType.Constructor && entity.DeclaringTypeDefinition == null)
235
refFinder.FindReferencesInFile (refFinder.GetSearchScopes (entity), file, unit, doc.Compilation, (astNode, r) => {
186
236
if (IsNodeValid (obj, astNode))
187
result.Add (GetReference (r, astNode, editor.FileName, editor));
237
result.Add (GetReference (doc.Project, r, astNode, unit, editor.FileName, editor));
188
238
}, CancellationToken.None);
189
239
} else if (obj is IVariable) {
190
240
refFinder.FindLocalReferences ((IVariable)obj, file, unit, doc.Compilation, (astNode, r) => {
191
241
if (IsNodeValid (obj, astNode))
192
result.Add (GetReference (r, astNode, editor.FileName, editor));
242
result.Add (GetReference (doc.Project, r, astNode, unit, editor.FileName, editor));
193
243
}, CancellationToken.None);
194
244
} else if (obj is ITypeParameter) {
195
245
refFinder.FindTypeParameterReferences ((ITypeParameter)obj, file, unit, doc.Compilation, (astNode, r) => {
196
246
if (IsNodeValid (obj, astNode))
197
result.Add (GetReference (r, astNode, editor.FileName, editor));
198
}, CancellationToken.None);
247
result.Add (GetReference (doc.Project, r, astNode, unit, editor.FileName, editor));
248
}, CancellationToken.None);
249
} else if (obj is INamespace) {
250
var entity = (INamespace)obj;
251
refFinder.FindReferencesInFile (refFinder.GetSearchScopes (entity), file, unit, doc.Compilation, (astNode, r) => {
252
if (IsNodeValid (obj, astNode))
253
result.Add (GetReference (doc.Project, r, astNode, unit, editor.FileName, editor));
254
}, CancellationToken.None);
204
public override IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> possibleFiles, IEnumerable<object> members)
260
public override IEnumerable<MemberReference> FindReferences (Project project, IProjectContent content, IEnumerable<FilePath> possibleFiles, IProgressMonitor monitor, IEnumerable<object> members)
207
throw new ArgumentNullException ("project", "Project not set.");
208
262
if (content == null)
209
263
throw new ArgumentNullException ("content", "Project content not set.");
210
264
SetPossibleFiles (possibleFiles);
211
265
SetSearchedMembers (members);
213
var scopes = searchedMembers.Select (e => refFinder.GetSearchScopes (e as IEntity));
214
var compilation = TypeSystemService.GetCompilation (project);
267
var scopes = searchedMembers.Select (e => e is IEntity ? refFinder.GetSearchScopes ((IEntity)e) : refFinder.GetSearchScopes ((INamespace)e));
268
var compilation = project != null ? TypeSystemService.GetCompilation (project) : content.CreateCompilation ();
215
269
List<MemberReference> refs = new List<MemberReference> ();
216
270
foreach (var opendoc in openDocuments) {
217
271
foreach (var newRef in FindInDocument (opendoc.Item2)) {
235
290
var storedFile = content.GetFile (file);
236
var parsedFile = storedFile as CSharpParsedFile;
291
var parsedFile = storedFile as CSharpUnresolvedFile;
238
293
if (parsedFile == null && storedFile is ParsedDocumentDecorator) {
239
parsedFile = ((ParsedDocumentDecorator)storedFile).ParsedFile as CSharpParsedFile;
294
parsedFile = ((ParsedDocumentDecorator)storedFile).ParsedFile as CSharpUnresolvedFile;
242
297
if (parsedFile == null) {
243
298
// for fallback purposes - should never happen.
244
299
parsedFile = unit.ToTypeSystem ();
245
content = content.UpdateProjectContent (content.GetFile (file), parsedFile);
300
content = content.AddOrUpdateFiles (parsedFile);
246
301
compilation = content.CreateCompilation ();
248
303
foreach (var scope in scopes) {