Incorrect parse of subscripts
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 2.4k
- Forks
- 237
- PR merge metrics
- No merged PRs in 30d
Description
SourceKitten seems to have problems with this kind of Swift:
extension Test {
/// This comment is for subscript()
subscript(bounds: Range<Int>) -> String {
return "dummy 1"
}
}
extension Test {
/// This comment is for whatever()
func whatever() -> String {
return "dummy 2"
}
}
When that's run using sourcekitten doc --single-file test.swift it generates the following output:
{
"\/Users\/twostraws\/Desktop\/Issue\/test.swift" : {
"key.diagnostic_stage" : "source.diagnostic.stage.swift.parse",
"key.length" : 261,
"key.offset" : 0,
"key.substructure" : [
{
"key.bodylength" : 119,
"key.bodyoffset" : 16,
"key.kind" : "source.lang.swift.decl.extension",
"key.length" : 136,
"key.name" : "Test",
"key.namelength" : 4,
"key.nameoffset" : 10,
"key.offset" : 0,
"key.substructure" : [
]
},
{
"key.bodylength" : 103,
"key.bodyoffset" : 154,
"key.doc.comment" : "This comment is for subscript()",
"key.kind" : "source.lang.swift.decl.extension",
"key.length" : 120,
"key.name" : "Test",
"key.namelength" : 4,
"key.nameoffset" : 148,
"key.offset" : 138,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.internal",
"key.bodylength" : 30,
"key.bodyoffset" : 225,
"key.doc.comment" : "This comment is for whatever()",
"key.kind" : "source.lang.swift.decl.function.method.instance",
"key.length" : 58,
"key.name" : "whatever()",
"key.namelength" : 10,
"key.nameoffset" : 203,
"key.offset" : 198
}
]
}
]
}
}
So, an empty extension, followed by an extension commented using the comment from my subscript, which in turn contains the whatever() method. I would expect the This comment is for subscript() comment to appear in the first extension, along with subscript().
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 by reproducing the report with the Swift sample in test.swift using sourcekitten doc --single-file test.swift, then inspect the generated key.substructure output. The issue is done when the subscript and its comment appear in the correct extension and the unrelated whatever() method remains correctly represented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100