SourceKitten icon indicating copy to clipboard operation
SourceKitten copied to clipboard

Incorrect parse of subscripts

Open twostraws opened this issue 8 years ago • 0 comments

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().

twostraws avatar Jan 12 '18 02:01 twostraws