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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

psibi
Copy link
Collaborator

@psibi psibi commented Aug 18, 2023

This code is based on #480, but there are some changes based on my testing.

This code is based on #480, but
there are some changes based on my testing.
@failable
Copy link

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)

@psibi
Copy link
Collaborator Author

psibi commented Aug 18, 2023

@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-*

@failable
Copy link

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

@psibi
Copy link
Collaborator Author

psibi commented Aug 18, 2023

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

@failable
Copy link

failable commented Aug 18, 2023

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")))

@psibi
Copy link
Collaborator Author

psibi commented Aug 18, 2023

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

@CeleritasCelery
Copy link
Contributor

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.

@failable
Copy link

@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 #527 (comment)

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.

@psibi
Copy link
Collaborator Author

psibi commented Aug 19, 2023

@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.

@failable
Copy link

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

@psibi
Copy link
Collaborator Author

psibi commented Aug 21, 2023

@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 ?

@failable
Copy link

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

@NickSica
Copy link

NickSica commented Sep 20, 2023

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.

@psibi
Copy link
Collaborator Author

psibi commented Feb 17, 2024

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

@NickSica
Copy link

@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.

@psibi
Copy link
Collaborator Author

psibi commented Feb 17, 2024

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

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

Successfully merging this pull request may close these issues.

4 participants