44
55import logging
66from functools import lru_cache
7- import pkg_resources
7+ from typing import List , Mapping , Sequence , Union
88
9+ import pkg_resources
910import pluggy
11+ from pluggy ._hooks import HookImpl
1012
1113from pylsp import _utils , hookspecs , uris , PYLSP
1214
1618DEFAULT_CONFIG_SOURCES = ['pycodestyle' ]
1719
1820
21+ class PluginManager (pluggy .PluginManager ):
22+
23+ def _hookexec (
24+ self ,
25+ hook_name : str ,
26+ methods : Sequence [HookImpl ],
27+ kwargs : Mapping [str , object ],
28+ firstresult : bool ,
29+ ) -> Union [object , List [object ]]:
30+ # called from all hookcaller instances.
31+ # enable_tracing will set its own wrapping function at self._inner_hookexec
32+ try :
33+ return self ._inner_hookexec (hook_name , methods , kwargs , firstresult )
34+ except Exception as e : # pylint: disable=broad-except
35+ log .warning (f"Failed to load hook { hook_name } : { e } " )
36+ return []
37+
38+
1939class Config :
2040 def __init__ (self , root_uri , init_opts , process_id , capabilities ):
2141 self ._root_path = uris .to_fs_path (root_uri )
@@ -39,7 +59,7 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
3959 except ImportError :
4060 pass
4161
42- self ._pm = pluggy . PluginManager (PYLSP )
62+ self ._pm = PluginManager (PYLSP )
4363 self ._pm .trace .root .setwriter (log .debug )
4464 self ._pm .enable_tracing ()
4565 self ._pm .add_hookspecs (hookspecs )
0 commit comments