louiscad
02/22/2024, 12:08 AMRoman Golyshev
02/22/2024, 1:13 PMmodifier = Modifier
, right?
Or does the author of the tweet wants Modifier
to be completed to be able to complete some fun Modifier.Companion.ext(): Modifier {...}
function later on?louiscad
02/22/2024, 1:30 PMlouiscad
02/22/2024, 1:39 PMModifier
, that's all.
As I commented, Modifier
(companion object) itself implements the Modifier
interface.
That's to make all common "modifiers" like padding(…)
, fillMaxSize()
, sizeIn(…)
, background(…)
, etc, autcomplete either on the base empty modifier that is Modifier
(the companion object)`, or when chained with another Modifier
instance returned by any modifier like the ones I just mentioned.
The Modifier
companion object is defined as such:
// The companion object implements `Modifier` so that it may be used as the start of a
// modifier extension factory expression.
companion object : Modifier {
override fun <R> foldIn(initial: R, operation: (R, Element) -> R): R = initial
override fun <R> foldOut(initial: R, operation: (Element, R) -> R): R = initial
override fun any(predicate: (Element) -> Boolean): Boolean = false
override fun all(predicate: (Element) -> Boolean): Boolean = true
override infix fun then(other: Modifier): Modifier = other
override fun toString() = "Modifier"
}
There are 3 problems.
• First the IDE wants to go too far. Instead of just suggesting the shortest option: Modifier
, it tries to go the extra mile and save you characters in case you want to call the overrides from Modifier
. It's annoying because if it was really necessary, it could let me do so in two steps. First autocomplete Modifier
, then autocomplete whatever is next based on the first or subsequent characters I type, after I type .
that comes after Modifier
, if I ever do.
• Second, the IDE seems to believe that those overrides are members found exclusively in the Modifier
companion objects, while they're not, it's merely an implementation to conform to the Modifier
interface, and the signature is exactly the same as in the interface
, so they should not take priority.
• Third, the IDE never seems to learn that I'm never using Modifier.foldIn
, Modifier.foldOut
, Modifier.then
, and other irrelevant options when a Modifier
type is expected. It's annoying as an experienced dev, it'd most likely be misleading as a beginner.Roman Golyshev
02/22/2024, 2:09 PMRoman Golyshev
02/22/2024, 2:10 PMlouiscad
02/22/2024, 2:11 PMlouiscad
02/22/2024, 2:12 PMRoman Golyshev
02/22/2024, 2:12 PMlouiscad
02/22/2024, 2:12 PMlouiscad
02/22/2024, 2:12 PMKonstantin Klassen
02/22/2024, 3:47 PM