My Hackathon Camp Project: Building a Swift IDE
Hackathons are the longest running tradition in Facebook’s engineering culture. This hackathon featured a “summer camp” theme and spanned three days. I decided to use that time to build an IDE for Swift.
Three days isn’t enough time to build an IDE application from scratch. Instead, I built a relatively small package that integrated into Nuclide, which itself is a package for the Atom editor. I call the package
Atom and Nuclide are “hackable”: they expose APIs (called “services”) that allow plugins (called “packages”) to interact with every single part of the editor. In fact, nearly every feature of Atom – its file tree sidebar, its open file buffer, its panes – is implemented as a package.
Scroll down for some demos of what I was able to accomplish in three days of Nuclide development. Scroll further for things to come, and for details on when and how you’ll be able to use these features.
Note: If you find this post on Swift integration in Nuclide useful, consider helping me write more of these posts, by supporting me on Patreon.
What nuclide-swift can do today
Build Swift packages via a toolbar
I used the
nuclide.build-system-registry service to display a toolbar to build Swift packages. The toolbar provides a GUI that interacts the Swift package manager command line interface,
swift build. Build output is displayed via the
Test Swift packages via that same toolbar
Another integration between the
nuclide.build-system-registry service and the Swift package manager’s
swift test command. I highlight the test failures in this demo, but don’t expect to see this UI in the official release – it’ll use the
nuclide-test-runner service instead.
nuclide-swift registers itself as an
autocomplete.provider service. It uses the build commands generated by the Swift package manager, and feeds those to SourceKitten. SourceKitten is a convenient wrapper for Apple’s SourceKit, the technology behind the autocompletion suggestions Xcode provides.
I’m proud of this integration. Most Swift editor plugins I’ve seen don’t provide SourceKitten with build commands, and as a result their autocompletion suggestions are inaccurate or incomplete.
nuclide-swift, thanks to its build integration, can get autocompletion suggestions on par with Xcode.
nuclide-swift also registers as a
nuclide-type-hint.provider, to display type information for any Swift symbol you hover over. Another happy collaboration between Nuclide, the Swift package manager, and SourceKitten.
sourcekitten structure meets
nuclide-outline-view to displays the hierarchy of symbols – classes, structs, methods, variables – defined in a Swift source file. Clicking on a symbol in the outline view moves your cursor to that position in the source code.
Automatically format Swift source code
sourcekitten format and
nuclide-code-format.provider join forces to end the “tabs vs. spaces” debate once and for all.
This feature comes thanks to Nico Reed.
Swift package commands
Create a new Swift package, fetch its dependencies, and more, all from within Nuclide.
This feature comes thanks to Kevin Casey.
Coming soon to nuclide-swift
Display errors in your Swift code as you type
This won’t be hard to do, thanks to SourceKit and the
nuclide-diagnostics-provider service. I’ll be sending pull requests to SourceKitten to add the commands I need.
⌘-click to jump to declaration
hyperclick.provider service makes it easy to jump to another source code location via ⌘-click, and I think SourceKit can provide the declaration location.
One of Nuclide’s killer features is its ability to connect to remote servers when editing. It’s trivial to modify
nuclide-swift so that it can connect to a server. This would allow you to edit the source code for your server-side Swift application, build it, run its tests, attach a debugger – all from the Nuclide IDE.
Better testing support
It should be possible to lists tests in a package, display pass/fail in the gutter, and re-run tests by clicking on them, thanks to a combination of
swift test --list-tests, SourceKit’s
is_test_candidate flag, and Nuclide’s gutter APIs. I’m still learning about all the features of the
nuclide-test-runner service, so expect the UI here to change a lot.
How do I install this?
You can install Nuclide right now, but the features here won’t be available to download for a week or two. I coded most of these features during a hackathon, and now I need to clean the code up and add some unit tests.
If you’d like to contribute, send your pull requests to my
A lot of open-source software made these features possible, but it’s hard to express just how awesome SourceKitten is. Kudos to JP Simard, Norio Nomura, and all the other contributors. ❤️