jdtsmith / indent-bars

Fast, configurable indentation guide-bars for Emacs
GNU General Public License v3.0
373 stars 14 forks source link

Error running timer ‘indent-bars-ts--update-scope1’: (wrong-type-argument number-or-marker-p nil) [6 times] #56

Closed JordanAnthonyKing closed 1 month ago

JordanAnthonyKing commented 2 months ago

I'm trying to get indent-bars-ts-mode to work with a fairly simple setup:

(use-package indent-bars
  :ensure (indent-bars :host github :repo "jdtsmith/indent-bars")
  :hook ((typescript-ts-mode angular-ts-mode) . indent-bars-ts-mode)
  :custom
  (indent-bars-treesit-support t)
  ;; (indent-bars-treesit-ignore-blank-lines-types nil)
  (indent-bars-treesit-scope '((typescript class_body)))
                                ;; program comment ternary_expression member_expression named_imports 
                                ;; statement_block switch_case switch_default type_arguments type_parameters 
                                ;; arguments array formal_parameters template_string template_substitution 
                                ;; object_pattern object object_type enum_body class_body interface_body 
                                ;; arrow_function parenthesized_expression binary_expression if_statement 
                                ;; for_statement for_in_statement while_statement do_statement else_clause)))

  :config
  (setq indent-bars-starting-column 0)
  (defun set-indent-bars-spacing () (setq-local indent-bars-spacing 2))
  (add-hook 'indent-bars-mode-hook 'set-indent-bars-spacing)

  ;; (setq indent-bars-color '(:face background :blend 1.0))
  ;; (setq indent-bars-highlight-current-depth '(:face nano-popout))

  (setq indent-bars-ts-highlight-current-depth '(:face nano-popout))) 
jdtsmith commented 2 months ago

Is it working with a default setup? If not, try M-x toggle-debug-on-error and post the traceback.

JordanAnthonyKing commented 2 months ago

What qualifies as a default setup? Does indent-bars not need me to provide it a spec of scopes?

jdtsmith commented 2 months ago

Maybe comment out everything except the treesit vars.

jdtsmith commented 1 month ago

Did you manage to solve this?

JordanAnthonyKing commented 1 month ago

Hi, I’ve been a bit busy. Running with a minimal config still ran into the issue. I’ll try and get a backtrace for you sometime next week.

jdtsmith commented 1 month ago

When you can reproduce the error and get a backtrace, open indent-bars-ts.el, navigate to indent-bars-ts--update-scope1, C-M-x to evaluate the functions, make the error occur, and send the full backtrace.

JordanAnthonyKing commented 1 month ago

Here's my backtrace when triggering indent-bars-ts-mode:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  indent-bars--current-indentation-depth()
  indent-bars-ts--update-scope1(#<buffer add-edit-location-modal.component.ts>)
  apply(indent-bars-ts--update-scope1 #<buffer add-edit-location-modal.component.ts>)
  timer-event-handler([t 0 0 125000 nil indent-bars-ts--update-scope1 (#<buffer add-edit-location-modal.component.ts>) idle 0 nil])

For reference, here's a relevant chunk from treesit-explore, I'm trying to match class_body:

 export
 declaration: 
  (class_declaration class name: (type_identifier)
   (class_heritage
    (extends_clause extends value: (identifier))
    (implements_clause implements (type_identifier) , (type_identifier) , (type_identifier)))
   body: 
    (class_body {
     (public_field_definition
      decorator: 
       (decorator @
        (call_expression function: (identifier)
         arguments: 
          (arguments ( (identifier) ,
           (object {
            (pair key: (property_identifier) : value: (false))
            })
           ))))
      (accessibility_modifier public)
      name: (property_identifier)
      type: (type_annotation : (type_identifier)))

Here's the full backtrace:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  indent-bars--current-indentation-depth()
  (save-excursion (goto-char (car new)) (indent-bars--current-indentation-depth))
  (aset v 2 (save-excursion (goto-char (car new)) (indent-bars--current-indentation-depth)))
  (let* ((v cl-x)) (aset v 2 (save-excursion (goto-char (car new)) (indent-bars--current-indentation-depth))))
  (let* ((cl-x indent-bars-ts-current-scope)) (let* ((v cl-x)) (aset v 2 (save-excursion (goto-char (car new)) (indent-bars--current-indentation-depth)))))
  (if (and (= (car new) (car old)) (= (cdr new) (cdr old))) nil (let* ((--cl-var-- (indent-bars-ts--union old new)) (end nil) (beg nil)) (while (consp --cl-var--) (progn (setq end (car --cl-var--)) (setq beg (car-safe (prog1 end (setq end ...))))) (jit-lock-refontify beg end) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((cl-x indent-bars-ts-current-scope)) (let* ((v cl-x)) (aset v 2 (save-excursion (goto-char (car new)) (indent-bars--current-indentation-depth))))) (set-marker (car old) (car new)) (set-marker (cdr old) (cdr new)))
  (let* ((pmn (point-min)) (pmx (point-max)) (old (let* ((cl-x indent-bars-ts-current-scope)) (progn (progn (aref cl-x 1))))) (node (treesit-node-on (max pmn (1- (point))) (point) indent-bars-ts--parser)) (scope (and node (indent-bars-ts--node-query node (let* ((cl-x indent-bars-ts-current-scope)) (progn (progn ...))) nil 'innermost indent-bars-treesit-scope-min-lines))) (new (if scope (cons (treesit-node-start scope) (treesit-node-end scope)) (cons pmn pmx)))) (if (and (= (car new) (car old)) (= (cdr new) (cdr old))) nil (let* ((--cl-var-- (indent-bars-ts--union old new)) (end nil) (beg nil)) (while (consp --cl-var--) (progn (setq end (car --cl-var--)) (setq beg (car-safe (prog1 end ...)))) (jit-lock-refontify beg end) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((cl-x indent-bars-ts-current-scope)) (let* ((v cl-x)) (aset v 2 (save-excursion (goto-char (car new)) (indent-bars--current-indentation-depth))))) (set-marker (car old) (car new)) (set-marker (cdr old) (cdr new))))
  (progn (setq indent-bars-ts--scope-timer nil) (let* ((pmn (point-min)) (pmx (point-max)) (old (let* ((cl-x indent-bars-ts-current-scope)) (progn (progn (aref cl-x 1))))) (node (treesit-node-on (max pmn (1- (point))) (point) indent-bars-ts--parser)) (scope (and node (indent-bars-ts--node-query node (let* (...) (progn ...)) nil 'innermost indent-bars-treesit-scope-min-lines))) (new (if scope (cons (treesit-node-start scope) (treesit-node-end scope)) (cons pmn pmx)))) (if (and (= (car new) (car old)) (= (cdr new) (cdr old))) nil (let* ((--cl-var-- (indent-bars-ts--union old new)) (end nil) (beg nil)) (while (consp --cl-var--) (progn (setq end (car --cl-var--)) (setq beg (car-safe ...))) (jit-lock-refontify beg end) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((cl-x indent-bars-ts-current-scope)) (let* ((v cl-x)) (aset v 2 (save-excursion (goto-char ...) (indent-bars--current-indentation-depth))))) (set-marker (car old) (car new)) (set-marker (cdr old) (cdr new)))))
  (unwind-protect (progn (setq indent-bars-ts--scope-timer nil) (let* ((pmn (point-min)) (pmx (point-max)) (old (let* ((cl-x indent-bars-ts-current-scope)) (progn (progn ...)))) (node (treesit-node-on (max pmn (1- ...)) (point) indent-bars-ts--parser)) (scope (and node (indent-bars-ts--node-query node (let* ... ...) nil 'innermost indent-bars-treesit-scope-min-lines))) (new (if scope (cons (treesit-node-start scope) (treesit-node-end scope)) (cons pmn pmx)))) (if (and (= (car new) (car old)) (= (cdr new) (cdr old))) nil (let* ((--cl-var-- (indent-bars-ts--union old new)) (end nil) (beg nil)) (while (consp --cl-var--) (progn (setq end ...) (setq beg ...)) (jit-lock-refontify beg end) (setq --cl-var-- (cdr --cl-var--))) nil) (let* ((cl-x indent-bars-ts-current-scope)) (let* ((v cl-x)) (aset v 2 (save-excursion ... ...)))) (set-marker (car old) (car new)) (set-marker (cdr old) (cdr new))))) (if (memq modified '(nil autosaved)) (progn (restore-buffer-modified-p modified))))
  (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (setq indent-bars-ts--scope-timer nil) (let* ((pmn (point-min)) (pmx (point-max)) (old (let* (...) (progn ...))) (node (treesit-node-on (max pmn ...) (point) indent-bars-ts--parser)) (scope (and node (indent-bars-ts--node-query node ... nil ... indent-bars-treesit-scope-min-lines))) (new (if scope (cons ... ...) (cons pmn pmx)))) (if (and (= (car new) (car old)) (= (cdr new) (cdr old))) nil (let* ((--cl-var-- ...) (end nil) (beg nil)) (while (consp --cl-var--) (progn ... ...) (jit-lock-refontify beg end) (setq --cl-var-- ...)) nil) (let* ((cl-x indent-bars-ts-current-scope)) (let* (...) (aset v 2 ...))) (set-marker (car old) (car new)) (set-marker (cdr old) (cdr new))))) (if (memq modified '(nil autosaved)) (progn (restore-buffer-modified-p modified)))))
  (save-current-buffer (set-buffer buf) (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (setq indent-bars-ts--scope-timer nil) (let* ((pmn (point-min)) (pmx (point-max)) (old (let* ... ...)) (node (treesit-node-on ... ... indent-bars-ts--parser)) (scope (and node ...)) (new (if scope ... ...))) (if (and (= ... ...) (= ... ...)) nil (let* (... ... ...) (while ... ... ... ...) nil) (let* (...) (let* ... ...)) (set-marker (car old) (car new)) (set-marker (cdr old) (cdr new))))) (if (memq modified '(nil autosaved)) (progn (restore-buffer-modified-p modified))))))
  indent-bars-ts--update-scope1(#<buffer add-edit-location-modal.component.ts>)
  apply(indent-bars-ts--update-scope1 #<buffer add-edit-location-modal.component.ts>)
  timer-event-handler([t 0 0 125000 nil indent-bars-ts--update-scope1 (#<buffer add-edit-location-modal.component.ts>) idle 0 nil])

Thanks for your patience :)

jdtsmith commented 1 month ago

Can you C-M-x on indent-bars--current-indentation-depth and add the richer backtrace?

JordanAnthonyKing commented 1 month ago

I followed the same steps as earlier but don't seem to get anything richer:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  indent-bars--depth(0)
  (let* ((c (current-indentation)) (d (indent-bars--depth c)) ppss-ind) (if indent-bars--ppss (progn (let* ((p (prog1 (point) (forward-line 0))) (ppss (syntax-ppss)) (ss (and indent-bars-no-descend-string (nth 8 ppss))) (sl (and indent-bars-no-descend-lists (nth 1 ppss)))) (if (setq ppss-ind (if (and ss sl) (max ss sl) (or ss sl))) (progn (goto-char ppss-ind) (let* (... ...) (if ... ...)))) (goto-char p)))) (if (and indent-bars--update-depth-function (not ppss-ind)) (progn (setq d (funcall indent-bars--update-depth-function d)))) (if (and (eq on-bar 'context) (< (indent-bars--context-depth) (+ c indent-bars-spacing))) (progn (setq on-bar nil))) (if (and on-bar (= c (+ indent-bars--offset (* d indent-bars-spacing)))) (1+ d) d))
  indent-bars--current-indentation-depth()
  indent-bars-ts--update-scope1(#<buffer add-edit-location-modal.component.ts>)
  apply(indent-bars-ts--update-scope1 #<buffer add-edit-location-modal.component.ts>)
  timer-event-handler([t 0 0 125000 nil indent-bars-ts--update-scope1 (#<buffer add-edit-location-modal.component.ts>) idle 0 nil])
jdtsmith commented 1 month ago

Can you let me know the values of indent-bars--offset and indent-bars--spacing in the buffer?

JordanAnthonyKing commented 1 month ago

Can you let me know the values of indent-bars--offset and indent-bars--spacing in the buffer?

nil and nil

jdtsmith commented 1 month ago

OK, that's your problem. I don't know how this is possible. What does M-: (derived-mode-p 'js-mode) say? If non-nil, what is js-indent-level? If nil, what is js2-basic-offset? Or maybe this is typescript-ts-mode?

Please visit the function indent-bars--guess-spacing, C-u C-M-x, then enable indent-bars in the TS buffer, and use space bar to step through the function. On what statement does it exit the cond statement?

JordanAnthonyKing commented 1 month ago

(derived-mode-p 'js-mode) = nil js2-basic-offset = not defined

It doesn't exit in either js-mode or js2-mode. Typescript-ts-mode derives from typescript-ts-base-mode which derives directly from prog-mode.

jdtsmith commented 1 month ago

It doesn't exit in either js-mode or js2-mode.

So where does it exit? The catch-all is 4, not nil. So one of the other variables must be defined (and nil). standard-indent maybe?

JordanAnthonyKing commented 1 month ago

Sorry, it passed all the way to the bottom of the function, so yeah, 4. That said, and maybe this is user error, but if I call indent-bars-ts-mode as I had my hook setup then I didn't get to debug that function, I had to call indent-bars-mode.

jdtsmith commented 1 month ago

I call indent-bars-ts-mode as I had my hook setup

Ahh, missed that. That's the real issue. To get TS support, you simply set indent-bars-treesit-support=t and enable indent-bars-mode! indent-bars-ts-mode is just a "helper mode" and does not stand alone. It will do the right thing depending on whether TS is available in the buffer where it's enabled.

I also pushed a commit with typescript-ts-mode support. Give these a try and report back.

jdtsmith commented 1 month ago

Assuming this is fixed. Let me know if not.

shipmints commented 1 month ago

Perhaps rename indent-bars-ts-mode to indent-bars--ts-mode to indicate that it should not be used by users? It will immediately smoke out the people using it incorrectly when they next update indent-bars.

jdtsmith commented 1 month ago

Good idea. Update: done.