Skip to content

(wrong-type-argument number-or-marker-p nil) in (lsp-headerline--build-symbol-string) #4834

@bwo

Description

@bwo

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

All this takes places also in an environment with lsp-start-plain:

When editing a python source file, whenever the file is not completely grammatically correct (which of course happens all the time, for instance when you have just typed the . to start a method call), a big backtrace buffer pops up when the lsp--on-idle timer is triggered. The backtrace looks like this:

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  min(1 nil)
  (setq range-severity (min range-severity severity?))
  (progn (setq range-severity (min range-severity severity?)))
  (if (lsp-point-in-range? start range) (progn (setq range-severity (min range-severity severity?))))
  (let* ((start (gethash "start" (gethash "range" input0))) (severity? (gethash "severity" input0))) (if (lsp-point-in-range? start range) (progn (setq range-severity (min range-severity severity?)))))
  #f(lambda (input0) [(range-severity 1) (range #<hash-table equal 2/2 0x5721dbf1 ...>)] (let* ((start (gethash "start" (gethash "range" input0))) (severity? (gethash "severity" input0))) (if (lsp-point-in-range? start range) (progn (setq range-severity (min range-severity severity?))))))(#<hash-table equal 3/3 0x5de9d919 ...>)
  mapc(#f(lambda (input0) [(range-severity 1) (range #<hash-table equal 2/2 0x5721dbf1 ...>)] (let* ((start (gethash "start" (gethash "range" input0))) (severity? (gethash "severity" input0))) (if (lsp-point-in-range? start range) (progn (setq range-severity (min range-severity severity?)))))) (#<hash-table equal 4/4 0x5de856b0 ...> #<hash-table equal 4/4 0x5de85626 ...> #<hash-table equal 6/6 0x5de85659 ...> #<hash-table equal 6/6 0x5de857f5 ...> #<hash-table equal 3/3 0x5de9d919 ...>))
  (let ((range-severity 10)) (mapc #'(lambda (input0) (let* ((start (gethash "start" ...)) (severity? (gethash "severity" input0))) (if (lsp-point-in-range? start range) (progn (setq range-severity ...))))) (lsp--get-buffer-diagnostics)) range-severity)
  lsp-headerline--severity-level-for-range(#<hash-table equal 2/2 0x5721dbf1 ...>)
  (let ((range-severity (lsp-headerline--severity-level-for-range range))) (cond (deprecated? 'lsp-headerline-breadcrumb-deprecated-face) ((not lsp-headerline-breadcrumb-enable-diagnostics) 'lsp-headerline-breadcrumb-symbols-face) ((= range-severity lsp/diagnostic-severity-error) 'lsp-headerline-breadcrumb-symbols-error-face) ((= range-severity lsp/diagnostic-severity-warning) 'lsp-headerline-breadcrumb-symbols-warning-face) ((= range-severity lsp/diagnostic-severity-information) 'lsp-headerline-breadcrumb-symbols-info-face) ((= range-severity lsp/diagnostic-severity-hint) 'lsp-headerline-breadcrumb-symbols-hint-face) (t 'lsp-headerline-breadcrumb-symbols-face)))
  (let* ((deprecated? (gethash "deprecated" input0)) (range (gethash "range" input0))) (let ((range-severity (lsp-headerline--severity-level-for-range range))) (cond (deprecated? 'lsp-headerline-breadcrumb-deprecated-face) ((not lsp-headerline-breadcrumb-enable-diagnostics) 'lsp-headerline-breadcrumb-symbols-face) ((= range-severity lsp/diagnostic-severity-error) 'lsp-headerline-breadcrumb-symbols-error-face) ((= range-severity lsp/diagnostic-severity-warning) 'lsp-headerline-breadcrumb-symbols-warning-face) ((= range-severity lsp/diagnostic-severity-information) 'lsp-headerline-breadcrumb-symbols-info-face) ((= range-severity lsp/diagnostic-severity-hint) 'lsp-headerline-breadcrumb-symbols-hint-face) (t 'lsp-headerline-breadcrumb-symbols-face))))
  lsp-headerline--face-for-symbol(#<hash-table equal 5/5 0x54e755de ...>)
  (propertize name 'font-lock-face (lsp-headerline--face-for-symbol symbol))
  (let* ((symbol2-name (propertize name 'font-lock-face (lsp-headerline--face-for-symbol symbol))) (symbol2-icon (lsp-headerline--symbol-icon symbol)) (full-symbol-2 (concat (if lsp-headerline-breadcrumb-enable-symbol-numbers (concat (propertize (number-to-string index) 'face 'lsp-headerline-breadcrumb-symbols-face) " ") "") (if symbol2-icon (concat symbol2-icon symbol2-name) symbol2-name)))) (lsp-headerline--symbol-with-action symbol full-symbol-2))
  (let* ((--dash-source-1507-- input0) (symbol (car-safe (prog1 --dash-source-1507-- (setq --dash-source-1507-- (cdr --dash-source-1507--))))) (name (gethash "name" symbol)) (index --dash-source-1507--)) (let* ((symbol2-name (propertize name 'font-lock-face (lsp-headerline--face-for-symbol symbol))) (symbol2-icon (lsp-headerline--symbol-icon symbol)) (full-symbol-2 (concat (if lsp-headerline-breadcrumb-enable-symbol-numbers (concat (propertize ... ... ...) " ") "") (if symbol2-icon (concat symbol2-icon symbol2-name) symbol2-name)))) (lsp-headerline--symbol-with-action symbol full-symbol-2)))
  #f(lambda (input0) [t] (let* ((--dash-source-1507-- input0) (symbol (car-safe (prog1 --dash-source-1507-- (setq --dash-source-1507-- (cdr --dash-source-1507--))))) (name (gethash "name" symbol)) (index --dash-source-1507--)) (let* ((symbol2-name (propertize name 'font-lock-face (lsp-headerline--face-for-symbol symbol))) (symbol2-icon (lsp-headerline--symbol-icon symbol)) (full-symbol-2 (concat (if lsp-headerline-breadcrumb-enable-symbol-numbers (concat (propertize (number-to-string index) 'face 'lsp-headerline-breadcrumb-symbols-face) " ") "") (if symbol2-icon (concat symbol2-icon symbol2-name) symbol2-name)))) (lsp-headerline--symbol-with-action symbol full-symbol-2))))((#<hash-table equal 5/5 0x54e755de ...> . 1))
  mapconcat(#f(lambda (input0) [t] (let* ((--dash-source-1507-- input0) (symbol (car-safe (prog1 --dash-source-1507-- (setq --dash-source-1507-- ...)))) (name (gethash "name" symbol)) (index --dash-source-1507--)) (let* ((symbol2-name (propertize name 'font-lock-face (lsp-headerline--face-for-symbol symbol))) (symbol2-icon (lsp-headerline--symbol-icon symbol)) (full-symbol-2 (concat (if lsp-headerline-breadcrumb-enable-symbol-numbers ... "") (if symbol2-icon ... symbol2-name)))) (lsp-headerline--symbol-with-action symbol full-symbol-2)))) ((#<hash-table equal 5/5 0x54e755de ...> . 1)) #(" > " 1 2 (face lsp-headerline-breadcrumb-separator-face)))
  (if enumerated-symbols-hierarchy (mapconcat #'(lambda (input0) (let* ((--dash-source-1507-- input0) (symbol (car-safe ...)) (name (gethash "name" symbol)) (index --dash-source-1507--)) (let* ((symbol2-name ...) (symbol2-icon ...) (full-symbol-2 ...)) (lsp-headerline--symbol-with-action symbol full-symbol-2)))) enumerated-symbols-hierarchy (concat " " (lsp-headerline--arrow-icon) " ")) "")
  (let ((enumerated-symbols-hierarchy (-map-indexed #'(lambda (index elt) (cons elt (1+ index))) symbols-hierarchy))) (if enumerated-symbols-hierarchy (mapconcat #'(lambda (input0) (let* ((--dash-source-1507-- input0) (symbol ...) (name ...) (index --dash-source-1507--)) (let* (... ... ...) (lsp-headerline--symbol-with-action symbol full-symbol-2)))) enumerated-symbols-hierarchy (concat " " (lsp-headerline--arrow-icon) " ")) ""))
  (if symbols-hierarchy (let ((enumerated-symbols-hierarchy (-map-indexed #'(lambda (index elt) (cons elt ...)) symbols-hierarchy))) (if enumerated-symbols-hierarchy (mapconcat #'(lambda (input0) (let* (... ... ... ...) (let* ... ...))) enumerated-symbols-hierarchy (concat " " (lsp-headerline--arrow-icon) " ")) "")) "")
  (let ((symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols))) (if symbols-hierarchy (let ((enumerated-symbols-hierarchy (-map-indexed #'(lambda ... ...) symbols-hierarchy))) (if enumerated-symbols-hierarchy (mapconcat #'(lambda (input0) (let* ... ...)) enumerated-symbols-hierarchy (concat " " (lsp-headerline--arrow-icon) " ")) "")) ""))
  (if symbols (let ((symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols))) (if symbols-hierarchy (let ((enumerated-symbols-hierarchy (-map-indexed #'... symbols-hierarchy))) (if enumerated-symbols-hierarchy (mapconcat #'(lambda ... ...) enumerated-symbols-hierarchy (concat " " (lsp-headerline--arrow-icon) " ")) "")) "")) "")
  (let ((symbols (lsp--get-document-symbols))) (if symbols (let ((symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols))) (if symbols-hierarchy (let ((enumerated-symbols-hierarchy (-map-indexed ... symbols-hierarchy))) (if enumerated-symbols-hierarchy (mapconcat #'... enumerated-symbols-hierarchy (concat " " ... " ")) "")) "")) ""))
  (if lsp--document-symbols-request-async (let ((symbols (lsp--get-document-symbols))) (if symbols (let ((symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols))) (if symbols-hierarchy (let ((enumerated-symbols-hierarchy ...)) (if enumerated-symbols-hierarchy (mapconcat ... enumerated-symbols-hierarchy ...) "")) "")) "")) "")
  (let ((lsp--document-symbols-request-async t)) (if lsp--document-symbols-request-async (let ((symbols (lsp--get-document-symbols))) (if symbols (let ((symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols))) (if symbols-hierarchy (let (...) (if enumerated-symbols-hierarchy ... "")) "")) "")) ""))
  (if (lsp-feature? "textDocument/documentSymbol") (let ((lsp--document-symbols-request-async t)) (if lsp--document-symbols-request-async (let ((symbols (lsp--get-document-symbols))) (if symbols (let ((symbols-hierarchy ...)) (if symbols-hierarchy (let ... ...) "")) "")) "")) "")
  lsp-headerline--build-symbol-string()
  (let nil (lsp-headerline--build-symbol-string))
  (cond ((eq segment 'project) (let nil (lsp-headerline--build-project-string))) ((eq segment 'file) (let nil (lsp-headerline--build-file-string))) ((eq segment 'path-up-to-project) (let nil (lsp-headerline--build-path-up-to-project-string))) ((eq segment 'symbols) (let nil (lsp-headerline--build-symbol-string))) (t (let nil (lsp-log "'%s' is not a valid entry for `lsp-headerline-breadcrumb-segments'" (symbol-name segment)) "")))
  (let ((segment-string (cond ((eq segment 'project) (let nil (lsp-headerline--build-project-string))) ((eq segment 'file) (let nil (lsp-headerline--build-file-string))) ((eq segment 'path-up-to-project) (let nil (lsp-headerline--build-path-up-to-project-string))) ((eq segment 'symbols) (let nil (lsp-headerline--build-symbol-string))) (t (let nil (lsp-log "'%s' is not a valid entry for `lsp-headerline-breadcrumb-segments'" (symbol-name segment)) ""))))) (if (string-empty-p segment-string) "" (concat (lsp-headerline--arrow-icon) " " segment-string " ")))
  #f(lambda (segment) [all-the-icons-scale-factor all-the-icons-default-adjust t] (let ((segment-string (cond ((eq segment 'project) (let nil (lsp-headerline--build-project-string))) ((eq segment 'file) (let nil (lsp-headerline--build-file-string))) ((eq segment 'path-up-to-project) (let nil (lsp-headerline--build-path-up-to-project-string))) ((eq segment 'symbols) (let nil (lsp-headerline--build-symbol-string))) (t (let nil (lsp-log "'%s' is not a valid entry for `lsp-headerline-breadcrumb-segments'" (symbol-name segment)) ""))))) (if (string-empty-p segment-string) "" (concat (lsp-headerline--arrow-icon) " " segment-string " "))))(symbols)
  mapconcat(#f(lambda (segment) [all-the-icons-scale-factor all-the-icons-default-adjust t] (let ((segment-string (cond ((eq segment ...) (let nil ...)) ((eq segment ...) (let nil ...)) ((eq segment ...) (let nil ...)) ((eq segment ...) (let nil ...)) (t (let nil ... ""))))) (if (string-empty-p segment-string) "" (concat (lsp-headerline--arrow-icon) " " segment-string " ")))) (path-up-to-project file symbols) "")
  (string-trim-right (mapconcat #'(lambda (segment) (let ((segment-string (cond ... ... ... ... ...))) (if (string-empty-p segment-string) "" (concat (lsp-headerline--arrow-icon) " " segment-string " ")))) lsp-headerline-breadcrumb-segments ""))
  lsp-headerline--build-string()
  (set-window-parameter (selected-window) 'lsp-headerline--string (lsp-headerline--build-string))
  lsp-headerline-check-breadcrumb()
  run-hooks(lsp-on-idle-hook)
  (progn (run-hooks 'lsp-on-idle-hook))
  (if (and (buffer-live-p buffer) (equal buffer (current-buffer)) (not lsp-inhibit-lsp-hooks) lsp-managed-mode) (progn (run-hooks 'lsp-on-idle-hook)))

this makes editing with the headerline essentially impossible.

Steps to reproduce

honestly: I couldn't figure this out. But I can tell you that running this in the affected python buffer has this output:

evaluate these expressions with C-x e

# (setq m (lsp--get-buffer-diagnostics))
# (print (gethash "start" (gethash "range" (car m))))

this is printed:

#s(hash-table test equal data (line 461 character 41))

ie, there is no "severity" key. therefore this fails:

(setq range-severity (min range-severity severity?))

because you can't call min on nil.

Expected behavior

the idle hook doesn't blow up the editor

Which Language Server did you use?

lsp-pyright

OS

Linux

Error callstack

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions