zkry / yaml-pro

Edit YAML in Emacs like a pro
GNU General Public License v3.0
137 stars 9 forks source link

yaml-pro stops working with polymode enabled #46

Closed uqix closed 6 months ago

uqix commented 6 months ago

To reproduce:

Configure:

(require 'polymode)

(define-innermode poly-bash-innermode
  :mode 'bash-ts-mode
  :head-matcher "^ *#!/usr/bin/env \\(sh\\|bash\\)\n"
  :tail-matcher "^ *# </bash>$"
  :head-mode 'body
  :tail-mode 'body)

(define-hostmode poly-yaml-ts-hostmode
  :mode 'yaml-ts-mode)

(define-polymode poly-yaml-ts-mode
  :hostmode 'poly-yaml-ts-hostmode
  :innermodes
  '(poly-bash-innermode))

(add-hook 'yaml-ts-mode-hook 'poly-yaml-ts-mode)

Open test.yaml:

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: bash-v1
spec:
  params:
    - name: args
      type: array
      default: []
    - name: script
  steps:
    - name: execute
      script: |
        #!/usr/bin/env bash

        set -exu -o pipefail +o histexpand
        shopt -s inherit_errexit extglob

        # </bash>
image

Call yaml-pro-ts-kill-subtree on any key, nothing happens, other subtree jump commands don't work neither.

Have no idea the problem is from yaml-pro or polymode, some help appreciated, thanks.

zkry commented 6 months ago

So I tried replicate this with the steps you wrote but I was't able to for some reason.

2024-02-22 20 26 05

Some ideas come to mind to track down this problem:

(defun yaml-pro-ts-up-level ()
  "Move the point to the parent tree."
  (interactive)
  (let* ((at-node (treesit-node-at (point))) ;; Should get a valid node back
         (tree-top (yaml-pro-ts--until-mapping-or-list at-node)) ;; should be non-nil
         (parent-tree-top (and tree-top (yaml-pro-ts--until-mapping-or-list tree-top)))) ;;  should be non-nil
    (when parent-tree-top
      (goto-char (treesit-node-start parent-tree-top)))))

are those let values returning things non-nil elements?

uqix commented 6 months ago

How about adding this config:

(advice-remove 'bash-ts-mode #'sh--redirect-bash-ts-mode)
(add-to-list 'major-mode-remap-alist '(sh-mode . bash-ts-mode))
uqix commented 6 months ago

shopt should have builtin face in bash-ts-mode, yaml-pro works perfectly with sh-mode.

zkry commented 6 months ago

I see the issue now. It turns out the (treesit commands were getting the other parse-trees when the existed. I just merged a fix so that only the 'yaml treesitter tree is used. Definitely let me know if you have further problems!

uqix commented 6 months ago
  (let* ((at-tree (yaml-pro-ts--until-mapping-or-list (treesit-node-at (point) 'ymal))))

Pls fix this typo: ymal -> yaml.

zkry commented 6 months ago

ah, good catch, sorry about that. Should be fixed now.

uqix commented 6 months ago

Awesome, thank you.