4
4
5
5
import logging
6
6
from functools import lru_cache
7
- import pkg_resources
7
+ from typing import List , Mapping , Sequence , Union
8
8
9
+ import pkg_resources
9
10
import pluggy
11
+ from pluggy ._hooks import HookImpl
10
12
11
13
from pylsp import _utils , hookspecs , uris , PYLSP
12
14
16
18
DEFAULT_CONFIG_SOURCES = ['pycodestyle' ]
17
19
18
20
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
+
19
39
class Config :
20
40
def __init__ (self , root_uri , init_opts , process_id , capabilities ):
21
41
self ._root_path = uris .to_fs_path (root_uri )
@@ -39,7 +59,7 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
39
59
except ImportError :
40
60
pass
41
61
42
- self ._pm = pluggy . PluginManager (PYLSP )
62
+ self ._pm = PluginManager (PYLSP )
43
63
self ._pm .trace .root .setwriter (log .debug )
44
64
self ._pm .enable_tracing ()
45
65
self ._pm .add_hookspecs (hookspecs )
0 commit comments