Thread overview
[Issue 19800] JSON output does not include scoped imports
Apr 17, 2019
RazvanN
Apr 17, 2019
Seb
Apr 18, 2019
GoaLitiuM
Apr 19, 2019
RazvanN
April 17, 2019
https://issues.dlang.org/show_bug.cgi?id=19800

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
I don't know that the json output should contain, but maybe this is by design? It seems to work as a .di generator.

--
April 17, 2019
https://issues.dlang.org/show_bug.cgi?id=19800

Seb <greeenify@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greeenify@gmail.com

--- Comment #2 from Seb <greeenify@gmail.com> ---
Yeah the JSON output currently doesn't look inside the function. I am curious: what is your use case?

--
April 18, 2019
https://issues.dlang.org/show_bug.cgi?id=19800

--- Comment #3 from GoaLitiuM <goalitium@dissues.mail.kapsi.fi> ---
I'm trying to build a dependency tree of the imported modules for a build tool to find out which modules are needed to rebuild after one of the files are changed. This works with the -X switch and having the imports outside the functions, but are missed when imported in a scope.

I don't know what the intended output should be but I assumed the import would be listed under the members of the main function (in this particular case), but they are only listed under the members of the modules if the module is imported outside any functions.

--
April 19, 2019
https://issues.dlang.org/show_bug.cgi?id=19800

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to GoaLitiuM from comment #3)
> I'm trying to build a dependency tree of the imported modules for a build tool to find out which modules are needed to rebuild after one of the files are changed. This works with the -X switch and having the imports outside the functions, but are missed when imported in a scope.
> 
> I don't know what the intended output should be but I assumed the import would be listed under the members of the main function (in this particular case), but they are only listed under the members of the modules if the module is imported outside any functions.

The json generator is ran after the parsing phase, so semantic analysis is not yet done. This means that function bodies have not yet been analyzed, therefore the json will not include the declarations inside them. This is the expected behavior.

If you want to have all the imports (recursively) you need to compile with the -deps option; this will give all the imports recursively, but this may be a bit verbose because you will also get the standard library dependency tree.

Another way to do this is to write your own tool that uses dmd as a library and print whatever declarations you are interested in. If its just imports that you are interested in then this little example program [1] using dmd as a library will simply print the imports (ImportVisitor2 prints all imports, ImportVisitor prints only toplevel imports). The bad part is that the imports are not printed as a json.

I will close this as invalid, as the json generater works as expected.

[1] https://github.com/dlang/dmd/blob/master/src/examples/impvisitor.d#L14

--