Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceKit Language Server server crashes #635

Closed
LazyOtto opened this issue Sep 17, 2022 · 9 comments
Closed

SourceKit Language Server server crashes #635

LazyOtto opened this issue Sep 17, 2022 · 9 comments

Comments

@LazyOtto
Copy link

Repeatable crash when used with VSCode on Linux Mint.
Installed with: swift-5.7-RELEASE-ubuntu22.04.tar.gz
Code to cause it to crash - second line below:

var someInts: [Int] = []
someInts.append()
// someInts.append(contentsOf: [5, 7, 9])
print("An array of \(someInts)) with count of: \(someInts.count)")

Stack trace of thread 29377:
#0 0x0000555b412ae48e n/a (/home/user/Applications/swift-5.7-RELEASE-ubuntu22.04/usr/bin/sourcekit-lsp + 0x9e648e)

Core was generated by `sourcekit-lsp'.
Program terminated with signal SIGILL, Illegal instruction.
#0  Swift runtime failure: precondition failure () at /home/build-user/sourcekit-lsp/Sources/SourceKitLSP/Swift/Diagnostic.swift:83
83	/home/build-user/sourcekit-lsp/Sources/SourceKitLSP/Swift/Diagnostic.swift: No such file or directory.
[Current thread is 1 (Thread 0x7f2b92cf7640 (LWP 29377))]
@LazyOtto
Copy link
Author

I replaced the precondition check in "fixitTitle" as below. Have not run any suite of tests on the patch other than the case which I stumbled upon above.

  public static func fixitTitle(replace oldText: String, with newText: String) -> String {
    switch (oldText.isEmpty, newText.isEmpty) {
    case (false, false):
      return "Replace '\(oldText)' with '\(newText)'"
    case (false, true):
      return "Remove '\(oldText)'"
    case (true, false):
      return "Insert '\(newText)'"
    case (true, true):
      // preconditionFailure("FixIt makes no changes")
      log("FixIt makes no changes", level: .warning)
      return ""
    }
  }

@LazyOtto
Copy link
Author

Tests supplied with the package pass:

Test Suite 'All tests' passed at 2022-09-17 10:22:47.836
Executed 249 tests, with 4 tests skipped and 0 failures (0 unexpected) in 32.119 (32.119) seconds

@ahoppen
Copy link
Collaborator

ahoppen commented Sep 20, 2022

rdar://100158700

@ahoppen
Copy link
Collaborator

ahoppen commented Sep 20, 2022

I suspect you are using an editor that has snippets disabled, in which case this issue should be fixed by #602.

To verify that this is indeed the case could you:

  • Check if this issue still happens with a recent main development snapshot.
  • Check if snippets are enabled in your VSCode
    • In VSCode open the Output windows (Command Palette -> Output: Focus on Output View) -> select SourceKit Language Server and paste the initialize request here (should be the first 500-ish lines). I suspect that it has snippetSupport set to false.

@LazyOtto
Copy link
Author

I will try the suggested test later.

More information for now, editor/VSCode version in use is:

Version: 1.71.2
Commit: 74b1f979648cc44d385a2286793c226e611f59e7
Date: 2022-09-14T21:12:14.256Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Linux x64 5.15.0-47-generic
Sandboxed: No

Searching on "snippets" in Settings shows seven relevant hits. (Four for "Text Editor" and three for "Emmet".)

All are enabled except "Extensions:Emmet Show Suggestions as Snippets".

@LazyOtto
Copy link
Author

And I don't know if "Emmet" is actually relevant. Researching WTH that is now.

@adam-fowler
Copy link
Contributor

Hi guys,
I can replicate this issue, and I have snippetSupport set to true. Also I have reduce the amount of text you need to get the crash to

var a: [Int] = []
a.append()

This does appear to be fixed on main. If we could bring what fixed it across to the 5.7 branch that would be great. The above code seems pretty common place.

@ahoppen
Copy link
Collaborator

ahoppen commented Oct 7, 2022

Ah, I see what’s happening now. We disable snippet support when translating the insertion response for code completion (because LSP doesn’t support snippets for code completion). I opened a PR to get this fixed in 5.7 but can’t make any promises when this will end up in a toolchain release. #646

@ahoppen ahoppen closed this as completed Oct 26, 2022
@ahoppen
Copy link
Collaborator

ahoppen commented Oct 26, 2022

I merged the fix into release/5.7. The next release should contain the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants