SolaWing / xcode-build-server

a build server protocol implementation for integrate xcode with sourcekit-lsp
MIT License
424 stars 19 forks source link

Integration with Swift Development Snapshot? (support for smart rename) #34

Closed wojciech-kulik closed 9 months ago

wojciech-kulik commented 9 months ago

Hi, I'm trying to figure out if there is any chance to support smart rename. I found this conversation: https://github.com/apple/sourcekit-lsp/issues/498

and they say that it is supported by the latest swift development snapshot. So I installed it and I switched my lsp cmd to:

/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/sourcekit-lsp

I see that the lsp client is attached but the code completion stopped working completely. When I run :LspLog I see only:

[START][2024-02-04 12:57:59] LSP logging initiated
[ERROR][2024-02-04 12:57:59] .../vim/lsp/rpc.lua:734    "rpc"   "/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/sourcekit-lsp"  "stderr"    "SWIFT TASK CONTINUATION MISUSE: run() leaked its continuation!\nINFO:root:Xcode Build Server Startup. Waiting Request...\n"

I'm not sure if it is a problem with LSP itself or with xcode-build-server? Is there any difference whether I use sourcekit-lsp from Xcode or from this package?

SolaWing commented 9 months ago

It shouldn't has any issue. can you run it with environment SOURCEKIT_LOGGING=3 or XBSDEBUG=1 to see the full detailed logs?

also notice main branch version maybe not stable as release version

wojciech-kulik commented 9 months ago

Do you know how can I run it this way?

    lspconfig["sourcekit"].setup({
      capabilities = capabilities,
      on_attach = on_attach,
      cmd = {
        "SOURCEKIT_LOGGING=3 /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/sourcekit-lsp",
      },
}

This way it doesn't work, it says the path is incorrect

SolaWing commented 9 months ago

you can set env in parent process like vim or terminal, child process will inherit it. lspconfig seems have cmd_env too(not tested)

wojciech-kulik commented 9 months ago

I include logs after setting SOURCEKIT_LOGGING=3 lsp.log

SolaWing commented 9 months ago

It seems different swift toolchain may not compatible. since you use newest toolchain from lsp, you should compile from this toolchain too. this may fix any potential compatible issue.

second, I found there is error: error: unknown argument: '-emit-localized-strings'error: unknown argument: '-emit-localized-strings-path'\n in your log, maybe this is the specific argument not supported by newest toolchain. delete it from flags may fixes problem.

I will test this case when I have time

fireplusteam commented 9 months ago

I also tried to run the latest snapshot and looks like it doesn't know about a parameter -emit-localized-strings. Also tried to build a project with latest snapshot, but that parameter is also here as well

error response (Request Failed): error: unknown argument: '-emit-localized-strings'error: unknown argument: '-emit-localized-strings-path'
[Trace - 12:51:23] Received response 'textDocument/diagnostic - (102)' in 1ms.
Result: {
    "items": [],
    "kind": "full"
}
wojciech-kulik commented 9 months ago

Second, I found there is error: error: unknown argument: '-emit-localized-strings'error: unknown argument: '-emit-localized-strings-path'\n in your log, maybe this is the specific argument not supported by newest toolchain. delete it from flags may fixes problem.

It appeared after using gd

I will test this case when I have time

Ok, thank you!

since you use newest toolchain from lsp, you should compile from this toolchain too

Do you know how to change toolchain when using Xcode?

wojciech-kulik commented 9 months ago

And thank you for your amazing work! This tool allowed me to move my iOS development to Neovim. I also built a plugin that integrates all needed Xcode-actions into Neovim. If you also develop iOS/macOS apps you may want to check it out: https://github.com/wojciech-kulik/xcodebuild.nvim Thank you 🍻

SolaWing commented 9 months ago

xcode can change toolchains by menu. xcodebuild seems has -toolchain parameter too

图片
fireplusteam commented 9 months ago

also you can try to set export TOOLCHAINS=org.swift.510202402021a where org.swift.510202402021a can be found in plist of toolchain

SolaWing commented 9 months ago

I just push newest-toolchain branch, which reject the -emit-localized-strings flags. check if this works? @wojciech-kulik

fireplusteam commented 9 months ago

@SolaWing , for me it works fine with your fix, thanks

fireplusteam commented 9 months ago

Also, go to reference works much better with the latest sourcekit-lsp :)

wojciech-kulik commented 9 months ago

I can't build the project from Xcode using other toolchain. Any idea why?

ld: file cannot be open()ed, errno=2 path=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-02-03-a.xctoolchain/usr/lib/clang/17/lib/darwin/libclang_rt.profile_iossim.a in '/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-02-03-a.xctoolchain/usr/lib/clang/17/lib/darwin/libclang_rt.profile_iossim.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
wojciech-kulik commented 9 months ago

It turned out that it doesn't work with one of the dependencies. This approach works with other projects after your fix @SolaWing 🙌 .

However, this swift version is not stable enough to use it for work. 50% of my iOS projects don't work with it. But it's good to know that finally, smart rename will work with the new release, I checked it and it renamed classes correctly 🔥 .