Coc.nvim: How do I get coc.nvim working with Swift files?

Created on 16 Sep 2019  ยท  6Comments  ยท  Source: neoclide/coc.nvim

I have:

  • downloaded the XCode 11 beta (Version 11.0 beta 2 (11M337n))
  • Installed Swift v5.1 dev snapshot using swiftenv:
โฏ swift -v
Apple Swift version 5.1-dev (LLVM b47beb8a70, Swift 279ca888b5)
Target: x86_64-apple-darwin18.6.0
/Library/Developer/Toolchains/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-09-15-a.xctoolchain/usr/bin/lldb "--repl=-enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics"
Welcome to Apple Swift version 5.1-dev (LLVM b47beb8a70, Swift 279ca888b5)
  • Downloaded and built sourcekit-lsp:
~/dev/swift/test/test master*
โฏ which sourcekit-lsp
/Users/ben/.swiftenv/shims/sourcekit-lsp
  • set 'command line tools' version to xcode 11 in XCode > prefs > locations
    image

  • Added the following to coc-settings.json via :CocConfig

{
  "diagnostic.checkCurrentLine": true,
  "languageserver": {
    "swift": {
      "command": "sourcekit-lsp",
      "args": [],
      "filetypes": ["swift"],
      "initializationOptions": {},
      "settings": {
      }
    }
  }
}

Things _seem_ to work, but they kind of don't. Some examples:

func expands to nothing:
image

print doesn't evoke any completion options at all:

image

I also periodically see the following error in the status bar:

source languageserver.swift timeout after 2000ms

Do I have something configured incorrectly, or is this thing just not ready? Thanks.

All 6 comments

You can increase timeout for completion.

Can you tell me how to do that please?

Add "suggest.timeout": 5000 to coc-settings.json to increase.

That fixed the timeout errors, however, sourcekit-lsp doesn't seem to be working properly. I tried rebuilding and changed my config to the following:

{
  "diagnostic.checkCurrentLine": true,
  "suggest.timeout": 2000,
  "languageserver": {
    "swift": {
      "command": "/Users/ben/dev/GitHub/sourcekit-lsp/.build/x86_64-apple-macosx/debug/sourcekit-lsp",
      "args": [],
      "filetypes": ["swift"],
      "initializationOptions": {},
      "settings": {
      }
    }
  }
}

I also think it only works on projects that have been compiled with swift build. Think I'm gonna forget about this for now and come back when the sourcekit-lsp is more mature.

You can checkout verbose output from language server: https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel

So I updated my lsp config with "trace.server": "verbose" and if I view the logs with :CocCommand workspace.showOutput I see the following error:

[Trace - 2:59:42 PM] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "could not find manifest, or not a SwiftPM package: /Users/ben/dev/swift/test"
}

Looks like sourcekit-lsp doesn't work with XCode projects, because there is currently no way for it to understand XCode project files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lanox picture lanox  ยท  3Comments

cvlmtg picture cvlmtg  ยท  3Comments

FrankLA0203 picture FrankLA0203  ยท  3Comments

iago-lito picture iago-lito  ยท  3Comments

MaskRay picture MaskRay  ยท  3Comments