Skip to content

SourceKit document structure/key.substructure includes duplicate Swift attributes #75472

Open
@J-MR-T

Description

@J-MR-T

Description

In some cases, the key.substructure document substructure part of SourceKit requests such as editor.open, include the same attribute multiple times. I noticed this happening on an attribute with multiple arguments.

Reproduction

(sourcekitd-repl request to reproduce)

{
  key.request: source.request.editor.open,
  key.name: "myname",
  key.enablesubstructure: 1,
  key.sourcetext: "@available(iOS 16.0, macOS 13.0, *) func foo(){}"
}

Use this swift file as input for a SourceKit editor.open request:

@available(iOS 16.0, macOS 13.0, *)
func foo(){}

This is part of the editor.open response:

  key.substructure: [
    {
      key.kind: source.lang.swift.decl.function.free,
      key.accessibility: source.lang.swift.accessibility.internal,
      key.name: "foo()",
      key.offset: 36,
      key.length: 12,
      key.nameoffset: 41,
      key.namelength: 5,
      key.bodyoffset: 47,
      key.bodylength: 0,
      key.attributes: [
        {
          key.offset: 0,
          key.length: 35,
          key.attribute: source.decl.attribute.available
        },
        {
          key.offset: 0,
          key.length: 35,
          key.attribute: source.decl.attribute.available
        }
      ]
    }
  ]

Expected behavior

This includes the exact same attribute twice, in the key.attributes list, which doesn't seem useful, as there is no information on the attribute arguments anyway. I would either expect the two entries to differ in some way, or for there to only be one entry.

In addressing this, #75470 should also be taken into consideration.

Environment

Swift version 6.0-dev (LLVM b12fb441d8b2d6d, Swift cd7e4c3)
Target: arm64-apple-macosx14.0

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    SourceKitArea → source tooling: SourceKitattributesFeature: Declaration and type attributesavailabilityThe @available attribute and availability checking in generalbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.source toolingArea: IDE support, SourceKit, and other source toolingswift 6.0unexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions