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

Source Kitten Type Inference? #661

Open
ArEnSc opened this issue Jul 22, 2020 · 3 comments
Open

Source Kitten Type Inference? #661

ArEnSc opened this issue Jul 22, 2020 · 3 comments

Comments

@ArEnSc
Copy link

ArEnSc commented Jul 22, 2020

Hey so I am trying to solve a problem using sourceKitten.
In our source code people are don't like to insert the static type annotation, multiply this by 50 developers and it results in slow build times.

I was thinking of using source kitten to reveal the structure of the source and then reinsert the static types, so that we can do whatever we can to eat away at slow build times pre compile.

However it seems that in my example i,j we do not get the type to be inferred to be an Int.

Is this something we can build into source kitten ? i.e obtain inferred types in the structure?

sourcekitten structure --file /Users/raisintoastllc/Desktop/example.swift

class Hello {
    var i = 0
    var j = 1

    var k:Any = 1
    func shift() -> Int {

    }
}
{
  "key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
  "key.length" : 258,
  "key.offset" : 0,
  "key.substructure" : [
    {
      "key.accessibility" : "source.lang.swift.accessibility.internal",
      "key.bodylength" : 81,
      "key.bodyoffset" : 175,
      "key.kind" : "source.lang.swift.decl.class",
      "key.length" : 95,
      "key.name" : "Hello",
      "key.namelength" : 5,
      "key.nameoffset" : 168,
      "key.offset" : 162,
      "key.runtime_name" : "_TtC4main5Hello",
      "key.substructure" : [
        {
          "key.accessibility" : "source.lang.swift.accessibility.internal",
          "key.kind" : "source.lang.swift.decl.var.instance",
          "key.length" : 9,
          "key.name" : "i",
          "key.namelength" : 1,
          "key.nameoffset" : 184,
          "key.offset" : 180,
          "key.setter_accessibility" : "source.lang.swift.accessibility.internal"
        },
        {
          "key.accessibility" : "source.lang.swift.accessibility.internal",
          "key.kind" : "source.lang.swift.decl.var.instance",
          "key.length" : 9,
          "key.name" : "j",
          "key.namelength" : 1,
          "key.nameoffset" : 198,
          "key.offset" : 194,
          "key.setter_accessibility" : "source.lang.swift.accessibility.internal"
        },
        {
          "key.accessibility" : "source.lang.swift.accessibility.internal",
          "key.kind" : "source.lang.swift.decl.var.instance",
          "key.length" : 13,
          "key.name" : "k",
          "key.namelength" : 1,
          "key.nameoffset" : 213,
          "key.offset" : 209,
          "key.setter_accessibility" : "source.lang.swift.accessibility.internal",
          "key.typename" : "Any"
        },
        {
          "key.accessibility" : "source.lang.swift.accessibility.internal",
          "key.bodylength" : 6,
          "key.bodyoffset" : 248,
          "key.kind" : "source.lang.swift.decl.function.method.instance",
          "key.length" : 28,
          "key.name" : "shift()",
          "key.namelength" : 7,
          "key.nameoffset" : 232,
          "key.offset" : 227,
          "key.typename" : "Int"
        }
      ]
    }
  ]
}



@ArEnSc
Copy link
Author

ArEnSc commented Jul 22, 2020

@jpsim

@johnfairh
Copy link
Collaborator

The structure query just describes the parsed text of the program. You can use the SourceKit cursor-info request to get a type-checked view of an identifier -- sourcekitten doc does this for declarations which might be enough for you to get started.

@yume190
Copy link

yume190 commented Feb 8, 2022

I use sourcekitten cursor-info and swift-syntax to fill variables type.

here link: TypeFill

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

3 participants