Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when creating second Python code block in polymode #1229

Closed
fast-90 opened this issue Jun 4, 2023 · 1 comment
Closed

Error when creating second Python code block in polymode #1229

fast-90 opened this issue Jun 4, 2023 · 1 comment

Comments

@fast-90
Copy link

fast-90 commented Jun 4, 2023

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:

  • Server used: pylsp (issue also observed for pyright)
  • Emacs version: 29.0.9
  • Operating system: MacOS

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 <lambda>
[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 <lambda>
[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 <lambda>
[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) #<bytecode -0xf1e331c7291c2e7>)([])
  jsonrpc-connection-receive(#<eglot-lsp-server eglot-lsp-server-1ff72ef7075a> (:jsonrpc "2.0" :id 2 :result []))
  jsonrpc--process-filter(#<process EGLOT (myfunc/python-mode)> "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
(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!")
```
  1. With cursor in the above python block, do M-x eglot. The LSP server should start correctly.
  2. Under the python block above, try to add another block, e.g.
```{python}
print("World!")
```
  1. Get the following error: error in process filter: Wrong type argument: plistp
@fast-90 fast-90 changed the title Error when creating second Python code block in polymode (using pylsp server) Error when creating second Python code block in polymode Jun 4, 2023
@fast-90
Copy link
Author

fast-90 commented Jun 19, 2023

After some further searching I found polymode/polymode#305 (comment) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant