Skip to content

Commit

Permalink
apply includeDeclaration parameter from request
Browse files Browse the repository at this point in the history
  • Loading branch information
bryankenote committed Oct 12, 2023
1 parent 04fe2cc commit e723408
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/Facility.LanguageServer/FsdDefinitionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ from field in service.GetDescendants().OfType<ServiceFieldInfo>()
select service.FindMember(name)).FirstOrDefault();
}

public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this ServiceInfo service, Position requestPosition)
public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this ServiceInfo service, Position requestPosition, bool includeDeclaration)
{
var members = service.GetDescendants().OfType<ServiceMemberInfo>().ToList().AsReadOnly();

// memberNameAtCursor will be null if the cursor is not on a member name.
var memberNameAtCursor = members
// memberAtCursor will be null if the cursor is not on a member name.
var memberAtCursor = members
.Select(member =>
{
var part = member.GetPart(ServicePartKind.Name);
Expand All @@ -31,7 +31,7 @@ public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this
return (part, name);
})
.Where(x => x.part != null && requestPosition >= x.part.Position && requestPosition < x.part.EndPosition)
.Select(x => x.name)
.Select(x => (x.name, x.part))
.FirstOrDefault();

var fields = service.GetDescendants().OfType<ServiceFieldInfo>().ToList().AsReadOnly();
Expand All @@ -49,7 +49,7 @@ public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this
.Select(x => x.typeName)
.FirstOrDefault();

return fields
var referencedFields = fields
.Select(field =>
{
var part = field.GetPart(ServicePartKind.TypeName);
Expand All @@ -60,8 +60,23 @@ public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this

return (part, memberTypeName, typeName);
})
.Where(x => x.part != null && ((memberNameAtCursor != null && x.memberTypeName == memberNameAtCursor) || x.typeName == fieldTypeNameAtCursor))
.Where(x => x.part != null && ((memberAtCursor.name != null && x.memberTypeName == memberAtCursor.name) || x.typeName == fieldTypeNameAtCursor))
.Select(x => x.part);

var referencedMembers = members
.Select(member =>
{
var part = member.GetPart(ServicePartKind.Name);
var name = member.Name;

return (part, name);
})
.Where(x => x.part != null && x.name == fieldTypeNameAtCursor)
.Select(x => x.part);

return includeDeclaration
? referencedFields.Concat(referencedMembers)
: referencedFields;
}

private static string GetMemberTypeName(this ServiceTypeInfo type)
Expand Down
2 changes: 1 addition & 1 deletion src/Facility.LanguageServer/FsdReferenceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<LocationContainer> Handle(ReferenceParams request, Cancellatio

var position = new Position(request.Position);

var serviceParts = service.GetReferencedServicePartsAtPosition(position);
var serviceParts = service.GetReferencedServicePartsAtPosition(position, request.Context.IncludeDeclaration);

var locations = serviceParts.Select(part => new Location()
{
Expand Down

0 comments on commit e723408

Please sign in to comment.