Sourcery icon indicating copy to clipboard operation
Sourcery copied to clipboard

[QUESTION] Is possible to get the module where the type is defined?

Open Robuske opened this issue 3 years ago • 8 comments

I was not able to find documentation for this, is it possible to get the name of the module where the type was defined? That way I could do something like this:

Original type on ModuleA:

import Whatever

struct CoolStruct {
  // Stuff
}

Generated code on ModuleB:

import ModuleA

let coolStruct = CoolStruct()
// Do something with CoolStruct

Robuske avatar Jul 30 '21 02:07 Robuske

yes if you use pbxproj / target integration, each type has module optional field.

Not if you just use source paths since how could Sourcery know in that case

krzysztofzablocki avatar Jul 30 '21 09:07 krzysztofzablocki

Hum... I think I see the problem... I use trough command line because the source code is on Package and de generated code will be used on the Package too. Do you know of any way I could do that? I though about #fileID, but it is replaced only after compilation right?

Robuske avatar Jul 31 '21 02:07 Robuske

If there is no target information provided Sourcery can't really know what module it's scanning, there is path on Type but that wouldn't really help.

We'll be adding SPM support as one of the config options in near future

krzysztofzablocki avatar Jul 31 '21 08:07 krzysztofzablocki

There is path on Type? It doesn't appear on the reference. It could be enough since SPM follows a pretty rigid structure, but I guess Stencil doesn't allow for the level of string manipulation that I would required right? Basically extracting only the content between Source/ and the next /, and transforming Module-A into Module_A. From what I researched Stencil does not support RegExes right?

Robuske avatar Aug 03 '21 02:08 Robuske

If stencil supported the regex then it would be so cool! Btw do have have a workaround now for SPM packages? For modules integrated with pbxproj/target works fine. ❓

Nikoloutsos avatar Feb 17 '22 13:02 Nikoloutsos

we'd either need to add scanning of Package.swift or we could add support for injecting module name for a given source path

krzysztofzablocki avatar Feb 18 '22 07:02 krzysztofzablocki

yes if you use pbxproj / target integration, each type has module optional field.

Not if you just use source paths since how could Sourcery know in that case

Is it possible to get the target within the module for the type?

russellyeo avatar Sep 29 '22 13:09 russellyeo

@rus64 confused what you mean, module is a target isn't it?

krzysztofzablocki avatar Sep 29 '22 15:09 krzysztofzablocki