How to use SourceKit-LSP

hello I'm intaek cho from Korea.
I'm reading some documents about SourceKit-LSP because of GSOC2020.
I'm just curious about how to use SourceKit-LSP. I just installed a latest snapshots earlier.
but I was not able to run any commands like 'xcrun sourcekit-lsp' that is in README on terminal.
all it does see errors like 'xcrun: error: unable to find utility "sourcekit-lsp", not a developer tool or in PATH'.

what should I do after install snapshots?

I'm still learning English by the way, please understand.
thanks.

I don't know anything about sourcekit-lsp, but you should be able to do eg this (assuming you have installed a recent development snapshot):

xcrun --toolchain swift sourcekit-lsp --help

Which on my system will print:

OVERVIEW: Language Server Protocol implementation for Swift and C-based languages

USAGE: sourcekit-lsp [options]

OPTIONS:
  --build-path          Specify build/cache directory
  --configuration, -c   Build with configuration (debug|release) [default: debug]
  --log-level           Set the logging level (debug|info|warning|error) [default: info]
  -Xcc                  Pass flag through to all C compiler invocations
  -Xclangd              Pass options to clangd command-line
  -Xcxx                 Pass flag through to all C++ compiler invocations
  -Xlinker              Pass flag through to all linker invocations
  -Xswiftc              Pass flag through to all Swift compiler invocations
  -index-db-path        Override index-database-path from the build system
  -index-store-path     Override index-store-path from the build system
  --help                Display available options
3 Likes

I did something which solved my problems. And I got same result like you of that command.
I don't know still what to do now after that, but thanks for reply!

I guess you’d probably want to use an editor which uses sourcekit-lsp. The project website includes instructions for how to do that. VSCode and Sublime Text are some popular editors you might want to try.

3 Likes

thanks for reply
yes I'm gonna use it for VScode. But I have a problem while using VScode.

[Error - 8:22:42 PM] Starting client failed
Launching server using command sourcekit-lsp failed.

This message is on terminal of VScode. What should I do?

and also I guess I can use sourcekit-lsp on Xcode right?
I got an error while using a command which is xcrun sourcekit-lsp.

I solved it finally.
For VScode, I set sourcekit-lsp path which is like

/Users/cho/sourcekit-lsp/.build/x86_64-apple-macosx/debug/sourcekit-lsp

on 'Server Path section' that you can find on Preference/Extensions/SourceKit-LSP.

I don’t think Xcode uses LSP yet, but I’m not sure (if it did, I’m sure the sourcekit-lsp docs would mention it). In any case, VSCode is kind of the “reference implementation” that everybody works off. It’s also open-source and more easily debuggable.

Glad that you got it working.

1 Like

On Xcode 11.4, which it was released just few days ago, you get the sourcekit-lsp along with Xcode.

there is just one problem that I have with running it. I did as exactly as the doc says, xcrun sourcekit-lsp, but it doesn't seem to run. it's just there and nothing happens... any idea how long does it take to run? :slight_smile:

thanks.

Hi @TheAlienMann, you don't generally want to run the server from the command-line, you want to configure an LSP-compatible editor to run it. There are instructions for the most popular editors here; the general idea is to configure the editor to run xcrun sourcekit-lsp, or if the editor requires the full path to the executable, you can use xcrun --find sourcekit-lsp to get it. If you just want to sanity-check the executable, you could use the --help option to see the help message.

1 Like

I have XCode 11.4 installed, but there seems to be no sourcekit-lsp, xcrun sourcekit-lsp fails. So how can I get it?

you don't need to run xcrun sourcekit-lsp at all, all you need to do is to find the path, where sourcekit-lsp is. run this in Terminal xcrun --find sourcekit-lsp , that's all you need to do. :slight_smile:

see if you get a path like this,
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-ls

Hi all,

I don't know if it would help anyone but while trying to run

xcrun --find sourcekit-lsp and xcrun sourcekit-lsp

I had the same error:

xcrun: error: unable to find utility "sourcekit-lsp", not a developer tool or in PATH.

What I did to solve this issue was to reset the path using xcode-select like so:

$ sudo xcode-select -r

It seemed indeed that I had fiddled with xcode-select in the past which I didn't remember.

Best regards,
Thierry

SourceKit-lsp not support xcode project natively, but SourceKit-lsp support BSP protocol to provide compiler options. I have developed a simple BSP server to make sourceKit-lsp use xcode's compile logs. currently it's basicly work like in a xcode. see https://github.com/SolaWing/xcode-build-server

2 Likes