seagle0128 / doom-modeline

A fancy and fast mode-line inspired by minimalism design.
https://seagle0128.github.io/doom-modeline/
GNU General Public License v3.0
1.27k stars 157 forks source link

[Bug] segment report error in terminal #658

Closed blithefeng closed 1 year ago

blithefeng commented 1 year ago

Thank you for the bug report

Bug description

升级到doom新版后,doom有更新到doom-modeline的f45a5a200313568d54d73dd38bae76930c2008b5这个提交。打开go项目后无法启动lsp

Steps to reproduce

  1. 使用doom最新版本,配置(go +lsp) 启用lsp功能
  2. 打开一个go项目,默认lsp打开失败。使用lsp!命令再次打开,状态栏一直刷新状态,但lsp启动不成功。状态栏显示为:Go [= ]
  3. 检查状态栏,没有图标能够展示

Expected behavior

状态栏在安装了nerd-icons的情况下,在终端模式下正常显示图标

OS

MacOS

Emacs Version

29

Emacs Configurations

No response

Error callstack

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
   propertize(nil help-echo "LSP Connected [gopls:15789/starting]\nC-mouse-1: Sw..." mouse-face doom-modeline-highlight local-map (keymap (mode-line keymap (mouse-3 . lsp-workspace-restart) (mouse-2 . lsp-workspace-shutdown) (mouse-1 . lsp-desc$
   doom-modeline-update-lsp()
   run-hooks(lsp-before-initialize-hook)

Anything else

除了lsp以外,其他segment也在报错。但是因为lsp这个是个before hook,所以导致了lsp不可用

Error during redisplay: (eval (doom-modeline-segment--debug)) signaled (wrong-type-argument stringp nil)

blithefeng commented 1 year ago

@seagle0128 你好,你的这个commit修复并不能解决问题。我这里clone了库测试了下,导致问题的根因在调用doom-modeline-propertize-icon这个函数时,不过我实在是没有找到原因。我在这个函数里面加了message,但是并没有执行到 看起来在调用 (doom-modeline-propertize-icon icon face) 的时候问题就已经出现了。我修改为(if icon icon "")就能正常在终端下展示图标了

seagle0128 commented 1 year ago

这样不能修复问题吗?

(if icon
     (doom-modeline-propertize-icon icon face)
   "")
blithefeng commented 1 year ago

这样不能修复问题,最新的commit也不能修复问题。其实我这里看起来不是icon为nil的问题,而是在调用(doom-modeline-propertize-icon icon face)的时候,不知道中间发生了什么,导致还没进到这个函数里面去执行就已经出错了。我也不知道是不是doom那边的一些advice或者hook的问题。不过我改成直接使用时居然能正常work,但是其他地方还在使用这个函数

(if icon
            (when-let ((props (get-text-property 0 'face icon)))
              (when (listp props)
                (cl-destructuring-bind (&key family height inherit :allow-other-keys) props
                  (propertize icon 'face `(:inherit (doom-modeline ,(or face inherit props))
                                           :family ,(or family "")
                                           :height ,(or height 1.0))))))
          "")))
blithefeng commented 1 year ago
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
   propertize(nil help-echo "LSP Connected [gopls:1888/starting]\nC-mouse-1: Swi..." mouse-face doom-modeline-highlight local-map (keymap (mode-line keymap (mouse-3 . lsp-workspace-restart) (mouse-2 . lsp-works$
   doom-modeline-update-lsp()
   run-hooks(lsp-before-initialize-hook)
   lsp--start-workspace(#s(lsp-session :folders ("~/Workspace/playground/gotest") :folders-blacklist nil :server-id->folders #<hash-table equal 0/65 0x1ff5caa2e07d> :folder->servers #<hash-table $
   lsp--start-connection(#s(lsp-session :folders ("~/Workspace/playground/gotest") :folders-blacklist nil :server-id->folders #<hash-table equal 0/65 0x1ff5caa2e07d> :folder->servers #<hash-table$
   #f(compiled-function (client) #<bytecode 0x1ae5a3ddf7144946>)(#s(lsp--client :language-id "go" :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace) #<by$
   mapcar(#f(compiled-function (client) #<bytecode 0x1ae5a3ddf7144946>) (#s(lsp--client :language-id "go" :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspa$
   -map(#f(compiled-function (client) #<bytecode 0x1ae5a3ddf7144946>) (#s(lsp--client :language-id "go" :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn workspace$
   lsp--ensure-lsp-servers(#s(lsp-session :folders ("~/Workspace/playground/gotest") :folders-blacklist nil :server-id->folders #<hash-table equal 0/65 0x1ff5caa2e07d> :folder->servers #<hash-tab$
   lsp--try-project-root-workspaces(nil nil)
   lsp()
   lsp--init-if-visible()
   #f(compiled-function () #<bytecode 0x73f1a6b086c831>)()
   apply(#f(compiled-function () #<bytecode 0x73f1a6b086c831>) nil)
   timer-event-handler([t 0 0 0 nil #f(compiled-function () #<bytecode 0x73f1a6b086c831>) nil idle 0 nil])

这个不知道对你有没有帮助

seagle0128 commented 1 year ago

@blithefeng 能用 emacs -Q 重现下吗?如果是doom内部改了什么就不好定位了。你提供的backtrace就是icon为nil(虽然我认为这是不可能的),所以我加了一层保护。如果这样还是这个错误就奇怪了。

HouzuoGuo commented 1 year ago

I'm still experiencing this issue after doom-modeline to https://github.com/seagle0128/doom-modeline/commit/259ff6a1862b9860f9280f940fe949562766e62b

Error during redisplay: (eval (doom-modeline-segment--modals)) signaled (wrong-type-argument stringp nil) [42 times]
Projectile project root has been force-set to "/google/src/cloud/howardguo/uni-filter/google3/production/automation/autodash/" in workspace "uni-filter"
Error during redisplay: (eval (doom-modeline-segment--modals)) signaled (wrong-type-argument stringp nil) [5 times]
run-hooks: Wrong type argument: stringp, nilError during redisplay: (eval (doom-modeline-segment--modals)) signaled (wrong-type-argument stringp nil)
Error during redisplay: (eval (doom-modeline-segment--modals)) signaled (wrong-type-argument stringp nil) [26 times]

BTW, my emacs runs in a terminal instead of a graphical window, in case that helps.

See https://pastebin.com/6rUJSTCQ for the system information, there are also more details in https://github.com/doomemacs/doomemacs/issues/7367

seagle0128 commented 1 year ago

@HouzuoGuo Are you using doom-emacs? Can you please reproduce with emacs -Q? I couldn't reproduce on macOS and Linux.

blithefeng commented 1 year ago

@seagle0128 我写了简单的init.el

;; -*- lexical-binding: t -*-

(require 'package)
(setq package-archives '(("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
                         ("gnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")))

(setq package-enable-at-startup nil)
(package-initialize)

(package-refresh-contents)

(unless (package-installed-p 'compat)
  (package-install 'compat))

(unless (package-installed-p 'nerd-icons)
  (package-install 'nerd-icons))

(unless (package-installed-p 'doom-modeline)
  (package-install 'doom-modeline))

(require 'doom-modeline)
(doom-modeline-mode 1)

然后终端启动是有图标的 image

blithefeng commented 1 year ago

@seagle0128 @HouzuoGuo In doom-emacs modules/ui/modeline/config.el, there is a advice

(defadvice! +modeline-disable-icon-in-daemon-a (fn &rest args)
    :around #'doom-modeline-propertize-icon
    (when (display-graphic-p)
      (apply fn args)))

I disable this and It works! This advice results doom-modeline-propertize-icon returns nil in terminal.

HouzuoGuo commented 1 year ago

@blithefeng many thanks!

seagle0128 commented 1 year ago

如果非要加advice,其实更应该override doom-modeline-icon-displayable-p,或者直接不安装nerd-icons。但是nerd-icons既然支持terminal,为什么不用呢? 😄 给doom提issue吧