emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.73k stars 865 forks source link

lsp-mode set global-mode-string as buffer local in python mode, results in no org-mode-line-string in mode line #2987

Open wztdream opened 3 years ago

wztdream commented 3 years ago

Thank you for the bug report

Bug description

The issue is that some times there is no org-clock in mode-line for python mode. This issue is originally reported in doom-mode-line, and finally it turns out should due to lsp-mode.

Steps to reproduce

Here is how you can reproduce it:

  1. open emacs
  2. install doom-mode-line
  3. open a .py file
  4. clock in a task, then there is no org-clock. The value of global-mode-string is:
    ((t
    (:eval lsp-modeline--code-actions-string))
    (t
    (:eval
    (lsp-modeline--diagnostics-update-modeline)))
    (t
    (:eval
    (-keep #'lsp--workspace-status-string
          (lsp-workspaces)))))
    Local in buffer test.py; global value is 
    ("" org-mode-line-string)

    It is set as a buffer local value, the global value is shadowed then, so there is no org-clock. By watching the value of global-mode-string it shows this buffer local value is set by lsp-mode, so I report this issue here, hope can solve it.

    Debugger entered--setting global-mode-string in buffer test.py to ((t (:eval lsp-modeline--code-actions-string)) (t (:eval (lsp-modeline--diagnostics-update-modeline)))): 
    debug--implement-debug-watch(global-mode-string ((t (:eval lsp-modeline--code-actions-string)) (t (:eval (lsp-modeline--diagnostics-update-modeline)))) set #<buffer test.py>)
    add-to-list(global-mode-string (t (:eval lsp-modeline--code-actions-string)))
    lsp-modeline-code-actions-mode()
    run-hooks(lsp-configure-hook)
    lsp-configure-buffer()
    lsp-managed-mode(1)
    lsp--text-document-did-open()
    lsp--open-in-workspace(#s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 14/14 0x158ea758ac69> :registered-server-capabilities (#s(lsp--registered-capability :id "169bbe02-c1f1-43be-a4b0-62539361faed" :method "workspace/didChangeWatchedFiles" :options #<hash-table equal 1/1 0x158ea839b0cd>) #s(lsp--registered-capability :id "55d01b1f-f1dc-4bd0-9a60-1aac3ace1bc9" :method "workspace/didChangeWorkspaceFolders" :options #<hash-table equal 0/1 0x158ea7e0e9ed>)) :root "/home/wangzongtao/test" :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn) #<bytecode 0x158ea90db43d>) :test\? #f(compiled-function () #<bytecode 0x158ea90db449>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x158ea91179d1> :request-handlers #<hash-table equal 0/65 0x158ea822b49d> :response-handlers #<hash-table eql 1/65 0x158ea8570275> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x158ea8615d91> :action-handlers #<hash-table equal 0/65 0x158ea861cda9> :major-modes (python-mode) :activation-fn nil :priority 3 :server-id pyright :multi-root t :initialization-options nil :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn #f(compiled-function (workspace) #<bytecode 0x158ea9090749>) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x158ea861f305> :download-server-fn #f(compiled-function (client callback error-callback update\?) #<bytecode 0x158ea9090755>) :download-in-progress? nil :buffers nil) :host-root nil :proc #<process pyright> :cmd-proc #<process pyright> :buffers (#<buffer test.py>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x158ea7e07cc1> :watches #<hash-table equal 0/65 0x158ea89a2821> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x158ea8f3a9d9> :work-done-tokens #<hash-table equal 0/65 0x158ea9d853b9>))
    #f(compiled-function (buffer) #<bytecode 0x158ea75af835>)(#<buffer test.py>)
    mapc(#f(compiled-function (buffer) #<bytecode 0x158ea75af835>) (#<buffer test.py>))
    #f(compiled-function (response) #<bytecode 0x158eaa30d991>)(#<hash-table equal 1/1 0x158ea758ac35>)
    #f(compiled-function (result) #<bytecode 0x158ea8f0a8bd>)(#<hash-table equal 1/1 0x158ea758ac35>)
    #f(compiled-function (result) #<bytecode 0x158ea8f0a8c9>)(#<hash-table equal 1/1 0x158ea758ac35>)
    lsp--parser-on-message(#<hash-table equal 3/3 0x158ea758abdd> #s(lsp--workspace :ewoc nil :server-capabilities #<hash-table equal 14/14 0x158ea758ac69> :registered-server-capabilities (#s(lsp--registered-capability :id "169bbe02-c1f1-43be-a4b0-62539361faed" :method "workspace/didChangeWatchedFiles" :options #<hash-table equal 1/1 0x158ea839b0cd>) #s(lsp--registered-capability :id "55d01b1f-f1dc-4bd0-9a60-1aac3ace1bc9" :method "workspace/didChangeWorkspaceFolders" :options #<hash-table equal 0/1 0x158ea7e0e9ed>)) :root "/home/wangzongtao/test" :client #s(lsp--client :language-id nil :add-on? nil :new-connection (:connect #f(compiled-function (filter sentinel name environment-fn) #<bytecode 0x158ea90db43d>) :test\? #f(compiled-function () #<bytecode 0x158ea90db449>)) :ignore-regexps nil :ignore-messages nil :notification-handlers #<hash-table equal 3/65 0x158ea91179d1> :request-handlers #<hash-table equal 0/65 0x158ea822b49d> :response-handlers #<hash-table eql 1/65 0x158ea8570275> :prefix-function nil :uri-handlers #<hash-table equal 0/65 0x158ea8615d91> :action-handlers #<hash-table equal 0/65 0x158ea861cda9> :major-modes (python-mode) :activation-fn nil :priority 3 :server-id pyright :multi-root t :initialization-options nil :semantic-tokens-faces-overrides nil :custom-capabilities nil :library-folders-fn nil :before-file-open-fn nil :initialized-fn #f(compiled-function (workspace) #<bytecode 0x158ea9090749>) :remote? nil :completion-in-comments? nil :path->uri-fn nil :uri->path-fn nil :environment-fn nil :after-open-fn nil :async-request-handlers #<hash-table equal 0/65 0x158ea861f305> :download-server-fn #f(compiled-function (client callback error-callback update\?) #<bytecode 0x158ea9090755>) :download-in-progress? nil :buffers nil) :host-root nil :proc #<process pyright> :cmd-proc #<process pyright> :buffers (#<buffer test.py>) :semantic-tokens-faces nil :semantic-tokens-modifier-faces nil :extra-client-capabilities nil :status initialized :metadata #<hash-table equal 0/65 0x158ea7e07cc1> :watches #<hash-table equal 0/65 0x158ea89a2821> :workspace-folders nil :last-id 0 :status-string nil :shutdown-action nil :diagnostics #<hash-table equal 1/65 0x158ea8f3a9d9> :work-done-tokens #<hash-table equal 0/65 0x158ea9d853b9>))
    #f(compiled-function (msg) #<bytecode 0x158ea75af5ad>)(#<hash-table equal 3/3 0x158ea758abdd>)
    mapc(#f(compiled-function (msg) #<bytecode 0x158ea75af5ad>) (#<hash-table equal 3/3 0x158ea6c1b109> #<hash-table equal 3/3 0x158ea758aab9> #<hash-table equal 3/3 0x158ea758abdd>))
    #f(compiled-function (proc input) #<bytecode 0x158ea75ddf11>)(#<process pyright> "Content-Length: 119\15\n\15\n{\"jsonrpc\":\"2.0\",\"method\":\"...")

If I clock in first then open any .py file, the org-clock shows in mode-line, and the value of global-mode-string is:

Value:
((t
  (:eval lsp-modeline--code-actions-string))
 (t
  (:eval
   (lsp-modeline--diagnostics-update-modeline)))
 (t
  (:eval
   (-keep #'lsp--workspace-status-string
          (lsp-workspaces))))
 "" org-mode-line-string)
Local in buffer test.py; global value is 
("" org-mode-line-string)

Note that org-mode-line-string is added to buffer local setting, so seems lsp-mode need update the value of buffer local value for global-mode-string after clock-in or some other command

Expected behavior

update global-mode-string after org-clock-in` or other related commands that need show information in modeline

Which Language Server did you use?

lsp-pyright

OS

Linux

Error callstack

No response

Anything else?

No response

yyoncho commented 3 years ago

Note that org-mode-line-string is added to buffer local setting, so seems lsp-mode need update the value of buffer local value for global-mode-string after clock-in or some other command

I don't see how that can happen considering that global-mode-string can be changed after lsp-mode. The issue will be fixed once we go away from global-mode-string as part of https://github.com/emacs-lsp/lsp-mode/issues/2571

wztdream commented 3 years ago

I double checked spacemacs-mode-line it can show org-clock correctly when there is no org-mode-line-string in buffer local global-mode-string, so seems doom-mode-line should consider show both buffer local and global value. I mentioned this in doom-mode-line too.