leodevbro / vscode-blockman

VSCode extension to highlight nested code blocks
https://github.com/leodevbro/vscode-blockman
MIT License
345 stars 16 forks source link

Enabling Blockman while viewing PySide6 function definitions causes VSCode and Pylance to hang #137

Open myuanz opened 1 month ago

myuanz commented 1 month ago

It seems to be caused by the excessive length of the PySide6 pyi files.

Environment data

Code Snippet

from PySide6.QtCore import Signal, QObject

class MyObject(QObject):
    t1 = Signal()

o = MyObject()

Repro Steps

  1. Enable blockman
  2. Open a Python project in VSCode that uses the PySide6 library
  3. Hover over QObject or any other PySide6 class/function and press F12 to go to its definition
  4. Try to go to the definition of another class/function by pressing F12 again

https://github.com/myuanz/pylance-pyside-hang/assets/25359546/578d6f25-0d52-49b6-a3ce-ee4e4b658537

Expected behavior

F12 should smoothly switch between different class/function definitions without freezing.

Actual behavior

  1. After using F12 to go to a definition in PySide6 for the first time, subsequent uses of F12 cause Pylance to hang and become unresponsive for dozens of seconds. This also affects other VSCode functionalities such as creating new files.
  2. When working in an SSH Remote environment, this issue also cause the SSH connection to drop. Remote system is Ubuntu 23.10, other softwares version is same to this issue.

Logs

Pylance log link: https://github.com/myuanz/pylance-pyside-hang/blob/master/test2.log

I'm not sure how to view the Blockman log, but there seem to be some traces in the Pylance log: https://github.com/microsoft/pylance-release/issues/5847#issuecomment-2096598931

leodevbro commented 1 month ago

Hello, thanks for the report. The thing is that Blockman uses third party libraries for parsing/tokenizing, because VS Code does not give extensions access to the native AST tokens.

For Python language, Blockman uses dt-python-parser, which is not exactly optimized for finding block start-end locations (tokens), it tokenizes everything in the Python code. And maybe it is the reason that it overanalyzes the file and causes freezing.

I will try to implement other libraries (more optimized, or more stable libraries) for parsing/tokenizing in Blockman.