rustic icon indicating copy to clipboard operation
rustic copied to clipboard

Re-add rustic mode based on rustic-ts (Treesitter support)

Open psibi opened this issue 1 year ago • 16 comments

This code is based on https://github.com/brotzeit/rustic/pull/480, but there are some changes based on my testing.

psibi avatar Aug 18 '23 15:08 psibi

Hi, following the config from README, I got errors like

Debugger entered--Lisp error: (error "Recursive load" "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti..." "/Users/User/.emacs.d/elpaca/builds/rustic/rusti...")
  require(rustic-ts-mode)
  activate-rustic-mode()
  byte-code("\300 \210\301\302\303\"\207" [activate-rustic-mode add-to-list auto-mode-alist ("\\.rs\\'" . rustic-mode)] 3)
  require(rustic)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312\305\312\313&\7\210\314\315\316\317\320DD\321\322\323\312\307&\7\210\314\324\316\317..." [require markdown-mode xterm-color s compile rustic custom-declare-group rustic-compilation nil "Rust Compilation." :group processes custom-declare-variable rustic-compile-command funcall function #f(compiled-function () #<bytecode 0x2f1ad4735795041>) "Default command for rust compilation." :type string rustic-compile-command-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Default command for remote rust compilation."] 8)
  require(rustic-compile)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312DD\313\314\315\316\317&\7\210\306\320\310\311\321DD\322\314\315\316\317&\7\210..." [require tabulated-list dash s rustic-compile rustic-interaction custom-declare-variable rustic-cargo-bin funcall function #f(compiled-function () #<bytecode 0x198009ffb0f94>) "Path to cargo executable." :type string :group rustic-cargo rustic-cargo-check-exec-command #f(compiled-function () #<bytecode 0x198009f7b5d94>) "Execute command to run cargo check." rustic-cargo-test-exec-command #f(compiled-function () #<bytecode 0x198000f33ec94>) "Execute command to run cargo test." rustic-cargo-nextest-exec-command #f(compiled-function () #<bytecode -0x6bfbc0fe6c97501>) "Execute command to run nextest." rustic-cargo-run-exec-command #f(compiled-function () #<bytecode 0x1980001bb2754>) "Execute command to run cargo run." rustic-cargo-build-exec-command #f(compiled-function () #<bytecode 0x198009f623694>) "Execute command to run cargo build." rustic-cargo-bin-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Path to remote cargo executable."] 8)
  require(rustic-cargo)
  byte-code("\300\301!\210\300\302!\210\303\304\305\306\307DD\310\311\312\313\314&\7\210\303\315\305\306\316DD\317\311\312\313\314&\7\207" [require project rustic-cargo custom-declare-variable rustic-rustfmt-bin funcall function #f(compiled-function () #<bytecode 0x198de82e58f14>) "Path to rustfmt executable." :type string :group rustic rustic-rustfmt-bin-remote #f(compiled-function () #<bytecode -0x139670276a5ac521>) "Path to remote rustfmt executable."] 8)
  require(rustic-rustfmt)
  require(rustic-ts-mode)
  activate-rustic-mode()
  byte-code("\300 \210\301\302\303\"\207" [activate-rustic-mode add-to-list auto-mode-alist ("\\.rs\\'" . rustic-mode)] 3)
  require(rustic)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312\305\312\313&\7\210\314\315\316\317\320DD\321\322\323\312\307&\7\210\314\324\316\317..." [require markdown-mode xterm-color s compile rustic custom-declare-group rustic-compilation nil "Rust Compilation." :group processes custom-declare-variable rustic-compile-command funcall function #f(compiled-function () #<bytecode 0x2f1ad4735795041>) "Default command for rust compilation." :type string rustic-compile-command-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Default command for remote rust compilation."] 8)
  require(rustic-compile)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312DD\313\314\315\316\317&\7\210\306\320\310\311\321DD\322\314\315\316\317&\7\210..." [require tabulated-list dash s rustic-compile rustic-interaction custom-declare-variable rustic-cargo-bin funcall function #f(compiled-function () #<bytecode 0x198009ffb0f94>) "Path to cargo executable." :type string :group rustic-cargo rustic-cargo-check-exec-command #f(compiled-function () #<bytecode 0x198009f7b5d94>) "Execute command to run cargo check." rustic-cargo-test-exec-command #f(compiled-function () #<bytecode 0x198000f33ec94>) "Execute command to run cargo test." rustic-cargo-nextest-exec-command #f(compiled-function () #<bytecode -0x6bfbc0fe6c97501>) "Execute command to run nextest." rustic-cargo-run-exec-command #f(compiled-function () #<bytecode 0x1980001bb2754>) "Execute command to run cargo run." rustic-cargo-build-exec-command #f(compiled-function () #<bytecode 0x198009f623694>) "Execute command to run cargo build." rustic-cargo-bin-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Path to remote cargo executable."] 8)
  require(rustic-cargo)
  byte-code("\300\301!\210\300\302!\210\303\304\305\306\307DD\310\311\312\313\314&\7\210\303\315\305\306\316DD\317\311\312\313\314&\7\207" [require project rustic-cargo custom-declare-variable rustic-rustfmt-bin funcall function #f(compiled-function () #<bytecode 0x198de82e58f14>) "Path to rustfmt executable." :type string :group rustic rustic-rustfmt-bin-remote #f(compiled-function () #<bytecode -0x139670276a5ac521>) "Path to remote rustfmt executable."] 8)
  require(rustic-rustfmt)
  require(rustic-ts-mode)
  activate-rustic-mode()
  byte-code("\300 \210\301\302\303\"\207" [activate-rustic-mode add-to-list auto-mode-alist ("\\.rs\\'" . rustic-mode)] 3)
  require(rustic)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312\305\312\313&\7\210\314\315\316\317\320DD\321\322\323\312\307&\7\210\314\324\316\317..." [require markdown-mode xterm-color s compile rustic custom-declare-group rustic-compilation nil "Rust Compilation." :group processes custom-declare-variable rustic-compile-command funcall function #f(compiled-function () #<bytecode 0x2f1ad4735795041>) "Default command for rust compilation." :type string rustic-compile-command-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Default command for remote rust compilation."] 8)
  require(rustic-compile)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312DD\313\314\315\316\317&\7\210\306\320\310\311\321DD\322\314\315\316\317&\7\210..." [require tabulated-list dash s rustic-compile rustic-interaction custom-declare-variable rustic-cargo-bin funcall function #f(compiled-function () #<bytecode 0x198009ffb0f94>) "Path to cargo executable." :type string :group rustic-cargo rustic-cargo-check-exec-command #f(compiled-function () #<bytecode 0x198009f7b5d94>) "Execute command to run cargo check." rustic-cargo-test-exec-command #f(compiled-function () #<bytecode 0x198000f33ec94>) "Execute command to run cargo test." rustic-cargo-nextest-exec-command #f(compiled-function () #<bytecode -0x6bfbc0fe6c97501>) "Execute command to run nextest." rustic-cargo-run-exec-command #f(compiled-function () #<bytecode 0x1980001bb2754>) "Execute command to run cargo run." rustic-cargo-build-exec-command #f(compiled-function () #<bytecode 0x198009f623694>) "Execute command to run cargo build." rustic-cargo-bin-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Path to remote cargo executable."] 8)
  require(rustic-cargo)
  byte-code("\300\301!\210\300\302!\210\303\304\305\306\307DD\310\311\312\313\314&\7\210\303\315\305\306\316DD\317\311\312\313\314&\7\207" [require project rustic-cargo custom-declare-variable rustic-rustfmt-bin funcall function #f(compiled-function () #<bytecode 0x198de82e58f14>) "Path to rustfmt executable." :type string :group rustic rustic-rustfmt-bin-remote #f(compiled-function () #<bytecode -0x139670276a5ac521>) "Path to remote rustfmt executable."] 8)
  require(rustic-rustfmt)
  require(rustic-ts-mode)
  activate-rustic-mode()
  byte-code("\300 \210\301\302\303\"\207" [activate-rustic-mode add-to-list auto-mode-alist ("\\.rs\\'" . rustic-mode)] 3)
  require(rustic)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312\305\312\313&\7\210\314\315\316\317\320DD\321\322\323\312\307&\7\210\314\324\316\317..." [require markdown-mode xterm-color s compile rustic custom-declare-group rustic-compilation nil "Rust Compilation." :group processes custom-declare-variable rustic-compile-command funcall function #f(compiled-function () #<bytecode 0x2f1ad4735795041>) "Default command for rust compilation." :type string rustic-compile-command-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Default command for remote rust compilation."] 8)
  require(rustic-compile)
  byte-code("\300\301!\210\300\302!\210\300\303!\210\300\304!\210\300\305!\210\306\307\310\311\312DD\313\314\315\316\317&\7\210\306\320\310\311\321DD\322\314\315\316\317&\7\210..." [require tabulated-list dash s rustic-compile rustic-interaction custom-declare-variable rustic-cargo-bin funcall function #f(compiled-function () #<bytecode 0x198009ffb0f94>) "Path to cargo executable." :type string :group rustic-cargo rustic-cargo-check-exec-command #f(compiled-function () #<bytecode 0x198009f7b5d94>) "Execute command to run cargo check." rustic-cargo-test-exec-command #f(compiled-function () #<bytecode 0x198000f33ec94>) "Execute command to run cargo test." rustic-cargo-nextest-exec-command #f(compiled-function () #<bytecode -0x6bfbc0fe6c97501>) "Execute command to run nextest." rustic-cargo-run-exec-command #f(compiled-function () #<bytecode 0x1980001bb2754>) "Execute command to run cargo run." rustic-cargo-build-exec-command #f(compiled-function () #<bytecode 0x198009f623694>) "Execute command to run cargo build." rustic-cargo-bin-remote #f(compiled-function () #<bytecode -0x1c50db2b56583d6d>) "Path to remote cargo executable."] 8)
  require(rustic-cargo)
  byte-code("\300\301!\210\300\302!\210\303\304\305\306\307DD\310\311\312\313\314&\7\210\303\315\305\306\316DD\317\311\312\313\314&\7\207" [require project rustic-cargo custom-declare-variable rustic-rustfmt-bin funcall function #f(compiled-function () #<bytecode 0x198de82e58f14>) "Path to rustfmt executable." :type string :group rustic rustic-rustfmt-bin-remote #f(compiled-function () #<bytecode -0x139670276a5ac521>) "Path to remote rustfmt executable."] 8)
  require(rustic-rustfmt)
  rustic-mode()
  set-auto-mode-0(rustic-mode nil)
  set-auto-mode--apply-alist((("\\.http\\'" . restclient-mode) ("\\.\\(phtml\\|php|[gj]sp\\|as[cp]x\\|erb\\|djhtml\\|html?..." . web-mode) ("/README\\(?:\\.md\\)?\\'" . gfm-mode) ("\\.rs\\'" . rustic-mode) ("\\.\\(?:md\\|markdown\\|mkd\\|mdown\\|mkdn\\|mdwn\\)\\'" . markdown-mode) ("\\.rs\\'" . rust-mode) ("\\.ipynb\\'" . code-cells-convert-ipynb) ("requirements\\.in" . pip-requirements-mode) ("requirements[^z-a]*\\.txt\\'" . pip-requirements-mode) ("\\.pip\\'" . pip-requirements-mode) ("\\.pxi\\'" . cython-mode) ("\\.pxd\\'" . cython-mode) ("\\.pyx\\'" . cython-mode) ("\\.tsv\\'" . tsv-mode) ("\\.[Cc][Ss][Vv]\\'" . csv-mode) ("\\.proto\\'" . protobuf-mode) ("/Cask\\'" . cask-mode) ("\\.editorconfig\\'" . editorconfig-conf-mode) ("/git/ignore\\'" . gitignore-mode) ("/info/exclude\\'" . gitignore-mode) ("/\\.gitignore\\'" . gitignore-mode) ("/etc/gitconfig\\'" . gitconfig-mode) ("/\\.gitmodules\\'" . gitconfig-mode) ("/git/config\\'" . gitconfig-mode) ("/modules/.*/config\\'" . gitconfig-mode) ("/\\.git/config\\'" . gitconfig-mode) ("/\\.gitconfig\\'" . gitconfig-mode) ("/git/attributes\\'" . gitattributes-mode) ("/info/attributes\\'" . gitattributes-mode) ("/\\.gitattributes\\'" . gitattributes-mode) ("/git-rebase-todo\\'" . git-rebase-mode) ("\\.hva\\'" . latex-mode) ("\\.envrc\\'" . envrc-file-mode) ("\\.sh$\\|\\.bash\\|\\.profile" . sh-mode) ("Cargo\\.lock" . toml-ts-mode) ("\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'" nil epa-file) ("\\.elc\\'" . elisp-byte-code-mode) ("\\.\\(?:3fr\\|arw\\|bmp\\|cr[2w]\\|d\\(?:cr\\|ds\\|ng\\)\\|ex..." . image-mode) ("\\.zst\\'" nil jka-compr) ("\\.dz\\'" nil jka-compr) ("\\.xz\\'" nil jka-compr) ("\\.lzma\\'" nil jka-compr) ("\\.lz\\'" nil jka-compr) ("\\.g?z\\'" nil jka-compr) ("\\.bz2\\'" nil jka-compr) ("\\.Z\\'" nil jka-compr) ("\\.vr[hi]?\\'" . vera-mode) ("\\(?:\\.\\(?:rbw?\\|ru\\|rake\\|thor\\|jbuilder\\|rabl\\|ge..." . ruby-mode) ("\\.re?st\\'" . rst-mode) ("\\.py[iw]?\\'" . python-mode) ...) nil nil)
  set-auto-mode()
  normal-mode(t)
  after-find-file(nil t)
  find-file-noselect-1(#<buffer backup_links.rs> "~/git/rust/cabinet/src/bin/backup_links.rs" nil nil "~/git/rust/cabinet/src/bin/backup_links.rs" (246753266 16777220))
  find-file-noselect("~/git/rust/cabinet/src/bin/backup_links.rs" nil nil nil)
  find-file("~/git/rust/cabinet/src/bin/backup_links.rs")
  consult-recent-file()
  funcall-interactively(consult-recent-file)
  call-interactively(consult-recent-file nil nil)
  command-execute(consult-recent-file)

failable avatar Aug 18 '23 15:08 failable

@liebkne Can you clean your eln-cache and the old package, and then restart your emacs. I believe this is the clean up command:

rm -rf ~/.emacs.d/eln-cache/
rm -rf ~/.emacs.d/elpa/rustic-*

psibi avatar Aug 18 '23 15:08 psibi

I've tried. I don't have native compile enabled and I manually delete all the *.elc and restart, but the issue still exists.

failable avatar Aug 18 '23 15:08 failable

@liebkne Hmm, interesting. Can you show me the entire rustic configuration that you are using ?

psibi avatar Aug 18 '23 15:08 psibi

Here you go

(use-package rustic
  :init
  (setq rustic-cargo-bin-remote "cargo"
        rustic-treesitter-derive t)

  (with-eval-after-load 'rustic-flycheck
    (remove-hook 'flycheck-mode-hook #'rustic-flycheck-setup))

  :config
  (with-eval-after-load 'hydra
    (defhydra hydra-rust-test (:color blue)
      "Test"
      ("t" rustic-cargo-test)
      ("r" rustic-cargo-test-rerun)
      ("." rustic-cargo-current-test)
      ("q" nil))
    (hydra-set-property 'hydra-rust-test :verbosity 1)

    (defhydra hydra-rust (:color blue)
      "Rust"
      (";" rustic-docstring-dwim)
      ("K" rustic-cargo-rm)
      ("a" rustic-cargo-add)
      ("b" rustic-cargo-build)
      ("B" rustic-cargo-bench)
      ("c" rustic-compile)
      ("d" rustic-racer-describe)
      ("f" rustfmt-format-buffer)
      ("g" rust-playground)
      ("k" rustic-cargo-check)
      ("l" rustic-cargo-clean)
      ("o" rustic-cargo-outdated)
      ("p" rustic-cargo-clippy)
      ("r" rustic-cargo-run)
      ("t" hydra-rust-test/body)
      ("v" rustic-recompile)
      ("q" nil))
    (hydra-set-property 'hydra-rust :verbosity 1)

    (bind-keys :map rustic-mode-map ("C-c h" . hydra-rust/body))
    (with-eval-after-load 'rustic-compile
      (bind-keys :map rustic-compilation-mode-map ("h" . hydra-rust/body))))

  (with-eval-after-load 'rustic-compile
    (unbind-keys :map rustic-compilation-mode-map '("p")))

failable avatar Aug 18 '23 15:08 failable

@liebkne Have pushed a fix, can you give it a try ?

psibi avatar Aug 18 '23 16:08 psibi

I am in the process of testing out these changes. Some things I noticed:

The normal C-c C-c keybindings are no longer defined.

lsp mode is not getting enabled by default.

CeleritasCelery avatar Aug 18 '23 20:08 CeleritasCelery

@psibi commented on Aug 19, 2023, 12:06 AM GMT+8:

@liebkne Have pushed a fix, can you give it a try ?

Originally posted by @psibi in https://github.com/brotzeit/rustic/issues/527#issuecomment-1684130402

Hi, the major mode seems to work now. But some variables are missing

File mode specification error: (void-variable rustic-indent-offset)

as complained by the dtrt-indent package.

failable avatar Aug 19 '23 03:08 failable

@liebkne

Hi, the major mode seems to work now

Cool, thanks for the confirmation.

as complained by the dtrt-indent package.

Can you provide list of all variables ? I will see if I can provide a compatibility layer for third party packages.

@CeleritasCelery Thanks for the report, I can reproduce it. I will look into it once I get some time.

psibi avatar Aug 19 '23 04:08 psibi

@psibi Hi, currently I only find rustic-indent-offset is missing.

failable avatar Aug 19 '23 09:08 failable

@CeleritasCelery Regarding the lsp mode, I got it working through the following configuration:

(use-package rustic
  :init
  (progn
    (setq rustic-treesitter-derive t)
    (add-hook 'rustic-mode-hook #'lsp-deferred))
...

Can you try that and see how it goes ?

psibi avatar Aug 21 '23 05:08 psibi

Found one more missing: rustic-after-save-hook.

failable avatar Aug 22 '23 15:08 failable

Found one more missing: rustic-after-save-hook.

I'm getting the same error. It seems like a lot of the variables aren't really loading as well. ~~They came back briefly, but disappeared again so I'm not sure what's causing this.~~ This seems to be an issue stemming from rust-ts-mode. A lot of variables are missing from it.

EDIT: Does this rely on rust-lang/rust-mode#482 to get all the functionality of regular rust-mode?

EDIT 2: For whoever comes across this, I managed to get it working by forking rust-mode and applying the changes in that pull request to master then using straight to grab my version of it. I then used rustic master since the PR linked causes rust-mode to be based off rust-ts-mode and it works so far, no need for this PR to be used.

NickSica avatar Sep 20 '23 22:09 NickSica

@NickSica You're right. I'm planning to get that rust-mode PR merged soon. How has been your experience so far ?

psibi avatar Feb 17 '24 05:02 psibi

@NickSica You're right. I'm planning to get that rust-mode PR merged soon. How has been your experience so far ?

I honestly haven't used it as much as I wanted to since a paper came in the way of my free time. From my experience, if I remember correctly, it worked pretty well.

NickSica avatar Feb 17 '24 05:02 NickSica

@NickSica Thanks for the feedback! I'm planning to test drive it a week and merge it if works well.

psibi avatar Feb 17 '24 06:02 psibi