Skip to content

Convert to computed property may generate code without a type annotation #2459

@ahoppen

Description

@ahoppen

Eg. consider the following new test case:

func testConvertStoredToComputedPropertyWithoutTypeAnnotation() async throws {
  try await assertCodeActions(
    ##"""
    1️⃣var 2️⃣foo = "abc"3️⃣
    """##,
    markers: ["2️⃣"],
    ignoringCodeActions: ["Add documentation"]
  ) { uri, positions in
    [
      CodeAction(
        title: "Convert to computed property",
        kind: .refactorInline,
        edit: WorkspaceEdit(
          changes: [
            uri: [
              TextEdit(
                range: positions["1️⃣"]..<positions["3️⃣"],
                newText: """
                  var foo { "abc" }
                  """
              )
            ]
          ]
        )
      )
    ]
  }
}

Notice how the generated code is invalid var foo { "abc" } because it doesn’t have a type annotation. What we should do is:

  • In ConvertStoredPropertyToComputed.Context allow specifying the type of the variable (which LSP can get via a cursor info request). The code action can then insert it. Should it not be possible to determine the type, we should insert an editor placeholder instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code actionCode action provided by LSP

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions