Refactor semantic highlight checks ; fix a few problems

The main change is to use `namePosition` from scala-refactoring (this is what scala-ide does). This fixes several problems with the wrong text being highlighted.

I also eliminated some code duplication and fixed a couple more known issues.