-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add reference handler #11
Add reference handler #11
Conversation
97bd216
to
21b7d26
Compare
6301855
to
acb4e81
Compare
… language server position
8f8e7c5
to
04fe2cc
Compare
public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this ServiceInfo service, Position requestPosition) | ||
{ | ||
var members = service.GetDescendants().OfType<ServiceMemberInfo>().ToList().AsReadOnly(); | ||
|
||
// memberNameAtCursor will be null if the cursor is not on a member name. | ||
var memberNameAtCursor = members | ||
.Select(member => | ||
{ | ||
var part = member.GetPart(ServicePartKind.Name); | ||
var name = member.Name; | ||
|
||
return (part, name); | ||
}) | ||
.Where(x => x.part != null && requestPosition >= x.part.Position && requestPosition < x.part.EndPosition) | ||
.Select(x => x.name) | ||
.FirstOrDefault(); | ||
|
||
var fields = service.GetDescendants().OfType<ServiceFieldInfo>().ToList().AsReadOnly(); | ||
|
||
// fieldTypeNameAtCursor will be null if the cursor is not on a field type name. | ||
var fieldTypeNameAtCursor = fields | ||
.Select(field => | ||
{ | ||
var part = field.GetPart(ServicePartKind.TypeName); | ||
var typeName = service.GetFieldTypeName(field); | ||
|
||
return (part, typeName); | ||
}) | ||
.Where(x => x.part != null && requestPosition >= x.part.Position && requestPosition < x.part.EndPosition) | ||
.Select(x => x.typeName) | ||
.FirstOrDefault(); | ||
|
||
return fields | ||
.Select(field => | ||
{ | ||
var part = field.GetPart(ServicePartKind.TypeName); | ||
var typeName = service.GetFieldTypeName(field); | ||
|
||
var type = service.GetFieldType(field); | ||
var memberTypeName = type?.GetMemberTypeName(); | ||
|
||
return (part, memberTypeName, typeName); | ||
}) | ||
.Where(x => x.part != null && ((memberNameAtCursor != null && x.memberTypeName == memberNameAtCursor) || x.typeName == fieldTypeNameAtCursor)) | ||
.Select(x => x.part); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be rewritten using the query syntax if that is preferred. I originally used the method syntax because it was easier to debug.
public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this ServiceInfo service, Position requestPosition) | |
{ | |
var members = service.GetDescendants().OfType<ServiceMemberInfo>().ToList().AsReadOnly(); | |
// memberNameAtCursor will be null if the cursor is not on a member name. | |
var memberNameAtCursor = members | |
.Select(member => | |
{ | |
var part = member.GetPart(ServicePartKind.Name); | |
var name = member.Name; | |
return (part, name); | |
}) | |
.Where(x => x.part != null && requestPosition >= x.part.Position && requestPosition < x.part.EndPosition) | |
.Select(x => x.name) | |
.FirstOrDefault(); | |
var fields = service.GetDescendants().OfType<ServiceFieldInfo>().ToList().AsReadOnly(); | |
// fieldTypeNameAtCursor will be null if the cursor is not on a field type name. | |
var fieldTypeNameAtCursor = fields | |
.Select(field => | |
{ | |
var part = field.GetPart(ServicePartKind.TypeName); | |
var typeName = service.GetFieldTypeName(field); | |
return (part, typeName); | |
}) | |
.Where(x => x.part != null && requestPosition >= x.part.Position && requestPosition < x.part.EndPosition) | |
.Select(x => x.typeName) | |
.FirstOrDefault(); | |
return fields | |
.Select(field => | |
{ | |
var part = field.GetPart(ServicePartKind.TypeName); | |
var typeName = service.GetFieldTypeName(field); | |
var type = service.GetFieldType(field); | |
var memberTypeName = type?.GetMemberTypeName(); | |
return (part, memberTypeName, typeName); | |
}) | |
.Where(x => x.part != null && ((memberNameAtCursor != null && x.memberTypeName == memberNameAtCursor) || x.typeName == fieldTypeNameAtCursor)) | |
.Select(x => x.part); | |
} | |
public static IEnumerable<ServicePart> GetReferencedServicePartsAtPosition(this ServiceInfo service, Position requestPosition) | |
{ | |
// memberNameAtCursor will be null if the cursor is not on a member name. | |
var memberNameAtCursor = ( | |
from member in service.GetDescendants().OfType<ServiceMemberInfo>() | |
let part = member.GetPart(ServicePartKind.Name) | |
let memberName = member.Name | |
where part != null && requestPosition >= part.Position && requestPosition < part.EndPosition | |
select memberName).FirstOrDefault(); | |
var fields = service.GetDescendants().OfType<ServiceFieldInfo>().ToList().AsReadOnly(); | |
// fieldTypeNameAtCursor will be null if the cursor is not on a member name. | |
var fieldTypeNameAtCursor = ( | |
from field in fields | |
let part = field.GetPart(ServicePartKind.TypeName) | |
let typeName = service.GetFieldTypeName(field) | |
where part != null && requestPosition >= part.Position && requestPosition < part.EndPosition | |
select typeName).FirstOrDefault(); | |
return | |
from field in fields | |
let part = field.GetPart(ServicePartKind.TypeName) | |
let typeName = service.GetFieldTypeName(field) | |
let type = service.GetFieldType(field) | |
let memberTypeName = type?.GetMemberTypeName() | |
where part != null && ((memberNameAtCursor != null && memberTypeName == memberNameAtCursor) || typeName == fieldTypeNameAtCursor) | |
select part; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does read better, especially if you move the where part != null
to immediately after let part =
lines, but I don't feel strongly about it.
894bd9b
to
04fe2cc
Compare
Based on #10. Will open once that is merged.