Way to increase retry threshold when sourcekit-lsp crashes?

sourcekit-lsp won’t restart if it crashes more than 5 times in the last 3 minutes. this forces me to Ctrl-Shift-P and reload the entire window to get syntax highlighting again. this happens every few minutes or so about every 30 seconds.

is there a way to increase the retry threshold, so i don’t have to keep restarting the entire editor?

There is no setting I know of that increases the number of attempts to start the LSP server.

Surely the more important question is why does your version of sourcekit-lsp keep crashing.

i wish i knew. recently i’ve been trying to record contexts where it was crashing and file them as issues. yesterday i filed #605.

anecdotally, i get the most crashes when:

  • using editable SPM packages
  • using code-completion
  • filling in the brackets of a subscript expression
  • modernizing pre-exclusivity (swift <= 3) code

but these are very general and probably not very helpful for fixing the crashes, which is why i have held off on reporting them until i can come up with more-reproducible test cases.

got another one: #606


and another one: #607

If you had time you could build your own version of sourcekit-lsp and use that in VS Code. There is a setting to set the sourcekit-lsp executable used. Then on macOS I used Xcode to attach to the version of sourcekit-lsp run by VSCode and then catch any crashes. I’ve done this in the past to diagnose issues.

I haven’t looked into attaching to processes using VSCode yet. I am meant to look into that this weekend though.

Actually attaching to a process is simple in VS Code. Add a launch.json config

{
    "type": "lldb",
    "request": "attach",
    "name": "Attach to Sourcekit-LSP",
    "program": "sourcekit-lsp",
    "pid": <process id>
}

To avoid attaching to the instance of sourcekit-lsp running when editing the SourceKit-LSP project you need to set the pid field to the process id for the correct version of sourcekit-lsp.

I have only tested this on macOS so far.

1 Like