I have the Swift compiler repo built with Ninja and tried to use SourceKit-LSP on Visual Studio Code to develop the Swift compiler repo. The clangd arguments forwarding works so far so good. But the Swift files can only get compiled with fallback arguments which makes the definition jumping to be constrained in a single file:
[2023-07-15 10:00:22.830] {
key.request: source.request.cursorinfo,
key.compilerargs: [
"-sdk",
"/Applications/Xcode-15.0-beta-2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk",
"/Users/REDACTED/swift-project/swift/stdlib/public/core/Dictionary.swift"
],
key.offset: 21037,
key.sourcefile: "/Users/REDACTED/swift-project/swift/stdlib/public/core/Dictionary.swift",
key.retrieve_refactor_actions: 1
}
This is my arguments for SourceKit LSP:
"sourcekit-lsp.serverArguments": [
"--log-level",
"debug",
// "--scratch-path",
// "../build/Ninja-DebugAssert/swift-macosx-arm64",
// clangd began
"-Xclangd",
"--compile-commands-dir=../build/Ninja-DebugAssert/swift-macosx-arm64/",
"-Xclangd",
"--query-driver=/Applications/Xcode-15.0-beta-2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang",
"-Xclangd",
"--all-scopes-completion",
"-Xclangd",
"--cross-file-rename",
"-Xclangd",
"--pch-storage=memory",
"-Xclangd",
"--background-index",
"-Xclangd",
"-j=10",
"-Xclangd",
"--inlay-hints=true",
// clangd ended
],
I also have made an alias of compile_commands.json
in Swift's build directory root to the root of the Swift compiler's project root. SourceKit LSP correctly read the IndexStore in Swift's build directory. But it does not work after all.
It seems that the build commands for particular Swift files in Swift compiler's repo like Dictionary.swift is stored in build.ninja
but not compile_commands.json
. But there is no such an implemented build server for ninja. I'm guessing that we cannot make SourceKit LSP work with Swift files in Swift compiler's repo before having a build server that implements build server protocol for Ninja. If that's wrong, how can I make SourceKit LSP work with those Swift files.