NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.02k stars 14.03k forks source link

`sourcekit-lsp` crashes when opening `.swift` files in VSCode #331943

Open thomaseizinger opened 2 months ago

thomaseizinger commented 2 months ago

Describe the bug

sourcekit-lsp crashes when opening .swift files with:

2024-08-03 18:01:29.517 sourcekit-lsp[56787:c4a006c0] failed to start language service open("/nix/store/h8gh9cg2z137ql7h1bgnhr9ixwcwj4az-swift-5.8/lib/libsourcekitdInProc.so: undefined symbol: _Z13OStream_write14BridgedOStreamN4llvm9StringRefE")

Steps To Reproduce

  1. Configure VSCode-swift with:
    userSettings = {
    "swift.path" = "${pkgs.swiftPackages.swift-unwrapped}/bin";
    "swift.sourcekit-lsp.serverPath" = "${pkgs.sourcekit-lsp}/bin/sourcekit-lsp";
    ];
  2. Open a .swift file in an editor

Expected behavior

Auto-complete and code analysis from the language server.

Additional context

A related bug is open on the Swift repository: https://github.com/swiftlang/swift/issues/67975

It hints that there might be a problem in how sourcekit-lsp gets built so I am opening this here. The suggestion there is that sourcekit-lsp should statically link against the above symbol.

The original issue I opened was: https://github.com/swiftlang/vscode-swift/issues/988. There the vscode-swift people are wondering why sourcekit-lsp is in a different package to begin with.

Notify maintainers

@dtzWill @trepetti @dduan @trundle @stephank

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.12, NixOS, 24.11 (Vicuna), 24.11.20240620.d603719`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - channels(root): `"home-manager-23.11.tar.gz, nixos-23.11, nixos-hardware"`
 - nixpkgs: `/nix/store/xfpiyfgf6y30fxk5ngv0cjn474qfr3sj-source`

Add a :+1: reaction to issues you find important.

nadevko commented 3 weeks ago

Same error.

Aug 3

Do you find any way to fix it?

shell.nix of project

{
  pkgs ? import <nixpkgs> { },
}:
with pkgs;
mkShell.override { inherit (swiftPackages) stdenv; } rec {
  vscode-settings = writeText "settings.json" (
    builtins.toJSON {
      "swift.path" = "${swiftPackages.swift-unwrapped}/bin";
      "swift.sourcekit-lsp.serverPath" = "${sourcekit-lsp}/bin/sourcekit-lsp";
      "lldb.library" = "${swiftPackages.swift-unwrapped}/lib/liblldb.so";
      "lldb.launch.expressions" = "native";
    }
  );

  packages = [
    swift
    swiftpm
    swift-corelibs-libdispatch
    swiftPackages.Foundation
    swiftPackages.Dispatch
  ];

  shellHook = ''
    LD_LIBRARY_PATH+=":${swift-corelibs-libdispatch}/lib";
    mkdir .vscode &>/dev/null
    cp --force ${vscode-settings} .vscode/settings.json
  '';
}

SourceKit Language Server logs from sswg.swift-lang VSCode extension (I use Codium)

2024-10-07 12:51:30.019 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.019 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.019 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.020 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.021 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.021 sourcekit-lsp[9338:3e0006c0] Could not determine host OS. Falling back to using '.so' as dynamic library extension
2024-10-07 12:51:30.193 sourcekit-lsp[9338:3e0006c0] [error]: Invalid manifest (compiled with: ["/nix/store/rh4jimyaclrhh04j0656a8gkxqsgk2k1-swift-5.8/bin/swiftc", "-vfsoverlay", "/tmp/TemporaryDirectory.SLww15/vfs.yaml", "-L", "/nix/store/rh4jimyaclrhh04j0656a8gkxqsgk2k1-swift-5.8/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/nix/store/rh4jimyaclrhh04j0656a8gkxqsgk2k1-swift-5.8/lib/swift/pm/ManifestAPI", "-swift-version", "5", "-I", "/nix/store/rh4jimyaclrhh04j0656a8gkxqsgk2k1-swift-5.8/lib/swift/pm/ManifestAPI", "-package-description-version", "5.8.0", "/home/nadevko/example/Package.swift", "-o", "/tmp/TemporaryDirectory.uYSWUf/example-manifest"])
<unknown>:0: warning: glibc not found for 'x86_64-pc-linux-gnu'; C stdlib may be unavailable
<unknown>:0: error: could not find module '_Concurrency' for target 'x86_64-pc-linux-gnu'; found: x86_64-unknown-linux-gnu, at: /nix/store/szbmx8gzg6fi977jbr5v3lg12b4j2x4v-swift-5.8-lib/lib/swift/linux/_Concurrency.swiftmodule
2024-10-07 12:51:30.194 sourcekit-lsp[9338:3e0006c0] failed to create SwiftPMWorkspace at /home/nadevko/example: the package does not contain a buildable target
2024-10-07 12:51:49.904 sourcekit-lsp[9338:360006c0] failed to start language service open("/nix/store/rh4jimyaclrhh04j0656a8gkxqsgk2k1-swift-5.8/lib/libsourcekitdInProc.so: undefined symbol: _Z13OStream_write14BridgedOStreamN4llvm9StringRefE")
[Info  - 12:59:32 PM] Connection to server got closed. Server will restart.
true
[Error - 12:59:32 PM] Server process exited with signal SIGILL.