# New LSP language service supporting Swift and C-family languages for any editor and platform

**URL:** <https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024>\
**Category:** Announcements\
**Created:** [October 15, 2018, 9:00pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024 "2018-10-15T21:00:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![akyrtzi](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/akyrtzi/32/4963_2.png) [@akyrtzi](https://forums.swift.org/u/akyrtzi)\
**Post date:** [October 15, 2018, 9:00pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/1 "2018-10-15T21:00:50Z")

</div>

Hey all,

At Apple we are making it a priority to support high-quality tooling for all Swift developers, including those working on non-Apple platforms. We want to collaborate with the open-source community and focus our efforts on building common infrastructure that can be shared by Xcode and other editors and platforms.

To that end, I'm excited to announce that we are going to start a new open-source project for a Swift and C-family language service based on the [Language Server Protocol](https://microsoft.github.io/language-server-protocol). We've chosen to adopt LSP so we can benefit from its active community and wide adoption across other editors and platforms. This means that Visual Studio Code, Atom, Sublime Text, or whatever your favorite editor happens to be, can use the same service as Xcode, and any improvements we make to the service will benefit them all.

This new LSP-based language service will support:

- Semantic functionality for Swift source files (code-completion, highlighting, etc.).
- Semantic functionality for C/C++/ObjC files.
- Cross-language indexing functionality, including but not limited to:
  - Jump-to-definition
  - Call-hierarchy
  - Search-symbols

- Cross-language refactoring functionality, like global rename.

We are also going to make the necessary changes for Xcode to use this new LSP-based language service. Similar to how you can load an [OSS toolchain](https://swift.org/download/#snapshots) in Xcode to try it out now, in the future you will be able to load a build of the OSS LSP service in your installed Xcode and test any fixes or enhancements you make.

We will try to stick to the common set of LSP requests, but for functionality in Xcode that is not currently supported by LSP, we will add extensions to the protocol. If these extensions can be generally useful for other editors as well, we will propose adding them to the LSP specification.

Given that we want to offer first-class support for other editors and platforms, we will aim for the new LSP service to have great support for SwiftPM projects. We will also be open to contributions for supporting other systems as well, like Bazel.

We should have a project repository up within a month, and in the meantime I'd be happy to hear any feedback or questions you may have!

---

<div class="post-metadata">

**Author:** ![duan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/duan/32/40252_2.png) [@duan](https://forums.swift.org/u/duan)\
**Post date:** [October 15, 2018, 9:39pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/2 "2018-10-15T21:39:09Z")

</div>

As a daily Swift + Vim user I'm super excited to see things moving in this direction. To that end I have a couple of questions on the technical side:

1. What would the relationship between this new project (we need an official name for it 😉) and SourceKit, when it comes to syntax highlighting? Is SwiftSyntax part of it?

2. For indexing/code completion/jump-to-definition: will this project replace Xcode's current implementation, or exist in parallel?

---

<div class="post-metadata">

**Author:** ![Daniel\_Martin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/daniel_martin/32/4130_2.png) [@Daniel\_Martin](https://forums.swift.org/u/Daniel_Martin)\
**Post date:** [October 15, 2018, 9:44pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/3 "2018-10-15T21:44:26Z")

</div>

Oh, that's great! I was starting to develop a Swift LSP server myself, but I'd probably contribute to this project instead.

One question I have is about the C/C++/ObjC part of this project. How will this project fit with clangd, which is already part of the Clang repository? Are you going to reuse code, start from scratch...?

---

<div class="post-metadata">

**Author:** ![Jens](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jens/32/12903_2.png) [@Jens](https://forums.swift.org/u/Jens)\
**Post date:** [October 15, 2018, 9:45pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/4 "2018-10-15T21:45:58Z")

</div>

Could this (among other more important things) also (finally) bring an improvement to Xcode's automatic indentation with it?

> **An example**
>
> Here's what it currently thinks this code should be indented like (even if you try to Editor -\> Structure -\> Re-Indent):
> 
> ```swift
> func f(_ v: Int) -> Int {
> guard
> v > 0
> else {
> return 0
> }
> let x = "abc" +
> "def"
> let y =
> 123
> return x.count + y +
> v
> }
> 
> ```
> 
> I think most people would expect:
> 
> ```swift
> func f(_ v: Int) -> Int {
> guard
> v > 0
> else {
> return 0
> }
> let x = "abc" +
> "def"
> let y =
> 123
> return x.count + y +
> v
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [October 15, 2018, 9:50pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/5 "2018-10-15T21:50:46Z")

</div>

> [@duan](#):
>
> What would the relationship between this new project (we need an official name for it 😉) and SourceKit, when it comes to syntax highlighting? Is SwiftSyntax part of it?

The LSP service will use sourcekitd to get its swift-specific support - ie. highlighting, code-completion, etc. I'd love to use libSyntax to implement syntactic highlighting, but that would be an implementation detail. I expect we will add an (extension) API to provide the syntax tree though.

> [@duan](#):
>
> For indexing/code completion/jump-to-definition: will this project replace Xcode's current implementation, or exist in parallel?

The intention is for this project to supercede the indexer we have today when it's ready.

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [October 15, 2018, 9:54pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/6 "2018-10-15T21:54:23Z")

</div>

> [@Daniel\_Martin](#):
>
> How will this project fit with clangd, which is already part of the Clang repository?

Our service will use clangd 😄 The idea is that we will load clangd + sourcekitd from a toolchain to provide the language-specific functionality for e.g. code-completion.

---

<div class="post-metadata">

**Author:** ![blangmuir](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/blangmuir/32/277_2.png) [@blangmuir](https://forums.swift.org/u/blangmuir)\
**Post date:** [October 15, 2018, 9:56pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/7 "2018-10-15T21:56:43Z")

</div>

> [@Jens](#):
>
> Could this (among other more important things) also (finally) bring an improvement to Xcode's automatic indentation with it?

This should be fixable regardless of whether it's in the new service or not. Have you filed a bug for this one?

---

<div class="post-metadata">

**Author:** ![akyrtzi](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/akyrtzi/32/4963_2.png) [@akyrtzi](https://forums.swift.org/u/akyrtzi)\
**Post date:** [October 15, 2018, 10:35pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/8 "2018-10-15T22:35:40Z")

</div>

> [@duan](#):
>
> Is SwiftSyntax part of it?

To add to what Ben mentioned, the new service will be written in Swift so it could use SwiftSyntax and any other functionality written on top of SwiftSyntax, like formatting.

---

<div class="post-metadata">

**Author:** ![gmittertreiner](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gmittertreiner/32/19651_2.png) [@gmittertreiner](https://forums.swift.org/u/gmittertreiner)\
**Post date:** [October 16, 2018, 12:00am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/9 "2018-10-16T00:00:08Z")

</div>

This is excellent! I had started implementing exactly this out of necessity at work for my team (DevX related tools at Facebook), but it seems like a good idea to join efforts.

How far along is the project right now? Would you mind us being included in some design talks? This aligns closely with a number of goals we have. We'd definitely be interested in spending time contributing to this as soon as possible. Would someone by chance be at the LLVM meeting this week?

---

<div class="post-metadata">

**Author:** ![akyrtzi](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/akyrtzi/32/4963_2.png) [@akyrtzi](https://forums.swift.org/u/akyrtzi)\
**Post date:** [October 16, 2018, 12:42am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/10 "2018-10-16T00:42:00Z")

</div>

> [@gmittertreiner](#):
>
> Would someone by chance be at the LLVM meeting this week?

I will be there, along with @blangmuir and @Nathan_Hawes. Jason, I've sent you a direct message. If anyone else will be at LLVM Dev meeting, and wants to chat about the LSP service, send me a message.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [October 16, 2018, 12:51am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/11 "2018-10-16T00:51:36Z")

</div>

Google is also very interested in contributing, as we've done a fair amount of work in this area to meet some of our internal needs (Bazel support is a big one for us, but general functionality as well). We're excited to see this moving forward!

---

<div class="post-metadata">

**Author:** ![DevAndArtist](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/devandartist/32/287_2.png) [@DevAndArtist](https://forums.swift.org/u/DevAndArtist)\
**Post date:** [October 16, 2018, 4:48am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/12 "2018-10-16T04:48:50Z")

</div>

I‘m thrilled by this announcement. You mentioned that this project itself will use Swift as its main language. Which coding style will the project follow? I‘d like to note that I really like the consistent way Swift code is written in stdlib compared to the inconsistent corelibs repo.

---

<div class="post-metadata">

**Author:** ![beefon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/beefon/32/13391_2.png) [@beefon](https://forums.swift.org/u/beefon)\
**Post date:** [October 16, 2018, 5:31am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/13 "2018-10-16T05:31:24Z")

</div>

This is great. I wonder how LSP could help build systems like Bazel and Buck? Could you provide any example of the feature that can be added into the build systems? Will LSP somehow improve llbuild?

---

<div class="post-metadata">

**Author:** ![samdeane](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/samdeane/32/2175_2.png) [@samdeane](https://forums.swift.org/u/samdeane)\
**Post date:** [October 16, 2018, 10:31am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/14 "2018-10-16T10:31:59Z")

</div>

This is great news.

I've been distracted from the [atom integration](https://github.com/elegantchaos/atom-ide-swift) that I was attempting, but this development should help to nudge me back into working on it.

---

<div class="post-metadata">

**Author:** ![ankit\_goel](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ankit_goel/32/2420_2.png) [@ankit\_goel](https://forums.swift.org/u/ankit_goel)\
**Post date:** [October 16, 2018, 10:42am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/15 "2018-10-16T10:42:50Z")

</div>

I am very interested in contributing to this. Can't wait for the repo to be up!

---

<div class="post-metadata">

**Author:** ![RUSshy](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@RUSshy](https://forums.swift.org/u/RUSshy)\
**Post date:** [October 16, 2018, 11:51am UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/16 "2018-10-16T11:51:53Z")

</div>

Thanks a lot !! This is big news !

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/matklad/32/4991_2.png) [@matklad](https://forums.swift.org/u/matklad)\
**Post date:** [October 16, 2018, 1:06pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/17 "2018-10-16T13:06:25Z")

</div>

> [@blangmuir](#):
>
> I'd love to use libSyntax to implement syntactic highlighting, but that would be an implementation detail.

👍, libSyntax would be an awesome foundation for close-to-concrete-syntax IDE features

> we will add extensions to the protocol.

You might want to take a look at the [Dart's protocol](https://htmlpreview.github.io/?https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/doc/api.html) for inspiration, it seems to handle some stuff better than LSP.

---

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [October 16, 2018, 1:23pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/18 "2018-10-16T13:23:22Z")

</div>

> [@beefon](#):
>
> This is great. I wonder how LSP could help build systems like Bazel and Buck? Could you provide any example of the feature that can be added into the build systems?

The general idea is that a language server needs to know the compilation commands that are used to build the modules used by a project (SourceKit does as well), for things like inter-module dependencies or taking the right branch of `#if` blocks based on the `-D` flags or target machine, and so forth. Since SwiftPM describes its build in one way and Bazel describes it in a different way, the LS needs to understand how to get that information from those systems.

So for example, if you had a VS Code workspace open and the LS detected that you had a typical SwiftPM directory structure, it could ask SwiftPM to provide those flags. If it detected that the project was a Bazel workspace structure, it could ask Bazel instead, and so forth.

---

<div class="post-metadata">

**Author:** ![slinberg](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@slinberg](https://forums.swift.org/u/slinberg)\
**Post date:** [October 16, 2018, 1:53pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/19 "2018-10-16T13:53:33Z")

</div>

> At Apple we are making it a priority to support high-quality tooling for all Swift developers, including those working on non-Apple platforms

Super. Any progress on non-Ubuntu Linux, like RHEL or CentOS? "yum install swift-dev"?

---

<div class="post-metadata">

**Author:** ![Schniz](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/schniz/32/4984_2.png) [@Schniz](https://forums.swift.org/u/Schniz)\
**Post date:** [October 16, 2018, 2:26pm UTC](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024/20 "2018-10-16T14:26:53Z")

</div>

Hey @duan, maybe unrelated to the thread, but can you share with me your vim & swift configuration?  
I wonder if I can be happy in Vim in Swift like I am with any other language 😸

Are you doing it for backend/cli dev or for iOS/macOS/tvOS development?

[Next page](https://forums.swift.org/t/new-lsp-language-service-supporting-swift-and-c-family-languages-for-any-editor-and-platform/17024.md?page=2)
