swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
743 stars 51 forks source link

Docs don't appear when hovering over types & methods in result builders #446

Open tarasis opened 1 year ago

tarasis commented 1 year ago

Describe the bug

When editing a SwiftUI file, sometimes the callout docs work, and other times they don't. For instance in example code A the only things that have hover docs are body, View, or PreviewContent but others like Image, Text, .padding() don't.

In code B, Text, .padding() and .foregroundColor() and .blue do have hover docs.

To Reproduce Steps to reproduce the behavior:

  1. Open code A: Swift file with a SwiftUI struct. (see code below)
  2. Hover over body you will see partial docs in a callout
  3. Hover over Image(), or Text(), .padding(), .blur()
  4. No callout appears.

Expected behavior A callout should appear for all things in the SDK. Open Code B in a file, and hover over Text, .padding() and so on. All work.

Environment

Additional context

Example code A

import SwiftUI

struct ContentView: View {
    #if SWIFT_PACKAGE
        var image = AsyncImage(url: Bundle.module.url(forResource: "AltIconOutside", withExtension: "png"))
    #else
        var image = Image("AltIconTest", bundle: .main)
    #endif

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

Example code B:

import SwiftUI

struct SwiftUIView: View {
    var body: some View {
        Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
            .padding().foregroundColor(.blue)
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}
adam-fowler commented 1 year ago

Is this SwiftUI for iOS or macOS?

tarasis commented 1 year ago

For macOS.

I’ve tried with and without the SDK option being explicitly set to the location of the macOS SDK in Xcode.

Aside; why this came up is I realised I could edit / create Mac apps as a hybrid package / Xcode project. I prefer the editor in VSCode compared to Xcode, except that hover docs are inconsistent. (Code completion works fine in both files)

On 16 Nov 2022, at 23:58, Adam Fowler @.***> wrote:

 Is this SwiftUI for iOS or macOS?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

adam-fowler commented 1 year ago

This looks like it is not working for function called within result builders. This is most likely an issue with SourceKit-LSP. I've added the following issue https://github.com/apple/swift/issues/67216