Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CursorInfo doesn’t provide a result if result builder contains an error #67216

Open
adam-fowler opened this issue Nov 17, 2022 · 2 comments
Open

Comments

@adam-fowler
Copy link

adam-fowler commented Nov 17, 2022

Reported in swift-vscode repo swiftlang/vscode-swift#446

In the code below hover fails for Text, image and HStack inside the View resultBuilder while it works for everything outside of the resultBuilder.

import SwiftUI

struct ContentView: View {
    var image = Image("AltIconTest", bundle: .main)
    var body: some View {
        Text("I've been edited in VSCode. But can be run from both Xcode and VSCode.")
            .padding()
        image
        HStack {
            // none of these will appear when built with swift build & run as it doesn't compile asset catalogue
            // only appears when compiled and run from Xcode
            Image("Buddy").border(.blue)
            // will appear in Xcode version and xcodebuild version
            Image(packageResource: "Buddy", ofType: "png", from: .assetCatalog).border(.orange)
            // will only appear in xcodebuild version
            Image("Buddy", bundle: .module).border(.green).blur(radius: 0.1)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
@adam-fowler adam-fowler changed the title textDocument/hover doesn't work for function calls inside ResultBuilders textDocument/hover doesn't work for symbols inside ResultBuilders Nov 17, 2022
@ahoppen
Copy link
Member

ahoppen commented Nov 17, 2022

rdar://102473561

@ahoppen
Copy link
Member

ahoppen commented Jul 11, 2023

This issue is not specific to SourceKit-LSP. The cursor info request that underlies hover does not provide results if the result builder body has an error. The solution here is to convert cursor info to the solver-based implementation as well but that might take a while.

The following reduced test case fails.

@resultBuilder
struct MyBuilder {
  static func buildBlock<Content>(_ components: Content...) -> Content {
    fatalError()
  }
  public static func buildExpression<Content>(_ content: Content) -> Content { return content }
}

struct ContentView {
  /// Some documentation
  var someInt: Int = 2

  @MyBuilder
  var body: Int {
    // RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):5 %s -- %s | %FileCheck %s
    someInt
    someInvalidRef
  }
}

// CHECK: source.lang.swift.ref.var.instance (11:7-11:14)

@ahoppen ahoppen transferred this issue from swiftlang/sourcekit-lsp Jul 11, 2023
@ahoppen ahoppen changed the title textDocument/hover doesn't work for symbols inside ResultBuilders CursorInfo doesn’t provide a result if result builder contains an error Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants