Building Swift Sourcekit on Linux

Error in backend: invalid llvm.linker.options building SourceKit-LSP on Ubuntu 18.10

This is an llvm bug (https://bugs.llvm.org/show_bug.cgi?id=39743). See workaround here: https://forums.swift.org/t/error-while-trying-to-build-sourcekit-lsp-on-linux/18138/2

XcodeKit and SourceKit

Depending on your end goal, you have a few options:

  • SwiftSyntax is a new (beta) open-source framework from Apple for walking through/modifying a document’s AST (abstract syntax tree). More information & an example are available on the GitHub repository.

  • As mentioned, SourceKitten is a Swift library for communicating with SourceKit. SourceKit is the backbone of Xcode, which is really just a glorified text editor without it. It provides everything from semantically-analyzed substructures and generated interfaces to code-completion and syntax highlighting—everything an IDE needs. It is the most encompassing option and it's not going anywhere anytime soon (as Maxim mentioned, Apple's even developing a LSP interface for it.) Shameless plug: I’ve further developed Sylvester , a typed, XPC-available SourceKitten (SourceKit) interface with some sugar. The SKEditorOpen request should provide you with enough information to extract whatever you want from a source document.

  • XcodeKit exposes an extremely limited API to interacting with the source code. In fact, it only provides a mutable buffer of the open document in the editor that the user invoked the command from.

As for your inquiry on retrieving the currently open documents in the editor, your only option would be to use the wonderful scripting interface that Xcode exposes. The Xcode SDEF file can be found at /Applications/Xcode.app/Contents/Resources/Xcode.sdef. You can use the ScriptingBridge framework to do so from a Cocoa application. If you're using Swift, then the SwiftScripting repository is crucially helpful.



Related Topics



Leave a reply



Submit