I think you can shorten this to 

``entityAt(Location(hit.cu, hit.offset)) collect { case x: TypeEntity => x }``

Which I find it still slightly more verbose than I'd like it to be, but better than the original ;-)