Pot*_*Ion 5 ios swift visual-studio-code language-server-protocol
当我离开 Mac 时,我仍然希望能够使用 VSCode 在我的 Linux 机器上起草 Swift 代码。但我无法sourcekit-lsp识别 iOS SDK 中的模块。
我偶尔会使用 Mac,但主要使用 Linux 机器。因此,我可以在 Mac 上构建应用程序,但我仍然希望能够使用 VSCode 提前在 Linux 机器上起草 Swift 代码。
但我无法sourcekit-lsp识别 iOS SDK 中的模块。与 TypeScript 开发人员类似references.d.ts,但速度很快,并且只有 VSCode/sourcekit-lsp 关心它。
我四处挖掘并Xcode.app发现了各种文件,在查看文本编辑器后,它们看起来提供了我想要的内容,但我不知道如何查看它们。.modulemap.swiftinterfacesourcekit-lsp
强调一下,我不期望也不希望能够在 Linux 机器上编译iOS 代码。在我的故障排除中,我
swift build只用来查找更有意义的错误。我不期望实际的构建发生——这就是 Mac 的用途。我只是希望能够在 VSCode 中使用本机模块(例如 UIKit)的自动完成功能,以便稍后将其复制到 Mac 上进行测试。
我知道,这是一个奇怪的工作流程,但这是我现在可以访问的。
我已经下载了 Xcode 11 beta 并将其解压,以便我可以访问框架/SDK。但是,我似乎无法找到一种方法来sourcekit-lsp理解各种框架的标头。
另外,swift 安装在/usr/local/bin/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-21-a-ubuntu18.04.
由于sourcekit-lsp没有记录很多错误,我决定swift build一遍又一遍地尝试,尽可能接近“工作”,直到希望sourcekit-lsp能找到一些东西。
到目前为止我已经尝试了很多不同的命令。但我会遵循我所取得的最佳进展。
我首先swiftc使用指向我的 SDK 和 iOS 目标-sdk Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -target arm64-apple-ios13.0
这修复了模块未找到错误(当我运行时swift build)
<unknown>:0: error: unable to load standard library for target 'arm64-apple-ios13.0'
Run Code Online (Sandbox Code Playgroud)
我猜测这是没有包含 swift 库,所以我复制Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos到/usr/local/bin/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-21-a-ubuntu18.04/usr/lib/swift/iphoneos,这确实修复了上述错误。
现在,swift build给我一个新错误:
<unknown>:0: error: compiled module was created by an older version of the compiler; rebuild 'Swift' and try again: /usr/local/bin/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-21-a-ubuntu18.04/usr/lib/swift/iphoneos/Swift.swiftmodule/arm64.swiftmodule
Run Code Online (Sandbox Code Playgroud)
此外,返回 VSCode,将鼠标悬停在模块导入上(如Foundation)会产生不同的错误:
error response (Request Failed): did not find primary SourceFile
Run Code Online (Sandbox Code Playgroud)
我尝试修复这些错误,但没有成功。我不需要swift build工作,但我只想sourcekit-lsp让我编写使用 UIKit 等的代码。
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Example",
platforms: [
.iOS("13.0")
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Example",
targets: ["Example"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "Example",
dependencies: [], swiftSettings: [SwiftSetting.unsafeFlags(["-sdk", "/why/doesnt/this/work/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk", "-target", "arm64-apple-ios13.0"])])
]
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
781 次 |
| 最近记录: |