Follow

Just released v0.1.0 of Cite, a Kotlin compiler plugin for embedding information about the source file being compiled. Try it out!

github.com/JakeWharton/cite

@jw cite + timber is what I've long been looking for.
Any plans for making them directly work together, or is that left as an exercise for the reader? 🙂

@ab @jw exactly my first thought was better logging

@ab I don't have any plans. My itch was not logging but testing, although logging is the extremely obvious and likely infinitely more useful application of such a tool. The biggest problem to any kind of integration is that you need to ensure people apply the plugin at all usage sites, which makes things like inline functions dangerous.

@jw lol I've finished building something like this at work this week! My version is a bit simpler - it uses annotations and supports only function params. It analyzes the callsites and replaces arguments with line/column number, function name or file name. Usages outside of function params seem less useful because you always get the same, static value.

@jw oh I see, you're replacing the values when the properties are referenced, so in the example you posted, the values will be different for each call. That's clever! Do you plan to add support for column number and for file paths as well?

@mzmzgreen @jw That would be obviously cool for logging, if extended to supply fully qualified names. Then you could even have proper logger names on JS.

@mzmzgreen Got an example of where column number is useful? I couldn't think of any which is why I didn't add it.

@jw maybe a bit silly but imagine a function cache {} (similar to Compose remember {}) that takes a lambda and caches its result using file name and line number. If you call it twice on the same line, it won't work as you expect. Adding column to the hash key would help here.

Sign in to participate in the conversation
Mastodon

This server is a place for Jake Wharton. Are you Jake Wharton? This is your place. Are you not Jake Wharton? Well, at least you can find him here.