Need setup help for sourcekit-lsp with an Xcode project

I know very little about Swift or XCode. I want to write a spreadsheet app but that’s another topic. Right now, I’m trying to get Emacs to work with lsp-mode which uses sourcekit-lsp.

I am using this project (click the Download button) to test with. When I start Xcode and do a build, it builds successfully.

The screenshot attached shows that sourcekit-lsp is confused. The @main is flagged and then the other structures which is part of swiftui are flagged.

I have also tried eglot. To start with, it flagged the same errors. Then I created a Package.swift file (which is probably not 100% correct) and that resolved those errors. With lsp-mode, it made no difference. eglot still has other errors. For example, the :robot in WritingApp/Views/AccessoryView.swift is flagged. I assume that it is defined somewhere somehow since the build is successful.

Update: Using eglot, I got almost everything working with the following Package.swift file:

// swift-tools-version:6.3
import PackageDescription

let package = Package(
    name: "WritingApp",
    platforms: [
        .iOS(.v26), .macOS(.v26)
    ],
    targets: [
        .executableTarget(
            name: "WritingApp",
            dependencies: [],
            path: "WritingApp",
	    resources: [.process("Resources")]
	),
    ]
)

There is one error in the EGLOT events buffer. It appears that <-- client/registerCapability[sk-0] {"id":"sk-0" ... doesn't work and is errored off with --> client/registerCapability[sk-0] {"jsonrpc":"2.0","id":"sk-0","error":{"code":-32603,"message":"Internal error"}}

But lsp-mode still is unchanged. I'm new to all this so I'm not sure which is better / preferred.

My Emacs set up now appears to be working 100%. Here is what I did in case others follow in my footsteps.

I gave up on lsp-mode and switched to eglot. I went back to xcode-build-server and installed it a second time. I’m on a Mac so I installed it using brew. I also did an update and upgrade for brew in case that matters but I don’t think it does. After installing the code, I executed xcode-build-server config -project *.xcodeproj. This produced buildServer.json. When I tested my Emacs setup, it worked.

The -32603 error was fixed by patching eglot.el as mentioned in this bug report.

I also had problems as mentioned with .robot not being defined. The project has resources. Apparently Xcode generates code based upon those resources which is tucked away in ~/Library/Developer/Xcode/DerivedData. The full path is specified in the build_root attribute in the buildServer.json file created by xcode-build-server. sourcekit-lsp must read the buildServer.json file and is thus able to find the definitions that it could not find before. This is vaguely documented in this bug report.