Sourcery
Sourcery copied to clipboard
Distinguish types with the same name from different modules
Currently multiple targets support has a limitation that it is not able to distinguish types with the same name coming from different modules. If types with the same name from different modules will be scanned together they will be merged into type scanned first, as they are mapped by their name, which does not contain module name. Also there is no way to access such types in the templates.
As far as I can see from the code, we can close this issue, could you confirm it please?
Nope, it was never done and to be honest, I'm not sure how to approach this, especially in terms of templates api.
If types with the same name from different modules will be scanned together they will be merged into type scanned first, as they are mapped by their name, which does not contain module name.
Wasn't it resolved with module
and globalName
properties on Type
? I can see in Composer
that it has the modules
dictionary to collect types by module name.
it collects, but I don't think it properly distinguish types mentioned in scanned code. Because if you have two types named the same from different modules what type we should assign to the declaration depends on the current scope of the file, what is being imported. Unless you use full type name. And other issues like how to mention these types in the templates. If you mention it by type name without module which one we should return? Currently we just override one type with another in types collections.
If you mention it by type name without module which one we should return? Currently we just override one type with another in types collections.
I think this should be done on the client's shoulders. So in the template there should be somehow information which module to use. But I got the point that this is not done yet.
I got the same issue with my project. In the sources, I saw there is a module
in Type
, which is not specified in docs. If I use sources
for scanning files, the module
is always nil. To have the correct value of module
I need to use project in configuration. But now I have another issue. In docs written You can use several project or target objects to scan multiple targets from one project or to scan multiple projects
, but in fact it only scans the last defined target. I have tried several configurations, like:
project:
file: test.xcodeproj
target:
name: test
templates:
- Templates
output:
path: CodeGenerated
project:
file: Pods/Pods.xcodeproj
target:
name: SomeFramework
templates:
- Templates
output:
path: CodeGenerated
Also
project:
file: test.xcodeproj
target:
name: test
project:
file: Pods/Pods.xcodeproj
target:
name: SomeFramework
templates:
- Templates
output:
path: CodeGenerated
@rubensamsonyanauto1 I believe what you described is a different problem, can you please create a new issue for it?
@ilyapuchka Sure, will do. From my comment it's not obvious, but I came here, because I had types with the same name from different modules and to fix the issue, wanted to add module name in front of the type name and got the issue I described :)
Any updates on this issue?
Sourcery have been doing lookups by module for a while now but there will be big changes in next releases anyway so if it doesn't do something atm then it won't until that AST rewrite happens
Are there any updates on this issue?