Is there a way to get implied type information?
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 2.4k
- Forks
- 237
- PR merge metrics
- No merged PRs in 30d
Description
For example on the following file:
class Thing {
let object = 5
}
sourcekitten structure --file produces
{
"key.substructure" : [
{
"key.kind" : "source.lang.swift.decl.class",
"key.offset" : 0,
"key.nameoffset" : 6,
"key.namelength" : 5,
"key.bodyoffset" : 13,
"key.bodylength" : 20,
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.substructure" : [
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 18,
"key.nameoffset" : 22,
"key.namelength" : 6,
"key.length" : 14,
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.typename" : "object",
"key.name" : "object"
}
],
"key.name" : "Thing",
"key.runtime_name" : "_TtC8__main__5Thing",
"key.length" : 34
},
{
"key.kind" : "source.lang.swift.decl.var.global",
"key.offset" : 36,
"key.nameoffset" : 40,
"key.namelength" : 5,
"key.length" : 19,
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.setter_accessibility" : "source.lang.swift.accessibility.internal",
"key.typename" : "thing",
"key.name" : "thing"
},
{
"key.kind" : "source.lang.swift.expr.call",
"key.offset" : 48,
"key.nameoffset" : 48,
"key.namelength" : 5,
"key.bodyoffset" : 54,
"key.bodylength" : 0,
"key.length" : 7,
"key.name" : "Thing"
}
],
"key.diagnostics" : [
{
"key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
"key.description" : "expected member name following '.'",
"key.severity" : "source.diagnostic.severity.error",
"key.column" : 20,
"key.filepath" : "--",
"key.line" : 5
}
],
"key.offset" : 0,
"key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
"key.length" : 56
}
The important thing in the above is key.typename is "object". If you add in the explicit type:
class Thing {
let object: Int = 5
}
Then the syntax command for key.typname is "Int"
I realize this would be a different type of parsing -- not only structure but also semantic analysis (which is I assume this code https://github.com/apple/swift/tree/master/lib/Sema). But I'm just curious if this is something that exists already in source kitten behind the scenes or if it would be a fully new thing.
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing sourcekitten structure --file command and compare its output for inferred and explicit property types. Review the referenced Swift lib/Sema area to determine whether inferred type information is already available; done means establishing a defined way for SourceKitten to expose it or documenting why it cannot.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- compilers, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100