Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wojciech-kulik opened this issue Feb 4, 2024 · 15 comments

Comments

@wojciech-kulik
Copy link

Hi, I'm trying to figure out if there is any chance to support smart rename. I found this conversation:
swiftlang/sourcekit-lsp#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
Copy link
Owner

SolaWing commented Feb 4, 2024

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
Copy link
Author

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
Copy link
Owner

SolaWing commented Feb 5, 2024

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
Copy link
Author

I include logs after setting SOURCEKIT_LOGGING=3
lsp.log

@SolaWing
Copy link
Owner

SolaWing commented Feb 5, 2024

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
Copy link

fireplusteam commented Feb 5, 2024

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
Copy link
Author

wojciech-kulik commented Feb 5, 2024

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
Copy link
Author

wojciech-kulik commented Feb 5, 2024

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
Copy link
Owner

SolaWing commented Feb 5, 2024

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

@fireplusteam
Copy link

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

@SolaWing
Copy link
Owner

SolaWing commented Feb 5, 2024

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

@fireplusteam
Copy link

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

@fireplusteam
Copy link

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

@wojciech-kulik
Copy link
Author

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
Copy link
Author

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 🔥 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants