[Question] iOS support
Is there any way to set up the LSP to work with iOS apps? Specifically with iOS SPM packages? I have a project which is based on SPM modularized architecture.
I have found a way to compile packages for iOS using the following command:
xcodebuild -scheme PackageName -destination 'platform=iOS Simulator,OS=16.4,name=iPhone 14'
However, when I try to develop some classes in my editor I get these errors in LSP logs:
[ERROR][2023-09-14 12:02:28] .../vim/lsp/rpc.lua:734 "rpc" "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp" "stderr" "[2023-09-14 12:02:28.905] [error]: the library 'SomDependency' requires macos 10.13, but depends on the product 'Kingfisher' which requires macos 10.14; consider changing the library 'SomDependency' to require macos 10.14 or later, or the product 'Kingfisher' to require macos 10.13 or earlier.\n"
It looks like the LSP is trying to build the project for macOS. I tried configuring LSP like this:
lspconfig["sourcekit"].setup({
capabilities = capabilities,
on_attach = on_attach,
cmd = { "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp",
"-Xswiftc", "-sdk",
"-Xswiftc", "/Users/xyz/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk",
"-Xswiftc", "-target",
"-Xswiftc", "arm64-apple-ios16.4-simulator" },
})
but I get the same errors when I try to work with my Swift files. I would like to be able to work on my project in Neovim or VSCode.
There's currently no way to make LSP work with cross-compilation.
😢 so it looks like iOS developers are doomed to use Xcode forever as the only IDE 😭
Tracked in Apple’s issue tracker as rdar://115484487
@wojciech-kulik you can try my tool xcode-build-server to bind xcode project compile info to sourcekit-lsp.
There's currently no way to make LSP work with cross-compilation.
So -sdk and -target do not work? I've had UIKit, SwiftUI completion with these parameters. It becomes problematic when you need to build a full project. There are a number of hurdles there, but breaking everything off into libraries and compiling them using swift CLI using same parameters generally works (as long as you aren't building tests).
These issues might be helpful! (Signed, a stubborn Sublime user)
#730 - xcodebuild support for sourcekit-lsp
https://github.com/apple/swift-package-manager/issues/4328 - SPM multiple targets
https://github.com/apple/swift-package-manager/issues/5619 - SPM unknownOS in -triple
@wojciech-kulik you can try my tool xcode-build-server to bind xcode project compile info to sourcekit-lsp.
Thank you! It seems to work! I'm only struggling with root_dir detection by lspconfig. It doesn't work properly when my xcodeproj is not where .git is located. Any advice on how to find it?
I tried:
root_dir = function(filename, _)
local git_root
git_root = lspconfig.util.find_git_ancestor(filename)
local handle = io.popen("find \"" .. git_root .. "\" -type d -name \"*.xcodeproj\" | tail -n 1 | xargs dirname")
local result = handle:read("*a")
handle:close()
return result
end,
but for some reasons, it doesn't work.
@wojciech-kulik may be you should use handle:read("*l")? "*a" return all output, which end with a invalid "\n".
anyway, the generated buildServer.json can be any dir, just ensure it same with your lsp root, it not have to in same dir as xcodeproj.
@SolaWing it helped, thank you!
I’m closing this since it’s the same underlying issue that we’re already tracking in #730.
I described how to set up Neovim and VS Code here: https://wojciechkulik.pl/ios/how-to-develop-ios-and-macos-apps-in-other-ides-like-neovim-or-vs-code
@wojciech-kulik may be you should use
handle:read("*l")? "*a" return all output, which end with a invalid "\n".anyway, the generated buildServer.json can be any dir, just ensure it same with your lsp root, it not have to in same dir as xcodeproj.
Had the same problem, was keeping buildServer.json file in the same dir as the workspace, then moved it to the .git directory, and resolved the issue. Thank you