sublimelsp / LSP-rust-analyzer

Convenience package for rust-analyzer
MIT License
69 stars 11 forks source link

LSP-rust-analyzer broken on NixOs #126

Open makemake-kbo opened 6 months ago

makemake-kbo commented 6 months ago

LSP-rust-analyzer is appears to be broken on NixOS.

I set up my rust environment in a nix-shell, with all the necessary tools including rust-analyzer. However, when launching sublime, I am met with this error: image

I'm attributing this to LSP-rust-analyzer downloading its own binary instead of using the one in PATH. Is there any way for this behavior to be changed?

predragnikolic commented 6 months ago

When you installed LSP-rust-analyzer, were there some installation errors in the Sublime Text console(ctrl+`) ? Can you remove and install LSP-rust-analyzer again and can check the console for errors?

I'm attributing this to LSP-rust-analyzer downloading its own binary instead of using the one in PATH. Is there any way for this behavior to be changed?

In LSP-rust-analyzer.sublime-settings, you can override the start command:

{
    "command": [
        "${storage_path}/LSP-rust-analyzer/rust-analyzer"  // change the path to your local rust-analyzer
    ],
}

But I would not recommend overriding the command because there is no guarantee that this LSP-rust-analyzer version is compatible with rust-analyzer you have locally, so you may run into a different issues somet

makemake-kbo commented 6 months ago

lsp-rust-analyzer does seem to start properly when uninstalling and installing with package control, but none of the LSP specific features work.

when starting sublime with the plugin installed i get this output in the console:

startup, version: 4152 linux x64 channel: stable
executable: /nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152/.sublime_text-wrapped
application: /nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152
working dir: /home/makemake/Documents/code/rust/blutgang
packages path: /home/makemake/.config/sublime-text/Packages
state path: /home/makemake/.config/sublime-text/Local
zip path: /nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152/Packages
zip path: /home/makemake/.config/sublime-text/Installed Packages
ignored_packages: ["Golang", "Rust", "Vintage"]
pre session restore time: 0.12342
startup time: 0.209015
git: located Sublime Merge installed at /opt/sublime_merge
git: using configuration from system git install
git: tracking working dir /home/makemake/Documents/code/rust/blutgang
first paint time: 0.256174
git: tracking working dir /home/makemake/Documents
reloading plugin Default.arithmetic
reloading plugin Default.auto_indent_tag
reloading plugin Default.block
reloading plugin Default.colors
reloading plugin Default.comment
reloading plugin Default.convert_color_scheme
reloading python 3.3 plugin HexViewer.hex_checksum
reloading plugin Default.convert_syntax
reloading plugin Default.copy_path
reloading plugin Default.echo
reloading plugin Default.exec
reloading python 3.3 plugin HexViewer.hex_common
reloading plugin Default.fold
reloading python 3.3 plugin HexViewer.hex_editor
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading python 3.3 plugin HexViewer.hex_finder
reloading python 3.3 plugin HexViewer.hex_highlighter
reloading plugin Default.html_print
reloading plugin Default.indentation
reloading python 3.3 plugin HexViewer.hex_inspector
reloading plugin Default.install_package_control
reloading python 3.3 plugin HexViewer.hex_notify
reloading python 3.3 plugin HexViewer.hex_viewer
reloading python 3.3 plugin HexViewer.hex_writer
reloading python 3.3 plugin HexViewer.sum_hashes
reloading python 3.3 plugin HexViewer.support
reloading python 3.3 plugin HexViewer.tiger
reloading python 3.3 plugin HexViewer.whirlpool
reloading python 3.3 plugin LSP-clangd.plugin
reloading plugin Default.keymap
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.profile
reloading plugin Default.quick_panel
reloading plugin Default.rename
reloading plugin Default.run_syntax_tests
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.settings
reloading plugin Default.show_scope_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.ui
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin Package Control.plugin
Package Control: oscrypto trust lists unavailable - libcrypto does not exist at /nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152/libcrypto.so.1.1
Package Control: OscryptoDownloader not available! libcrypto does not exist at /nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152/libcrypto.so.1.1
reloading python 3.3 plugin LSP-file-watcher-chokidar.watcher
reloading python 3.3 plugin LSP-rust-analyzer.plugin
reloading python 3.3 plugin LSP-rust-analyzer.plugin_commands
reloading python 3.3 plugin LSP-svelte.plugin
reloading python 3.3 plugin LSP.boot
reloading python 3.3 plugin Rust Enhanced.cargo_build
reloading python 3.3 plugin Rust Enhanced.SyntaxCheckPlugin
reloading python 3.3 plugin Rust Enhanced.toggle_setting
reloading python 3.3 plugin SideBarEnhancements.SideBar
reloading python 3.3 plugin SideBarEnhancements.SideBarAPI
reloading python 3.3 plugin SideBarEnhancements.SideBarDefaultDisable
reloading python 3.3 plugin SublimeLinter-clang.linter
reloading python 3.3 plugin SublimeLinter-golint.linter
reloading python 3.3 plugin SublimeLinter.__init__
reloading python 3.3 plugin SublimeLinter._init
reloading python 3.3 plugin SublimeLinter.active_linters_view
reloading python 3.3 plugin SublimeLinter.busy_indicator_view
reloading python 3.3 plugin SublimeLinter.goto_commands
reloading python 3.3 plugin SublimeLinter.highlight_view
reloading python 3.3 plugin SublimeLinter.log_handler
reloading python 3.3 plugin SublimeLinter.panel_view
reloading python 3.3 plugin SublimeLinter.quick_actions
reloading python 3.3 plugin SublimeLinter.status_bar_view
reloading python 3.3 plugin SublimeLinter.sublime_linter
reloading python 3.3 plugin Terminus.main
reloading python 3.3 plugin Tpl.tpl
reloading python 3.3 plugin ClangAutoComplete.ClangAutoComplete
reloading python 3.3 plugin EasyClangComplete.EasyClangComplete
plugins loaded
[ECC:INFO   ]: Getting version from command: `clang++ -v`
Traceback (most recent call last):
  File "/nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152/Lib/python33/sublime_plugin.py", line 528, in on_api_ready
    plc()
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/EasyClangComplete.py", line 88, in plugin_loaded
    handle_plugin_loaded_function()
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/EasyClangComplete.py", line 286, in on_plugin_loaded
    self.on_activated_async(sublime.active_window().active_view())
  File "/nix/store/iz3b5lci67wnp467acnnrmmfhhzp5c7l-sublimetext4-bin-4152/Lib/python33/sublime_plugin.py", line 190, in exception_handler
    return event_handler(*args)
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/EasyClangComplete.py", line 336, in on_activated_async
    settings = EasyClangComplete.settings_manager.settings_for_view(view)
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_manager.py", line 56, in settings_for_view
    self.__init_for_view(view)
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_manager.py", line 104, in __init_for_view
    self.__settings_dict[view_id].update_from_view(view)
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_storage.py", line 154, in update_from_view
    self.__update_wildcard_values(view)
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/plugin/settings/settings_storage.py", line 388, in __update_wildcard_values
    version_str = ClangUtils.get_clang_version_str(self.clang_binary)
  File "/home/makemake/.config/sublime-text/Packages/EasyClangComplete/plugin/utils/clang_utils.py", line 278, in get_clang_version_str
    if "Apple" in output_text:
TypeError: argument of type 'NoneType' is not iterable
Unable to start subprocess for rust-analyzer
Traceback (most recent call last):
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/windows.py", line 273, in start_async
    transport = create_transport(transport_config, transport_cwd, session)
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 265, in create_transport
    process = start_subprocess()
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 253, in start_subprocess
    return _start_subprocess(config.command, stdin, stdout, subprocess.PIPE, startupinfo, config.env, cwd)
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 339, in _start_subprocess
    cwd=cwd)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1452, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '/home/makemake/.cache/sublime-text/Package Storage/LSP-rust-analyzer/rust-analyzer'

Package Control: All specified packages up-to-date!
rchl commented 6 months ago

The first error is from EasyClangComplete. Maybe try removing/disabling it (LSP-clang should work better anyway) and then checking if that solves the problem.

makemake-kbo commented 6 months ago

heres the logs when starting sublime with it disabled:

Unable to start subprocess for rust-analyzer
Traceback (most recent call last):
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/windows.py", line 273, in start_async
    transport = create_transport(transport_config, transport_cwd, session)
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 265, in create_transport
    process = start_subprocess()
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 253, in start_subprocess
    return _start_subprocess(config.command, stdin, stdout, subprocess.PIPE, startupinfo, config.env, cwd)
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 339, in _start_subprocess
    cwd=cwd)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1452, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '/home/makemake/.cache/sublime-text/Package Storage/LSP-rust-analyzer/rust-analyzer'

Unable to start subprocess for rust-analyzer
Traceback (most recent call last):
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/windows.py", line 273, in start_async
    transport = create_transport(transport_config, transport_cwd, session)
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 265, in create_transport
    process = start_subprocess()
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 253, in start_subprocess
    return _start_subprocess(config.command, stdin, stdout, subprocess.PIPE, startupinfo, config.env, cwd)
  File "/home/makemake/.config/sublime-text/Installed Packages/LSP.sublime-package/plugin/core/transports.py", line 339, in _start_subprocess
    cwd=cwd)
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1452, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '/home/makemake/.cache/sublime-text/Package Storage/LSP-rust-analyzer/rust-analyzer'
predragnikolic commented 6 months ago

@makemake-kbo

Can you verify that this binary file exist /home/makemake/.cache/sublime-text/Package Storage/LSP-rust-analyzer/rust-analyzer ?

The file must exist if LSP-rust-analyzer installs successfully.

makemake-kbo commented 6 months ago

@predragnikolic looks like it is

file /home/makemake/.cache/sublime-text/Package\ Storage/LSP-rust-analyzer/rust-analyzer 
/home/makemake/.cache/sublime-text/Package Storage/LSP-rust-analyzer/rust-analyzer: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=4cb9801d931e886ce8110ee6af8892ce8c77f2c7, with debug_info, not stripped

ls -la /home/makemake/.cache/sublime-text/Package\ Storage/LSP-rust-analyzer/
total 43376
drwxr-xr-x 2 makemake users     4096 Feb 26 12:48 .
drwxrwxr-x 7 makemake users     4096 Feb 26 12:48 ..
-rwxr--r-- 1 makemake users 44402448 Feb 26 12:48 rust-analyzer
-rw-r--r-- 1 makemake users       10 Feb 26 12:48 VERSION
rchl commented 6 months ago

maybe related to permissions (the makemake user is not the one used when starting from ST)?

predragnikolic commented 6 months ago

Maybe found the cause:

https://nixos.wiki/wiki/Packaging/Binaries

Downloading and attempting to run a binary on NixOS will almost never work. This is due to hard-coded paths in the executable.

predragnikolic commented 6 months ago

Other editors faced the same issue in NixOS

https://discourse.nixos.org/t/nix-shell-and-rust-and-rust-analyzer/13940/2

I do not understand or know NixOS to suggest a solution to you.

makemake-kbo commented 6 months ago

Thank you all for the useful info! If i find a solution ill come back and post it.

jtojnar commented 4 months ago

On NixOS, you are generally expected to set up development environment through nix-shell (possibly autoloaded through https://github.com/misuzu/direnv-subl). Then you should be able to use:

{
    "command": ["rust-analyzer"],
}

Note: Currently, direnv-subl will not be visible to Sublime LSP 2.0 because the former still uses Python 3.3. You can clone the package and modify it as follows https://github.com/misuzu/direnv-subl/pull/3