Vercantez

Using SourceKit-LSP with Sublime

With the release of Xcode 11.4 beta, SourceKit-LSP now comes included with Xcode. This is a quick guide to get SourceKit-LSP working with Sublime Text.

First install Xcode 11.4 beta from Apple Developer. You might need to use xcode-select if you have an older version of Xcode installed.

sudo xcode-select -switch /Applications/Xcode-beta.app/

Then use Package Control to install "LSP"

Package Control: Install Package

Next you need to configure the LSP package to use SourceKit-LSP. Open the package's configuration.

Preferences: LSP Settings

This is the configuration that has worked best for me. Apple provides a good baseline in the SourceKit-LSP repository.


{
  "clients":
  {
    "SourceKit-LSP":
    {
      "command":
      [
        "xcrun",
        "sourcekit-lsp"
      ],
      "enabled": true,
      "env":
      {
      },
      "languages":
      [
        {
          "languageId": "swift",
          "scopes":
          [
            "source.swift"
          ],
          "syntaxes":
          [
            "Packages/Swift/Syntaxes/Swift.tmLanguage",
            "Packages/Decent Swift Syntax/Swift.sublime-syntax"
          ]
        },
        {
          "languageId": "c",
          "scopes":
          [
            "source.c"
          ],
          "syntaxes":
          [
            "Packages/C++/C.sublime-syntax"
          ]
        },
        {
          "languageId": "cpp",
          "scopes":
          [
            "source.c++"
          ],
          "syntaxes":
          [
            "Packages/C++/C++.sublime-syntax"
          ]
        },
        {
          "languageId": "objective-c",
          "scopes":
          [
            "source.objc"
          ],
          "syntaxes":
          [
            "Packages/Objective-C/Objective-C.sublime-syntax"
          ]
        },
        {
          "languageId": "objective-cpp",
          "scopes":
          [
            "source.objc++"
          ],
          "syntaxes":
          [
            "Packages/Objective-C/Objective-C++.sublime-syntax"
          ]
        }
      ]
    }
  },
  "complete_all_chars": true,
  "log_debug": true,
  "log_payloads": true,
  "log_stderr": true,
  "only_show_lsp_completions": true
  }
}

Build the project using `swift build` or by building it in Xcode before opening the project in Sublime. Enjoy! P.S. In my experience, SourceKit-LSP will sometimes crash and stop working until I rebuild the project.
Tagged with: