How to get an IDE to work with the Swift project source code on Linux?

Hi everyone!

I'm pretty new to the project. I've fixed a couple of starter issues, but so far my development environment is basically a text editor, which I think is not ideal.

I'd like to know how setup swift with an IDE on Linux to get all those normal IDE features like auto-complete, refactor, etc.

I see there's an initiative to make a starter guide document, so I could add any info shared here to the doc, so other newbies to the project using Linux can have a easier time setting up the project.



Hi! You can check out sourcekit-lsp, which can be integrated into many different IDE/text editors

Here's the info how to integrate it with some of the text editors:

I think you are talking about an IDE for developing the Swift toolchain. I do not have one of those myself. I just use a text editor. It works well enough for me. But if I were to envision one it'd use Visual Studio Code, Bear, clangd, vscode-clangd and vscode-lldb. The hardest part, I imagine, would be getting Bear to see the CMake commands that the build scripts issue so it can generate the compile_commands.json.

If you are talking about building a development environment for writing Swift code. Then I'd agree with @cukr, sourcekit-lsp is the way to go. I can say from personal experience that works very well for SwiftPM projects (even if it includes system modules and C code). The best part is that you don't even need to build sourcekit-lsp it is included with the 5.2.1 toolchain. You just need to install the extension for your editor. @cukr's link to editors would be a good place to start. I use Visual Studio Code with the VSCode extension in the sourcekit-lsp in repository. The only thing that does not work well is the integration of the vscode-lldb extension with the lldb that comes with Swift. I don't, yet, have an integrated debugger. But print and dump get me really far in that way.


Hi guys! Thanks for all the help.

@rlovelett I managed to get the compile_commands.json file by running:

utils/build-script "your flags here" --extra-cmake-options "CMAKE_EXPORT_COMPILE_COMMANDS=ON"

This generates one json per directory. I then concatenated the three files in one big json and that seems to work fine for vscode. Do you think there would be any advantages to using bear instead?

Only thing missing now is configuring the debugger in vscode.

1 Like

Check out CLion - from JetBrains. It's a C/C++ IDE for Linux but it also has support (via plugins) for Swift.

Hi Galen! I actually meant how to get an IDE experience when working the Swift project source code. I think my title was pretty ambiguous, sorry about that, I edited it so now it's better.

If you know how to setup Clion to work with the Swift project source code please let me know, as I love the Jetbrains tools :slight_smile:

If you are able to pass in the flags that make the compile_commands.json I see no value in Bear.

Only thing missing now is configuring the debugger in vscode.

I remember this being difficult. It's been a long time since I tried but what I remember is that you need to start a process and then use the debugger to connect to an already running process. And from what I remember (at the time) this was not supported for LLDB on Linux. I think I even wrote a patch to enable that on Linux. I submitted it upstream to LLDB. The reviewer wanted tests that I didn't know how to write and I gave up. YMMV.

I am actually using Linux. Iā€™d love if you can make a detailed video/ guide on how to setup the environment with VSCode.

Thank you :pray:

I found a tutorial for Swift and CLion here:

But to be honest: 200 ā‚¬ yearly (!) and you get a C-IDE that is not optimized for Swift. I'm pretty sure, that Swift beginners won't spend that money.

What about using Atom or VSCode? There are a tons of fantastic plugins. I think there should be a short step by step guide, so that people can start with Swift on other platforms easily (and this will help as well when there is finally a windows compiler).

1 Like

Now there is a IDE platform called Theia:

Maybe someone will be smart enough to create an IDE that is optimized for Swift :slight_smile:

See the updated tutorial -

1 Like

I think setting up CLion is pretty basic. There is a plugin in their plugin store (the plugin is free though) and then I believe you just point the plugin to your Swift installation. I'll play with it later today or tomorrow and post an update if there's more to it than that.