Closed JordanAnthonyKing closed 1 month ago
Is it working with a default setup? If not, try M-x toggle-debug-on-error
and post the traceback.
What qualifies as a default setup? Does indent-bars not need me to provide it a spec of scopes?
Maybe comment out everything except the treesit vars.
Did you manage to solve this?
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.
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.
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 :)
Can you C-M-x
on indent-bars--current-indentation-depth
and add the richer backtrace?
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])
Can you let me know the values of indent-bars--offset
and indent-bars--spacing
in the buffer?
Can you let me know the values of
indent-bars--offset
andindent-bars--spacing
in the buffer?
nil and nil
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?
(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.
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?
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.
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.
Assuming this is fixed. Let me know if not.
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.
Good idea. Update: done.
I'm trying to get indent-bars-ts-mode to work with a fairly simple setup: