abougouffa / minemacs

MinEmacs: an Emacs configuration framework for daily use
https://abougouffa.github.io/minemacs/
MIT License
140 stars 17 forks source link

[BUG] Nix-ts-mode doesn't seem to work with tree-sitter #140

Closed hmanhng closed 7 months ago

hmanhng commented 8 months ago

Describe the bug I enabled the me-progs module as well as me-tools, opened a .nix file with nix-ts-mode seems like treesitter is not working, when I Mx nix-mode the syntax is highlighted. Sorry if my English is not good.

Emacs version

GNU Emacs XX.29.1(build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.18.0)

Checkup list

Modules

;;; modules.el -*- lexical-binding: t; -*-

;;; Ordered list of enabled core modules
(setq minemacs-core-modules
      '(me-splash         ; Simple splash screen
        me-keybindings    ; Keybinding (general, which-key, hydra, ...)
        me-evil           ; Emacs as Vim (evil, evil-collection, evil-snipe, evil-numbers, ...)
        me-core-ui        ; Core UI (doom-themes, modus-themes, doom-modeline, ...)
        me-completion))   ; Completion (vertico, marginalia, corfu, cape, consult, embark, ...)

;;; List of enabled modules
(setq minemacs-modules
      '(me-ui             ; User interface (svg-lib, focus, mixed-pitch, ...)
        me-editor         ; Editing (tempel, tempel-collection, rainbow-delimiters, expreg, drag-stuff, ...)
        ;; me-daemon         ; Emacs daemon tweaks
        me-undo           ; Better undoing (undo-fu, undo-fu-session, vundo, ...)
        ;; me-multi-cursors  ; Multi-cursors editing (iedit, evil-mc, evil-iedit-state, ...)
        me-vc             ; Version control (magit, forge, core-review, diff-hl, ...)
        me-project        ; Project management (consult-project-extra, ibuffer-project, ...)
        me-prog           ; Programming stuff (tree-sitter, eldoc-box, apheleia, editorconfig, ...)
        me-checkers       ; Static checkers (flymake-easy, ...)
        ;; me-debug          ; Debugging tools (realgud, disaster, ...)
        ;; me-lsp         ; LSP and DAP (lsp-mode, dap-mode, consult-lsp, lsp-pyright, ccls, ...)
        me-emacs-lisp     ; Emacs lisp development (parinfer-rust, macrostep, eros, helpful, ...)
        ;; me-common-lisp ; Common Lisp development (sly, sly-quicklisp, ...)
        ;; me-scheme      ; Scheme development (racket-mode, geiser, ...)
        ;; me-clojure     ; Clojure development (clojure-mode, cider, ...)
        ;; me-embedded    ; Embedded systems (arduino, openocd, bitbake, ...)
        ;; me-robot       ; Robotics stuff (ros, robot-mode, ...)
        me-data           ; Data file formats (csv, yaml, toml, json, plantuml-mode, ...)
        ;; me-math        ; Mathematics (maxima, ess, ein, julia-mode, ...)
        ;; me-modeling    ; Modeling tools (scad-mode, ...)
        me-org            ; Org-mode for life (org-contrib, org-modern, org-appear, ...)
        ;; me-extra          ; Extra features (better-jumper, crux, ...)
        ;; me-notes          ; Notes & Zettelkasten (denote, ...)
        ;; me-email       ; Email (mu4e, mu4e-alert, org-msg, ...)
        ;; me-rss         ; News feed (elfeed, ...)
        ;; me-lifestyle   ; *Very* opinionated lifestyle packages (awqat, ...)
        ;; me-docs           ; Documents (pdf-tools, nov, ...)
        ;; me-calendar    ; Calendar (calfw, calfw-org, calfw-ical, ...)
        ;; me-latex          ; LaTeX (auctex, auctex-latexmk, ...)
        ;; me-biblio      ; Bibliography & citations (citar, zotxt, ...)
        ;; me-natural-langs  ; Natural language stuff (spell-fu, go-translate, eglot-ltex, ...)
        ;; me-files          ; Files and directories (dirvish, treemacs, vlf, ...)
        me-tools          ; System tools (vterm, tldr, ssh-deploy, docker, ...)
        me-tty            ; Emacs from terminal (xt-mouse, xclip, ...)
        ;; me-fun            ; Games and funny packages (xkcd, speed-type, ...)
        ;; me-media          ; Multimedia (empv, emms, ...)
        ;; me-workspaces  ; Workspace separation (tabspaces, ...)
        ;; me-binary         ; Display binary files in hex or decompile them
        me-window))       ; Frame & window tweaks

;;; List of disabled packages
(setq minemacs-disabled-packages
      (append
       '(;; me-ui
         focus
         me-writing-mode
         visual-fill-column
         ;; me-tools
         bitwarden)))

Backtrace If the bug rises an error, please attach the full backtrace. To be sure to obtain a backtrace, you should launch Emacs with MINEMACS_DEBUG=1 emacs or emacs --debug-init.

⛔ Warning (treesit): Cannot activate tree-sitter, because language grammar for nix is unavailable (not-found): (libtree-sitter-nix libtree-sitter-nix.0 libtree-sitter-nix.0.0 libtree-sitter-nix.so libtree-sitter-nix.so.0 libtree-sitter-nix.so.0.0) No such file or directory

Screenshots If applicable, add screenshots to help explain your problem. image

Additional context I tried running removing the nix-ts-mode package with MINEMACS_DEBUG=1 emacs and it worked fine, it seems the error is coming from nix-ts-mode.

hmanhng commented 8 months ago

image It seems treesit-auto is not doing its job treesit-auto-install-all also nothing happened

abougouffa commented 8 months ago

Thank you for the feedback @hmanhng ,

It seems weird! You can temporarily add (push 'nix-ts-mode minemacs-disabled-packages) to your modules.el in order to disable the package until I take a look at it!

hmanhng commented 8 months ago

As I understand it, the following 2 lines will push treesit are not installed to treesit-auto-langs but when I check the variable treesit-auto-langs it returns nil. Perhaps the error lies here ? image

abougouffa commented 8 months ago

@hmanhng

Yep, you're right!

It seems that seq-difference expects the bigger set to be the first one! I've pushed a fix, can you pull it and try again?

Thanks again

hmanhng commented 8 months ago

Now it works with other languages ​​except nix-ts-mode. There are 2 issue with nix-ts-mode

  1. ~nix-ts-mode doesn't work with hs-minor-mode~
  2. There is issue with (treesit-auto, tree-sitter-nix), when I try both nix-mode and nix-ts-mode they don't install automatically, but treesit-auto-install-all did install tree-sitter-nix and worked on both nix-mode and nix-ts-mode
hmanhng commented 7 months ago

https://github.com/abougouffa/minemacs/commit/3c5d6e9cd237d1206688b410b27263c9bcf3c350 I don't know why you deleted these lines, it will remove nix from treesit-auto-langs and make it impossible to install

abougouffa commented 7 months ago

What I wanted to achieve with these lines https://github.com/abougouffa/minemacs/commit/3c5d6e9cd237d1206688b410b27263c9bcf3c350 was to only try to install language grammars that are not already installed (due to an issue with a previous version of treesit-auto. However, setting the treesit-auto-langs this way resulted in an empty list, which disables the mode mapping (i.e. mapping x-mode to x-ts-mode).

Can you confirm that the libtree-sitter-nix.so has been installed (to ~/.emacs.d/local/tree-sitter/) ?

abougouffa commented 7 months ago

When reverting https://github.com/abougouffa/minemacs/commit/3c5d6e9cd237d1206688b410b27263c9bcf3c350, Emacs won't remap the modes when the grammars are installed. Practically, it will only work on the first session (when grammars aren't installed), and once installed and restarted Emacs, it will raise other problems.

For example, see: https://github.com/renzmann/treesit-auto/blob/07a8f924cd4f020a2eb32b45d8543af9556f355d/treesit-auto.el#L461C30-L461C30

The (treesit-auto--selected-recipes) function (which depends on treesit-auto-langs) is used in several places. Which make any change to treesit-auto-langs affect this.

hmanhng commented 7 months ago

if there is no nix in treesit-auto-langs then I won't be able to install it even with treesit-auto-install-all

abougouffa commented 7 months ago

Indeed. Well in this case, just adding nix to treesit-auto-langs will fix the issue.

I've pushed a fix for this.

Thanks for you patience! @hmanhng