这个脚本质量不算很高,很多写法不规范,但是最大的问题是他根本就不能工作,而且我打开 NeoVim 后 CPU 占用飙升。好在作者给了一个 write 函数,可以勉强当日志用。确定到问题出在后面的 while 循环是死循环,cur_path变量一直是WindowsPath('e:/')。当然很容易通过计数器变量来限制循环次数,这个问题先按下不表。
观察日志输出:
1 2 3 4 5 6 7 8
No activate command found in e:\code\python\.env Loopping... cur_path=WindowsPath('e:/code/python') Loopping... cur_path=WindowsPath('e:/code') Loopping... cur_path=WindowsPath('e:/') Loopping... cur_path=WindowsPath('e:/') Loopping... cur_path=WindowsPath('e:/') Loopping... cur_path=WindowsPath('e:/') ...
[ERROR][2024-05-06 16:20:42] .../vim/lsp/rpc.lua:734 "rpc" "D:\\Anaconda\\anaconda3\\Scripts\\pylsp.exe" "stderr" '2024-05-06 16:20:42,165 中国标准时间 - WARNING - pylsp.config.config - Failed to load hook pylsp_hover: D:\\Anaconda\\anaconda3\\envs\\django\\Scripts\\python.exe seems to be missing. Traceback (most recent call last): File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pylsp\\config\\config.py", line 39, in _hookexec return self._inner_hookexec(hook_name, methods, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_manager.py", line 327, in traced_hookexec return outcome.get_result() ^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_result.py", line 60, in get_result raise ex[1].with_traceback(ex[2]) File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_result.py", line 33, in from_call result = func() ^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_manager.py", line 324, in <lambda> lambda: oldcall(hook_name, hook_impls, kwargs, firstresult) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_callers.py", line 60, in _multicall return outcome.get_result() ^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_result.py", line 60, in get_result raise ex[1].with_traceback(ex[2]) File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pluggy\\_callers.py", line 39, in _multicall res = hook_impl.function(*args) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pylsp\\plugins\\hover.py", line 14, in pylsp_hover definitions = document.jedi_script(use_document_path=True).infer(**code_position) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pylsp\\workspace.py", line 33, in wrapper return method(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pylsp\\workspace.py", line 534, in jedi_script self.get_enviroment(environment_path, env_vars=env_vars) File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\pylsp\\workspace.py", line 566, in get_enviroment environment = jedi.api.environment.create_environment( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\jedi\\api\\environment.py", line 367, in create_environment return Environment(_get_executable_path(path, safe=safe), env_vars=env_vars) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\\Anaconda\\anaconda3\\Lib\\site-packages\\jedi\\api\\environment.py", line 380, in _get_executable_path raise InvalidPythonEnvironment("%s seems to be missing." % python) jedi.api.environment.InvalidPythonEnvironment: D:\\Anaconda\\anaconda3\\envs\\django\\Scripts\\python.exe seems to be missing. '