Closed adam-fowler closed 8 months ago
This is in VSCode right?
This is in VSCode right?
Yes
rdar://102213837
The problem here is that we don’t get compiler arguments for the files in the Plugin
folder. We need a new API in SwiftPM to get those arguments. Once we have that API, fixing this should be trivial.
I filed https://github.com/apple/swift-package-manager/issues/6699 to add the new API to SwiftPM.
Here’s a stub of a test case in SwiftPMWorkspaceTests that I started writing. The expected compiler arguments are almost certainly not correct but it should be a good starting point
func testPluginArgs() throws {
// FIXME: should be possible to use InMemoryFileSystem.
let fs = localFileSystem
try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDir in
try fs.createFiles(root: tempDir, files: [
"pkg/Plugins/MyPlugin/a.swift": "",
"pkg/Sources/lib/lib.swift": "",
"pkg/Package.swift": """
// swift-tools-version:5.7
import PackageDescription
let package = Package(
name: "a",
products: [],
dependencies: [],
targets: [
.target(name: "lib"),
.plugin(name: "MyPlugin", capability: .buildTool)
]
)
"""
])
let packageRoot = try resolveSymlinks(tempDir.appending(component: "pkg"))
let tr = ToolchainRegistry.shared
let ws = try SwiftPMWorkspace(
workspacePath: packageRoot,
toolchainRegistry: tr,
fileSystem: fs,
buildSetup: TestSourceKitServer.serverOptions.buildSetup)
let aswift = packageRoot.appending(components: "Plugins", "MyPlugin", "a.swift")
let hostTriple = ws.buildParameters.triple
let build = buildPath(root: packageRoot, platform: hostTriple.platformBuildPathComponent())
XCTAssertEqual(ws.buildPath, build)
XCTAssertNotNil(ws.indexStorePath)
let arguments = try ws._settings(for: aswift.asURI, .swift)!.compilerArguments
check(
"-module-name", "lib", "-incremental", "-emit-dependencies",
"-emit-module", "-emit-module-path", arguments: arguments)
check("-parse-as-library", "-c", arguments: arguments)
check("-target", arguments: arguments) // Only one!
#if os(macOS)
let versionString = PackageModel.Platform.macOS.oldestSupportedVersion.versionString
check("-target", hostTriple.tripleString(forPlatformVersion: versionString), arguments: arguments)
check("-sdk", arguments: arguments)
check("-F", arguments: arguments, allowMultiple: true)
#else
check("-target", hostTriple.tripleString, arguments: arguments)
#endif
check("-I", build.pathString, arguments: arguments)
check(aswift.pathString, arguments: arguments)
}
}
Is there something that I need to do to enable this? I have this issue on swift 5.10, 5.10.1, and 6.0 toolchains, but this issue was closed as completed in January
The issue should be fixed in Swift 6.0 toolchains. If you are still seeing it, could you open a new issue for it with reproduction steps?
Many sourcekit-lsp features are missing for the
PackagePlugin
framework.If I set up a SwiftPM build plugin, while editing the plugin source code I don't get symbol completion or
textDocument/hover
output for the symbols from thePackagePlugin
framework.This is with Swift 5.7 on macOS 13