Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not generate a graph output #1

Open
olbrichj opened this issue Feb 4, 2018 · 6 comments
Open

Does not generate a graph output #1

olbrichj opened this issue Feb 4, 2018 · 6 comments

Comments

@olbrichj
Copy link

olbrichj commented Feb 4, 2018

Hey,
I'm trying to run grift with a minimal example. I've build it from source with swift build and use the executable from .build/x86_64-apple-macosx10.10/debug/

class ClassA {
  func test() {}
}

class ClassB {
  func bla() {
    let a = ClassA()
    a.test()
  }
}

Both classes are in seperate Files.

If I understand grift dependencies correct, I just have to place grift in the same directory as the files and then run it.
The output I get is:

digraph { }

What am I doing wrong here?

@klundberg
Copy link
Owner

klundberg commented Feb 4, 2018 via email

@olbrichj
Copy link
Author

olbrichj commented Feb 4, 2018

I'll have a look if I find some time. It might take some time though.

Was curious what data you got from sourcekit and how you achieved that. Easiest way is running the tool ;)

@klundberg
Copy link
Owner

Ah cool :). So far I've taken the code structure info from sourcekit and searched through that for any type information I could find. It kind of works but there's some stuff missing (like function return types) that needs some sort of workaround. I suspect that the way grift does things will evolve over time in order to handle all these different cases that sourcekit itself might not be able to manage.

@olbrichj
Copy link
Author

olbrichj commented Feb 5, 2018

Depending on the data you need maybe sourcekitten doc is more appropriate. My problem with doc is, it does not return detailed information about method substructures. So I have to stick to index at the moment. It does provide some information, but returns vars and their type in two independent objects (doc returns them in one).

Just checked. In doc key.typename you could extract the return value.

@klundberg klundberg changed the title Does not generate a grap output Does not generate a graph output Feb 6, 2018
@klundberg
Copy link
Owner

Hmm, I tried docs instead of structure and for this code:

struct Thing { func foo() -> Double { return 0.0 } }

I got this output (which has no key.typename in it for the foo function)

[{
  "<No File>" : {
    "key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
    "key.substructure" : [
      {
        "key.bodyoffset" : 14,
        "key.nameoffset" : 7,
        "key.accessibility" : "source.lang.swift.accessibility.internal",
        "key.length" : 52,
        "key.substructure" : [
          {
            "key.bodyoffset" : 37,
            "key.nameoffset" : 20,
            "key.accessibility" : "source.lang.swift.accessibility.internal",
            "key.length" : 35,
            "key.name" : "foo()",
            "key.kind" : "source.lang.swift.decl.function.method.instance",
            "key.bodylength" : 12,
            "key.namelength" : 5,
            "key.offset" : 15
          }
        ],
        "key.name" : "Thing",
        "key.kind" : "source.lang.swift.decl.struct",
        "key.bodylength" : 37,
        "key.namelength" : 5,
        "key.offset" : 0
      }
    ],
    "key.offset" : 0,
    "key.length" : 52
  }
}]

I was considering exploring using syntax highlighting info combined with doc or structure somehow to get the return type, but that seems a bit brittle. I haven't tried index yet, that might prove fruitful if I can figure out how to do that through sourcekitten.

@olbrichj
Copy link
Author

olbrichj commented Feb 6, 2018

Interesting. I get this for a small project I'm using:

"key.substructure" : [
          {
            "key.filepath" : "Path-to-Swift-File",
            "key.parsed_declaration" : "func stateDidChange(state: AppState)",
            "key.annotated_decl" : "<Declaration>func stateDidChange(state: <Type usr=\"s:5Ami8AppStateO\">AppState<\/Type>)<\/Declaration>",
            "key.fully_annotated_decl" : "<decl.function.method.instance><syntaxtype.keyword>func<\/syntaxtype.keyword> <decl.name>stateDidChange<\/decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>state<\/decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.enum usr=\"s:5Ami8AppStateO\">AppState<\/ref.enum><\/decl.var.parameter.type><\/decl.var.parameter>)<\/decl.function.method.instance>",
            "key.accessibility" : "source.lang.swift.accessibility.internal",
            "key.length" : 123,
            "key.substructure" : [

            ],
            "key.overrides" : [
              {
                "key.usr" : "s:5Ami16ObserverProtocolP14stateDidChangeyAA8AppStateO0D0_tF"
              }
            ],
            "key.parsed_scope.start" : 34,
            "key.typeusr" : "_T0y5Ami8AppStateO5state_tcD",
            "key.kind" : "source.lang.swift.decl.function.method.instance",
            "key.offset" : 967,
            "key.nameoffset" : 972,
            "key.typename" : "(AdPresenter) -> (AppState) -> ()",
            "key.name" : "stateDidChange(state:)",
            "key.usr" : "s:5Ami11AdPresenterC14stateDidChangeyAA8AppStateO0D0_tF",
            "key.bodyoffset" : 1005,
            "key.bodylength" : 84,
            "key.parsed_scope.end" : 38,
            "key.namelength" : 31
          }

But I used this command:

doc --module-name Ami -- -project Ami.xcodeproj

Maybe it resolves the files differently if you don't use projects. I'm also surprised that your methods doesn't have "key.substructure".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants