Comments (10)
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.
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.
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.
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.
@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.
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.
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:
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.
@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.
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.
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)
- nextControlFlow with else HOT 1
- Type bound is incorrectly generated in case of 2 or more bound types. HOT 2
- Error when use ParameterSpec.unnamed - Char sequence is empty. HOT 1
- No ways to create @escaping lambda at all HOT 5
- Operator overloading isn't supported. HOT 1
- PropertySpec DOES NOT add Modifiers to global properties
- PropertySpec builder DOES NOT add Modifiers to global properties HOT 1
- Is there a way to add 'weak' modifier to a property? HOT 2
- Missing support for generate implicitly unwrapped optionals HOT 1
- Invalid rules for nested types and protocols HOT 3
- 1.4.0 Release HOT 1
- 1.4.1 crash HOT 2
- Support Subscript builders HOT 4
- Why ComposedTypeName.composed is internal? HOT 1
- Support for optional closure/lambda parameters
- Inferred type names are not finding "Swift." (amongst other things). HOT 8
- Support `convenience init`
- Formatting string produces error HOT 14
- SwiftPoet Status HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftpoet.