Compiler-assisted editor isolation hints

The other day I was thinking about function colors and it occurred to me that it might be a good idea to take the abstract concept that's useful as a mental model and make it literal.

Imagine if when you opened your editor (Xcode* or otherwise), the compiler could impart its knowledge of isolation to allow the editor to hint/highlight/color a block of code in some way to help you reason about its isolation. Suddenly implicit isolation due to either compiler settings or defaults becomes "explicit" in that you can't mistake the distinction.

I don't have a proof of concept or anything (yet), just starting a conversation out loud and in the open. I'm curious to hear others' thoughts and to find out whether this is technically feasible. And, if feasible, where it ought to be explored? The LSP probably isn't the right fit, but it seems to be the closest right place?

Is anyone aware of a VSCode (or other editor) plugin that does something similar with either Swift or another language?

*Obviously, Xcode doesn't fall under the purview of this community, but I wonder if this kind of feature or tooling ought to be built as part of the Swift project and hope that it gets adopted.

4 Likes

There's been some interesting discussion on that topic here.

3 Likes

Ah love to see it! Thanks @mattie

1 Like

Something like this would be really useful, but not in the editor. Probably in a separate entity: something like a program analyzer or program inspector. :slight_smile:

Other languages with type inference would disagree with you there (Kotlin does it right inline in Android Studio, for example), as would Xcode itself for other analysis features. Xcode's Obj-C analysis not only renders inline, but include graphical flow elements, like arrows, to show when objects may become nil or leaked, and was a huge feature back in the day. Taking the same UI and rendering it from isolation information would be great. You could even use VSCode as the separate "analyzer", since it can already do visualizations like this, if it could build Apple-platform apps.

1 Like