Trying it out for Atom

I've been trying to hook this up for use with Atom, making use of Atom's atom-languageclient module.

I'm having limited success.

On Linux, I'm getting a lot of output like this:

logger.js:21 Swift (Swift IDE) stderr 2018-11-16 17:00:20.849 sourcekit-lsp[13596:50be9700] could not open compilation database for /home/sam/code/Sources/XPkg noEntry.

If I turn on the atom-languageclient verbose logging, it looks like it's sending requests to the daemon, but not getting anything back.

On the Mac, I'm getting a little further. Communication seems to be flowing in both directions, according to the atom-languageclient log output. However, I don't seem to be getting useful data back - eg for auto-completion the reply back from sourcekit-lsp is correctly formatting but doesn't offer any actual suggestions.

I am almost definitely holding it wrong, and it's quite likely that my mistake might relate to atom-languageclient rather than sourcekit-lsp.

That said, if anyone on the team has any ideas, or would be willing to try out the Atom plugin, that would be really helpful.

2 Likes

I should have said that I believe I'm using the correct toolchain - the November 1st one - on both platforms. The sourcekit-lsp executable is built with it, as is the code that I'm trying to view with Atom.

You can ignore this particular message. This is about support for compile_commands.json files, which are used for supporting e.g. a cmake project using clangd. I should change the logging of this probably.

If you run the service with environment SOURCEKIT_LOGGING=2 (or 3) does that give any additional hints for either the linux or mac issues?

I don't seem to be seeing any more logging output that way.

This is an example of the output I'm getting on the Mac:

Swift (sourcekit) rpc.sendRequest textDocument/completion sending {textDocument: {…}, position: {…}, context: {…}}context: {triggerKind: 2, triggerCharacter: "."}position: {line: 55, character: 7}textDocument: {uri: "file:///Users/sam/.local/share/xpkg/code/Sources/XPkgCommand/main.swift"}proto: Object
logger.js:33 Swift (sourcekit) rpc.onNotification (2) ["window/logMessage", {…}]
logger.js:33 Swift (sourcekit) rpc.sendRequest textDocument/completion received (7ms) {items: Array(0), isIncomplete: false}isIncomplete: falseitems: proto: Object
logger.js:33 Swift (sourcekit) rpc.onNotification (2) ["window/logMessage", {…}]

I do seem to be getting some indexing errors (warnings?) whilst building the thing that I'm trying to debug:

Linking ./.build/x86_64-apple-macosx10.10/debug/Configure
Compile Swift Module 'Arguments' (1 sources)
Index: Duplicate USR! s:9ArgumentsAAV7FailureO4nameSSvg
Index: Duplicate USR! s:9ArgumentsAAV7FailureO4nameSSvp
Index: Duplicate USR! s:9ArgumentsAAV7FailureO4nameSSvs

Compile Swift Module 'XPkg' (15 sources)
Index: Duplicate USR! s:4XPkgAAC7xpkgURL10Foundation0C0Vvg
Index: Duplicate USR! s:4XPkgAAC8vaultURL10Foundation0C0Vvg

Index: Duplicate USR! s:4XPkg7PackageC9installedSbvg

Compile Swift Module 'XPkgCommand' (2 sources)
Linking ./.build/x86_64-apple-macosx10.10/debug/xpkg

It does also look like the sourcekit-lsp process is logging some errors direct to the system console (bypassing the atom/web console), but they seem to be unreadable :frowning:

|error|16:00:23.242764 +0000|sourcekit-lsp|<private>|
|error|16:00:23.242852 +0000|sourcekit-lsp|<private>|
|error|16:00:23.242936 +0000|sourcekit-lsp|<private>|

These are benign and removed from later toolchain snapshots.

1 Like

The last NSHispter article talk about how to install lsp on vscode. Swift Development with Visual Studio Code - NSHipster

2 Likes

When we log to the system console we also send an LSP window/logMessage notification. I'm not sure how that's hooked up in Atom. Alternatively, if you're on macOS you can open Console.app and search for process:sourcekit-lsp before launching and it should capture any messages with warning/error level.

Yeah, those are coming through to the console in Atom/WebKit I think, but don't seem to have any obvious red flags in them explaining why I'm getting no completion suggestions.

I've recently fixed some issues when running the service on linux, you may want to give it another try there.

About failing to get code-completion on mac, I have some suggestions to help identify the issue:

  • Try to get the service working with Sublime Text. We know the service works properly with Sublime so the outcome of this will help steer the investigation, for example:
    • if you get code-completion working on Sublime it would seem the issue lies on the Atom side. Get the SOURCEKIT_LOGGING output from Sublime and compare it with Atom, are there differences ?
    • If code-completion is not working on Sublime as well, then it must be something unrelated to the editor, either on the service+toolchain side or possibly the project that you are trying it on. To reduce variables try it on a test project that you get via swift package init

I tried it out, and code completion and the outliner doesn’t seem to be working for me either. How do you view the logging output though?

btw I noticed you have to do

$ LD_LIBRARY_PATH= ... /swift/usr/lib/swift/linux
$ export LD_LIBRARY_PATH

before you start atom to get icu to link right,, if anyone was running into that. Seems to be a sourcekit-lsp issue though.

That sounds like SR-9251, which is not specific to sourcekit-lsp.