-
Notifications
You must be signed in to change notification settings - Fork 510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default imports for certain classes in sq files is confusing #2060
Comments
Default imports are a feature for text editors, not IDEs. I am very strongly opposed to doing what Kotlin does. |
Makes sense to me |
Thinking about this issue further, I believe we would need to implement this in conjunction with #2056, because otherwise there would be a potential regression for users that use the fully qualified name of the eight special cased classes which are imported by default. Here's a test to illustrate what I mean, where we have two @Test fun foo() {
val result = FixtureCompiler.parseSql("""
|CREATE TABLE test (
| col0 INTEGER AS Short,
| col1 INTEGER AS kotlin.Short
|);
|""".trimMargin(), tempFolder)
val generator = TableInterfaceGenerator(result.sqliteStatements().first().statement.createTableStmt!!.tableExposed())
val file = FileSpec.builder("", "Test")
.addType(generator.kotlinImplementationSpec())
.build()
assertThat(file.toString()).isEqualTo("""
|import com.squareup.sqldelight.ColumnAdapter
|import kotlin.Long
|import kotlin.Short
|import kotlin.String
|
|public data class Test(
| public val col0: Short?,
| public val col1: Short?
|) {
| public override fun toString(): String = ""${'"'}
| |Test [
| | col0: ${'$'}col0
| | col1: ${'$'}col1
| |]
| ""${'"'}.trimMargin()
|
| public class Adapter(
| public val col1Adapter: ColumnAdapter<Short, Long>
| )
|}
|""".trimMargin())
} |
For example, I think it's a bit confusing to have to specify an import for
kotlin.Byte
, but notkotlin.Short
. The types that are automatically imported are the ones that SQLDelight will automatically make type coercions for (per the docs).The following lines defines which imports we consider as not being required to be explicitly specified:
sqldelight/sqldelight-compiler/src/main/kotlin/com/squareup/sqldelight/core/sqldelight.bnf
Lines 88 to 97 in 5d939ca
I think it'd be less confusing to either:
import kotlin.Short
in the.sq
file).sq
files and add imports.sq
files and add importskotlin.Byte
,kotlin.Short
, etc.kotlin.collections.List
) Even though I think it should be easy to know which one to choose depending on the context, it may require some work.We could keep the default, but I think the idea of these "random" default imports that are currently in SQLDelight will make less sense when/if #2056 is implemented.
The text was updated successfully, but these errors were encountered: