swiftlang / vscode-swift

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

BUG: #Preview gets flagged as an error (plugin for module 'PreviewsMacros' not found) #943

Closed davidalejandroaguilar closed 4 months ago

davidalejandroaguilar commented 4 months ago

Feel free to dismiss if this only happens in beta, but would be great if someone has encountered this already (no open issues about this).

Also, if it can't be fixed, wondering if there's a way to tell the extension to ignore it.

On:

With this code:

// Error here
#Preview {
  ContentView()
}

Getting error:

External macro implementation type 'PreviewsMacros.SwiftUIView' could not be found for macro 'Preview(_:body:)'; plugin for module 'PreviewsMacros' not foundSourceKit
ContentView.swift(126, 1): 'Preview(_:body:)' declared here (SwiftUI.Preview)

VSCode settings:

  "[swift]": {
    "editor.defaultFormatter": "vknabel.vscode-swiftformat"
    // Also tried with:
    // "editor.defaultFormatter": "sswg.swift-lang"
  },
  "swift.path": "/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
image
adam-fowler commented 4 months ago

These macros don't exist in VSCode so not much we can do here. Does wrapping as follows work

#if canImport(PreviewMacros)
#Preview {
  ContentView()
}
#endif               
plemarquand commented 4 months ago

Closing this since it isn't an issue with vscode-swift specifically.

@davidalejandroaguilar Could you attach a zipped bundle of the output from the Swift: Capture VS Code Swift Diagnostic Bundle command? That might help diagnose why this macro can't be found.

davidalejandroaguilar commented 3 months ago

Thanks for taking a look at this @plemarquand, appreciate your time.

I tried to get a full diagnostic but got this error Error: Unknown option '--bundle-output-path':

Unable to capture diagnostic logs: Error: Command failed: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp diagnose --bundle-output-path /var/folders/l2/q76ntgmn4wb0nvrpc97yl1xr0000gn/T/vscode-diagnostics-2024-07-10T00-00-24+03-00/sourcekit-lsp --toolchain /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr Error: Unknown option '--bundle-output-path' Usage: source-kit-lsp diagnose [--os-log-history <os-log-history>] [--toolchain <toolchain>] [--components <components> ...] See 'source-kit-lsp diagnose --help' for more information.

The minimal diagnostics files are very small:

vscode-diagnostics-2024-07-10T00-00-55+03-00.zip

davidalejandroaguilar commented 3 months ago

Also, wrapping it in #if canImport(PreviewMacros) works to ignore this issue's error!

davidalejandroaguilar commented 3 months ago

Ahh damn, but wrapping it in #if canImport(PreviewMacros) breaks the preview in XCode... sad.