joaotavora / eglot

A client for Language Server Protocol servers
GNU General Public License v3.0
2.21k stars 203 forks source link

Error when creating second Python code block in polymode #1229

Closed fast-90 closed 1 year ago

fast-90 commented 1 year ago

Summary

Eglot works fine in a single Python block in polymode, however creating a second Python block results in an error.

If eglot reconnect is invoked after the creation of the second block (with the cursor in the block), then it starts to work as expected again until another block is created.

Not sure if related to #1085, however my setup is different so think it's good to separate the discussion for now.

Setup used:

Please let me know if I need to provide additional details to investigate.

Reports

eglot-events-buffer ``` [internal] Sun Jun 4 15:59:36 2023: (:message "Running language server: /Users/duynguyen/.local/bin/pylsp") [client-request] (id:1) Sun Jun 4 15:59:36 2023: (:jsonrpc "2.0" :id 1 :method "initialize" :params (:processId 17951 :rootPath "/Users/duynguyen/repos/myfunc/" :rootUri "file:///Users/duynguyen/repos/myfunc" :initializationOptions #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :capabilities (:workspace (:applyEdit t :executeCommand (:dynamicRegistration :json-false) :workspaceEdit (:documentChanges t) :didChangeWatchedFiles (:dynamicRegistration t) :symbol (:dynamicRegistration :json-false) :configuration t :workspaceFolders t) :textDocument (:synchronization (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t) :completion (:dynamicRegistration :json-false :completionItem (:snippetSupport :json-false :deprecatedSupport t :tagSupport (:valueSet [1])) :contextSupport t) :hover (:dynamicRegistration :json-false :contentFormat ["markdown" "plaintext"]) :signatureHelp (:dynamicRegistration :json-false :signatureInformation (:parameterInformation (:labelOffsetSupport t) :activeParameterSupport t)) :references (:dynamicRegistration :json-false) :definition (:dynamicRegistration :json-false :linkSupport t) :declaration (:dynamicRegistration :json-false :linkSupport t) :implementation (:dynamicRegistration :json-false :linkSupport t) :typeDefinition (:dynamicRegistration :json-false :linkSupport t) :documentSymbol (:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t :symbolKind (:valueSet [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26])) :documentHighlight (:dynamicRegistration :json-false) :codeAction (:dynamicRegistration :json-false :codeActionLiteralSupport (:codeActionKind (:valueSet ["quickfix" "refactor" "refactor.extract" "refactor.inline" "refactor.rewrite" "source" "source.organizeImports"])) :isPreferredSupport t) :formatting (:dynamicRegistration :json-false) :rangeFormatting (:dynamicRegistration :json-false) :rename (:dynamicRegistration :json-false) :publishDiagnostics (:relatedInformation :json-false :codeDescriptionSupport :json-false :tagSupport (:valueSet [1 2]))) :experimental #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ())) :workspaceFolders [(:uri "file:///Users/duynguyen/repos/myfunc" :name "~/repos/myfunc/")])) [server-reply] (id:1) Sun Jun 4 15:59:37 2023: (:jsonrpc "2.0" :id 1 :result (:capabilities (:codeActionProvider t :codeLensProvider (:resolveProvider :json-false) :completionProvider (:resolveProvider t :triggerCharacters ["."]) :documentFormattingProvider t :documentHighlightProvider t :documentRangeFormattingProvider t :documentSymbolProvider t :definitionProvider t :executeCommandProvider (:commands ["pylsp_rope.quickfix.generate" "pylsp_rope.refactor.introduce_parameter" "pylsp_rope.refactor.extract.method" "pylsp_rope.refactor.extract.variable" "pylsp_rope.refactor.inline" "pylsp_rope.refactor.local_to_field" "pylsp_rope.refactor.method_to_method_object" "pylsp_rope.refactor.use_function" "pylsp_rope.source.organize_import"]) :hoverProvider t :referencesProvider t :renameProvider t :foldingRangeProvider t :signatureHelpProvider (:triggerCharacters ["(" "," "="]) :textDocumentSync (:change 2 :save (:includeText t) :openClose t) :workspace (:workspaceFolders (:supported t :changeNotifications t)) :experimental nil) :serverInfo (:name "pylsp" :version "1.7.2"))) [client-notification] Sun Jun 4 15:59:37 2023: (:jsonrpc "2.0" :method "initialized" :params #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ())) [client-notification] Sun Jun 4 15:59:37 2023: (:jsonrpc "2.0" :method "textDocument/didOpen" :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md" :version 0 :languageId "python" :text "```{python}\nprint(\"Hello!\")\n```"))) [client-notification] Sun Jun 4 15:59:37 2023: (:jsonrpc "2.0" :method "workspace/didChangeConfiguration" :params (:settings #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()))) [server-notification] Sun Jun 4 15:59:38 2023: (:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params (:uri "file:///Users/duynguyen/repos/myfunc/mre.md" :diagnostics [(:range (:start (:line 0 :character 1) :end (:line 0 :character 2)) :message "SyntaxError: Got unexpected token `" :severity 1 :code "E999" :source "ruff" :tags []) (:source "mypy" :range (:start (:line 0 :character 0) :end (:line 0 :character 1000)) :message "mypy: can't read file '/Users/duynguyen/repos/myfunc/mre.md': No such file or directory\n" :severity 1)])) [client-notification] Sun Jun 4 15:59:45 2023: (:jsonrpc "2.0" :method "textDocument/didChange" :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md" :version 4) :contentChanges [(:range (:start (:line 5 :character 1) :end (:line 5 :character 1)) :rangeLength 0 :text "r") (:range (:start (:line 5 :character 2) :end (:line 5 :character 2)) :rangeLength 0 :text "i") (:range (:start (:line 5 :character 3) :end (:line 5 :character 3)) :rangeLength 0 :text "n") (:range (:start (:line 5 :character 4) :end (:line 5 :character 4)) :rangeLength 0 :text "t")])) [client-request] (id:2) Sun Jun 4 15:59:45 2023: (:jsonrpc "2.0" :id 2 :method "textDocument/signatureHelp" :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md") :position (:line 5 :character 5))) [client-request] (id:3) Sun Jun 4 15:59:45 2023: (:jsonrpc "2.0" :id 3 :method "textDocument/hover" :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md") :position (:line 5 :character 5))) [client-request] (id:4) Sun Jun 4 15:59:45 2023: (:jsonrpc "2.0" :id 4 :method "textDocument/documentHighlight" :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md") :position (:line 5 :character 5))) [stderr] 2023-06-04 15:59:46,031 CEST - WARNING - pylsp.config.config - Failed to load hook pylsp_signature_help: `line` parameter is not in a valid range. [stderr] Traceback (most recent call last): [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pylsp/config/config.py", line 33, in _hookexec [stderr] return self._inner_hookexec(hook_name, methods, kwargs, firstresult) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 327, in traced_hookexec [stderr] return outcome.get_result() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result [stderr] raise ex[1].with_traceback(ex[2]) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 33, in from_call [stderr] result = func() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 324, in [stderr] lambda: oldcall(hook_name, hook_impls, kwargs, firstresult) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall [stderr] return outcome.get_result() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result [stderr] raise ex[1].with_traceback(ex[2]) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall [stderr] res = hook_impl.function(*args) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pylsp/plugins/signature.py", line 20, in pylsp_signature_help [stderr] signatures = document.jedi_script().get_signatures(**code_position) [stderr] File "/Users/duynguyen/.pyenv/versions/3.10.5/lib/python3.10/site-packages/jedi/api/helpers.py", line 473, in wrapper [stderr] raise ValueError('`line` parameter is not in a valid range.') [stderr] ValueError: `line` parameter is not in a valid range. [server-reply] (id:2) Sun Jun 4 15:59:46 2023: (:jsonrpc "2.0" :id 2 :result []) [stderr] 2023-06-04 15:59:46,033 CEST - WARNING - pylsp.config.config - Failed to load hook pylsp_hover: `line` parameter is not in a valid range. [stderr] Traceback (most recent call last): [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pylsp/config/config.py", line 33, in _hookexec [stderr] return self._inner_hookexec(hook_name, methods, kwargs, firstresult) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 327, in traced_hookexec [stderr] return outcome.get_result() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result [stderr] raise ex[1].with_traceback(ex[2]) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 33, in from_call [stderr] result = func() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 324, in [stderr] lambda: oldcall(hook_name, hook_impls, kwargs, firstresult) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall [stderr] return outcome.get_result() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result [stderr] raise ex[1].with_traceback(ex[2]) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall [stderr] res = hook_impl.function(*args) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pylsp/plugins/hover.py", line 14, in pylsp_hover [stderr] definitions = document.jedi_script(use_document_path=True).infer(**code_position) [stderr] File "/Users/duynguyen/.pyenv/versions/3.10.5/lib/python3.10/site-packages/jedi/api/helpers.py", line 473, in wrapper [stderr] raise ValueError('`line` parameter is not in a valid range.') [stderr] ValueError: `line` parameter is not in a valid range. [stderr] 2023-06-04 15:59:46,034 CEST - WARNING - pylsp.config.config - Failed to load hook pylsp_document_highlight: `line` parameter is not in a valid range. [stderr] Traceback (most recent call last): [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pylsp/config/config.py", line 33, in _hookexec [stderr] return self._inner_hookexec(hook_name, methods, kwargs, firstresult) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 327, in traced_hookexec [stderr] return outcome.get_result() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result [stderr] raise ex[1].with_traceback(ex[2]) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 33, in from_call [stderr] result = func() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_manager.py", line 324, in [stderr] lambda: oldcall(hook_name, hook_impls, kwargs, firstresult) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall [stderr] return outcome.get_result() [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result [stderr] raise ex[1].with_traceback(ex[2]) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall [stderr] res = hook_impl.function(*args) [stderr] File "/Users/duynguyen/.local/lib/python3.10/site-packages/pylsp/plugins/highlight.py", line 13, in pylsp_document_highlight [stderr] usages = document.jedi_script().get_references(**code_position) [stderr] File "/Users/duynguyen/.pyenv/versions/3.10.5/lib/python3.10/site-packages/jedi/api/helpers.py", line 473, in wrapper [stderr] raise ValueError('`line` parameter is not in a valid range.') [stderr] ValueError: `line` parameter is not in a valid range. [internal] (id:3) Sun Jun 4 15:59:55 2023: (:timed-out :textDocument/hover :id 3 :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md") :position (:line 5 :character 5))) [internal] (id:4) Sun Jun 4 15:59:55 2023: (:timed-out :textDocument/documentHighlight :id 4 :params (:textDocument (:uri "file:///Users/duynguyen/repos/myfunc/mre.md") :position (:line 5 :character 5))) ```
Backtrace ``` Debugger entered--Lisp error: (wrong-type-argument plistp []) plist-member([] :signatures) #f(compiled-function (jsonrpc-lambda-elem10) #)([]) jsonrpc-connection-receive(# (:jsonrpc "2.0" :id 2 :result [])) jsonrpc--process-filter(# "Content-Length: 36\15\nContent-Type: application/vscode-jsonrpc; charset=utf8\15\n\15\n{\"jsonrpc\":\"2.0\",\"id\":2,\"result\":[]}Content-Length: 49\15\nContent-Type: application/vscode-jsonrpc; charset=utf8\15\n\15\n{\"jsonrpc\":\"2.0\",\"id\":3,\"result\":{\"contents\":\"\"}}Content-Length: 38\15\nContent-Type: application/vscode-jsonrpc; charset=utf8\15\n\15\n{\"jsonrpc\":\"2.0\",\"id\":4,\"result\":null}") ```

MRE recipe (tested with emacs -Q)

  1. Ensure the pylsp LSP is installed via pip install and available in path.
  2. In Emacs, require the following packages: eglot, python and poly-markdown (available on MELPA).
Example config ```elisp (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) (package-refresh-contents) (package-install 'poly-markdown) (require 'poly-markdown) (require 'python) (require 'eglot) ```
  1. Create a new markdown file (e.g. mre.md) with the following content:
```{python}
print("Hello!")

4. With cursor in the above `python` block, do `M-x eglot`. The LSP server should start correctly.
5. Under the `python` block above, try to add another block, e.g.

````md
```{python}
print("World!")

6. Get the following error: `error in process filter: Wrong type argument: plistp`
fast-90 commented 1 year ago

After some further searching I found https://github.com/polymode/polymode/issues/305#issuecomment-1018700437 and found a way to fix this issue in my config by adding the following lines:

  (add-to-list 'polymode-run-these-after-change-functions-in-other-buffers 'eglot--after-change)
  (add-to-list 'polymode-run-these-before-change-functions-in-other-buffers 'eglot--before-change)

I'm not sure whether this is something that needs be fixed in Eglot (or Polymode) or whether it is just something users have to put in their config, however since my issue is solved for now I'm happy to close this one. Feel free to open again if you think it needs addressing in Eglot.