Closed tonyarnold closed 4 months ago
Go to the settings and type the following in the filter bar @id:editor.defaultFormatter @lang:swift
. The setting that comes up should be set to Swift. VSCode normally comes up with a dialog if no formatter is chosen, don't know why that didn't appear
I just followed those instructions, and it still does the same thing. It added the following lines to my settings.json:
"[swift]": {
"editor.defaultFormatter": "sswg.swift-lang"
}
ok, working fine for me, but I'm using a nightly build of swift swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-22-a.xctoolchain/
. It should work for Xcode beta builds as well.
If you look in <Xcode install directory>/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
do you see swift-format?
Yeah, it's definitely there:
.rwxr-xr-x@ 21M tonyarnold 26 Jun 07:19 /Applications/Xcode-16.0.0-Beta.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format
Oh hang on, this is an LSP issue:
[Error - 20:28:54] SourceKit Language Server client: couldn't create connection to server.
Message: Pending response rejected since connection got disposed
Code: -32097
Error: Unknown option '--experimental-feature'
Usage: source-kit-lsp <options> <subcommand>
See 'source-kit-lsp --help' for more information.
[Error - 20:28:54] Server process exited with code 64.
[Error - 20:28:54] Server initialization failed.
Message: Pending response rejected since connection got disposed
Code: -32097
I tried to follow the guide here: https://github.com/apple/sourcekit-lsp/blob/main/Documentation/Enable%20Experimental%20Background%20Indexing.md
Ah if LSP doesn't start then you won't get formatting via the swift extension. You should report those issues setting up background indexing on the SourceKit-LSP repo
On further investigation, the sourcekit-lsp
binary included with Xcode 16 betas is quite old, and does not include the flags mentioned in that document you linked from the forums.
It's not an issue for this extension, but it may be worth mentioning in your post?
When running the "Format Document" command, I get the following error: "There is no formatter for swift files installed".
I have Xcode 16 beta 2 set as my Swift toolchain.
Environment