Giter Club home page Giter Club logo

Comments (10)

kdubb avatar kdubb commented on August 18, 2024

You have the extension statement still qualifying Observable as RsSwift.Observable. Are you not expecting it to be unqualified?

E.g.

import RsSwift

extension Observable {
}

from swiftpoet.

PaulWoitaschek avatar PaulWoitaschek commented on August 18, 2024

I am not a swift developer and am lacking some level of understand it different areas.
Generated code does not have to be beautiful, it has to be correct.
I do not care about unnecessary full qualifications.

If I understand the language correctly, not fully qualifying the extension would give a local type named Observable precedence here which would be a bug

from swiftpoet.

PaulWoitaschek avatar PaulWoitaschek commented on August 18, 2024

Actually this non explicit imports has caused me a lot of issues. I basically can't use DeclaredTypeName and always have to us TypeVariableName instead because else I end up in a lot of situations where the generated code is amgiuous.

For example I have an import on a package that contains an UUID and an import on Foundation. As swiftpoet tries to be clever and omits the Foundation prefix, the swift code does not compile because it can't know which UUID I meant.
Therefore I think generated code should always add imports to anything, especially on a language like swift where all these things are resolved dependant on the current project classes and setup.

from swiftpoet.

kdubb avatar kdubb commented on August 18, 2024

Generated code does not have to be beautiful, it has to be correct.

False. One of the goals of this project, and all of the "Poet" libraries (e.g. JavaPoet, KotlinPoet, etc.) is to create correctly formatted and concise code. Code that is as easy to read as handwritten code.

I appreciate that it is not working for you and some solution needs to be created for the issue you're having but we're not gonna throw the baby out with the bathwater and reduce code beauty to solve this issue.

Also, we generate a lot of code with this library in our team and it's now used in Square's Wire library, so it's doing its job quite well for many users.

from swiftpoet.

kdubb avatar kdubb commented on August 18, 2024

@PaulWoitaschek I've fixed this in the latest PR and should be available in 1.4.0-SNAPSHOT.

To extend an externally defined type (e.g. like RxSwift.Observable) you use the new ExtensionTypeSpec.build(TypeName); notice that it takes a type name.

from swiftpoet.

kdubb avatar kdubb commented on August 18, 2024

Also, I've added PR #56 which you can test to see if it solves your problem with needing types that are always fully qualified and don't generate imports.

from swiftpoet.

PaulWoitaschek avatar PaulWoitaschek commented on August 18, 2024

That's great and will solve my issues!

I still think it is very important to solve this generically for exactly everything.

Also, we generate a lot of code with this library in our team and it's now used in Square's Wire library, so it's doing its job quite well for many users.

Just that it works for many users does not mean that it's correct in every context.

and all of the "Poet" libraries (e.g. JavaPoet, KotlinPoet, etc.) is to create correctly formatted and concise code. Code that is as easy to read as handwritten code.

The other poet Libraries have their very primary focus on correct code. If we take a look at the queries that Sqldelight generates for Kotlin Poet:

package com.yazio.shared.database

import com.squareup.sqldelight.Query
import com.squareup.sqldelight.Transacter
import kotlin.Any
import kotlin.ByteArray
import kotlin.Long
import kotlin.Unit
import kotlin.collections.Collection

public interface CachedEventQueries : Transacter {
  public fun <T : Any> selectAll(mapper: (
    id: Long,
    proto: ByteArray,
    insertedAt: Long
  ) -> T): Query<T>

  public fun selectAll(): Query<CachedEvent>

  public fun <T : Any> lastInsertion(mapper: (max: Long?) -> T): Query<T>

  public fun lastInsertion(): Query<LastInsertion>

  public fun insert(proto: ByteArray, insertedAt: Long): Unit

  public fun deleteById(ids: Collection<Long>): Unit
}

You have explicit imports for all types, even the primitives - even though it is not strictly required.

Also take a look at this issue on wildcard imports:

square/kotlinpoet#349

Wildcard imports are the fastest way to breaking KotlinPoets automatic imports from working correctly.

And exactly that what's happening when kotlin poet is trying to omit imports.

from swiftpoet.

kdubb avatar kdubb commented on August 18, 2024

@PaulWoitaschek Point well taken. Assuredly we are working against Swift's limited import syntax; there just is no syntax for explicit imports and essentially everything is a wildcard.

Swift knows this and there has been a lot of discussion about adding them in the Swift forums. Rest assured that if/when they are added I'll take the stance of KotlinPoet.

Until then let me know if #56 works for you, I believe it should. Just generate all types with alwaysQualify set to true and you should have basically no imports.

from swiftpoet.

kdubb avatar kdubb commented on August 18, 2024

Also, type names with alwaysQualify are "infectious", so generating nested, child, parent type names from them will also set the alwaysQualify of the new type name to true as well.

from swiftpoet.

PaulWoitaschek avatar PaulWoitaschek commented on August 18, 2024

I currently can't test it in production due to pre-new-year-workload, but from the implementation and the test case it looks like exactly what I need. Thanks for implementing this! 👍

from swiftpoet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.