Hacker News new | ask | show | jobs
by Pulcinella 2201 days ago
Don’t think this will help you, but maybe provide some comfort in that you are not alone. I work in Swift and XCode everyday and still run into this problem occasionally. XCode still indeed will sometimes (seemingly randomly) lose syntax highlighting. It seems to be, at least sometimes, related to when you try to do something a bit too clever with closures (especially closures inside closures) and marking lots of changes at once, especially across targets. The biggest problem is that when the indexing required for syntax highlighting fails, there is no insight into why it failed and no way to force Xcode to re-index except by restarting Xcode. Building should re-index, but in practice this indexing is not as extensive as restarting Xcode.
2 comments

Instead of restarting Xcode you can also flip the file target, changing it will trigger an index.

  killall SourceKitService