1
- from LSP .plugin .core .typing import Any , Dict , Literal , Set , Union
2
- from LSP .plugin .core .url import uri_to_filename
1
+ from LSP .plugin .core .typing import Any , Callable , Dict , Literal , Optional , Set
2
+ from LSP .plugin import uri_to_filename
3
+ from LSP .plugin import WorkspaceFolder
4
+ from lsp_utils import notification_handler
3
5
from lsp_utils import NpmClientHandler
6
+ from lsp_utils import request_handler
4
7
import os
5
- import posixpath
6
8
import re
7
9
import sublime
8
10
import webbrowser
9
11
10
12
11
- def plugin_loaded ():
13
+ def plugin_loaded () -> None :
12
14
LspEslintPlugin .setup ()
13
15
14
16
15
- def plugin_unloaded ():
17
+ def plugin_unloaded () -> None :
16
18
LspEslintPlugin .cleanup ()
17
19
18
20
@@ -21,61 +23,55 @@ class LspEslintPlugin(NpmClientHandler):
21
23
server_directory = 'language-server'
22
24
server_binary_path = os .path .join (server_directory , 'out' , 'eslintServer.js' )
23
25
24
- @classmethod
25
- def install_in_cache (cls ) -> bool :
26
- return False
27
-
28
26
def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
29
27
super ().__init__ (* args , ** kwargs )
30
28
self ._probe_failed = set () # type: Set[str]
31
29
32
- def on_ready (self , api ) -> None :
33
- api .on_notification ('eslint/status' , self .handle_status )
34
- api .on_notification ('eslint/exitCalled' , self .handle_exit_called )
35
- api .on_notification ('eslint/showOutputChannel' , self .handle_show_output_channel )
36
- api .on_request ('eslint/openDoc' , self .handle_open_doc )
37
- api .on_request ('eslint/probeFailed' , self .handle_probe_failed )
38
- api .on_request ('eslint/noConfig' , self .handle_no_config )
39
- api .on_request ('eslint/noLibrary' , self .handle_no_library )
40
- api .on_request ('eslint/confirmESLintExecution' , self .handle_confirm_execution )
41
-
42
- def handle_status (self , params ) -> None :
30
+ @notification_handler ('eslint/status' )
31
+ def handle_status (self , params : Any ) -> None :
43
32
pass
44
33
45
- def handle_exit_called (self , params ) -> None :
34
+ @notification_handler ('eslint/exitCalled' )
35
+ def handle_exit_called (self , params : Any ) -> None :
46
36
pass
47
37
48
- def handle_show_output_channel (self , params ) -> None :
38
+ @notification_handler ('eslint/showOutputChannel' )
39
+ def handle_show_output_channel (self , params : Any ) -> None :
49
40
sublime .active_window ().run_command ('lsp_toggle_server_panel' )
50
41
51
- def handle_open_doc (self , params , respond ) -> None :
42
+ @request_handler ('eslint/openDoc' )
43
+ def handle_open_doc (self , params : Any , respond : Callable [[Any ], None ]) -> None :
52
44
webbrowser .open (params ['url' ])
53
45
respond ({})
54
46
55
- def handle_probe_failed (self , params , respond ) -> None :
47
+ @request_handler ('eslint/probeFailed' )
48
+ def handle_probe_failed (self , params : Any , respond : Callable [[Any ], None ]) -> None :
56
49
self ._probe_failed .add (params ['textDocument' ]['uri' ])
57
50
respond (None )
58
51
59
- def handle_no_config (self , params , respond ) -> None :
52
+ @request_handler ('eslint/noConfig' )
53
+ def handle_no_config (self , params : Any , respond : Callable [[Any ], None ]) -> None :
60
54
# TODO: Show better notification that no eslint configuration was found.
61
55
print ('LSP-eslint: Could not find eslint configuration ({}) for {}' .format (
62
56
params ['message' ], params ['document' ]['uri' ]))
63
57
respond (None )
64
58
65
- def handle_no_library (self , params , respond ) -> None :
59
+ @request_handler ('eslint/noLibrary' )
60
+ def handle_no_library (self , params : Any , respond : Callable [[Any ], None ]) -> None :
66
61
# TODO: Show better notification that no eslint library was found.
67
62
print ('LSP-eslint: Failed resolving eslint library for {}' .format (params ['source' ]['uri' ]))
68
63
respond (None )
69
64
70
- def handle_confirm_execution (self , params , respond ) -> None :
65
+ @request_handler ('eslint/confirmESLintExecution' )
66
+ def handle_confirm_execution (self , params : Any , respond : Callable [[Any ], None ]) -> None :
71
67
respond (4 ) # ConfirmExecutionResult.approved
72
68
73
- def on_workspace_configuration (self , params , configuration ) -> None :
69
+ def on_workspace_configuration (self , params : Any , configuration : Dict ) -> None :
74
70
session = self .weaksession ()
75
71
if session :
76
72
scope_uri = params .get ('scopeUri' )
77
73
if scope_uri :
78
- workspace_folder = None
74
+ workspace_folder = None # type: Optional[WorkspaceFolder]
79
75
for folder in session .get_workspace_folders ():
80
76
if folder .includes_uri (scope_uri ):
81
77
workspace_folder = folder
@@ -90,7 +86,8 @@ def on_workspace_configuration(self, params, configuration) -> None:
90
86
configuration ['validate' ] = 'on'
91
87
del configuration ['probe' ]
92
88
93
- def resolve_working_directory (self , configuration , scope_uri , workspace_folder ) -> None :
89
+ def resolve_working_directory (self , configuration : Dict , scope_uri : str ,
90
+ workspace_folder : Optional [WorkspaceFolder ]) -> None :
94
91
working_directories = configuration .get ('workingDirectories' , None )
95
92
if isinstance (working_directories , list ):
96
93
working_directory = None
@@ -132,25 +129,27 @@ def resolve_working_directory(self, configuration, scope_uri, workspace_folder)
132
129
configuration ['workingDirectory' ] = working_directory
133
130
configuration .pop ('workingDirectories' , None )
134
131
135
- def is_working_directory_item (self , item , configuration_key ) -> bool :
132
+ def is_working_directory_item (self , item : Any , configuration_key : str ) -> bool :
136
133
if isinstance (item , dict ):
137
134
value = item .get (configuration_key , None )
138
135
not_cwd = item .get ('!cwd' , None )
139
136
return isinstance (value , str ) and (isinstance (not_cwd , bool ) or not_cwd is None )
140
137
return False
141
138
142
- def is_mode_item (self , item ) -> bool :
139
+ def is_mode_item (self , item : Any ) -> bool :
143
140
if isinstance (item , dict ):
144
141
mode = item .get ('mode' , None )
145
142
return isinstance (mode , str ) and mode in ('auto' , 'location' )
146
143
return False
147
144
148
- def to_os_path (self , path ) -> str :
145
+ def to_os_path (self , path : str ) -> str :
149
146
if sublime .platform == 'windows' :
150
147
path = re .sub (r'^\/(\w)\/' , r'\1:\\' , path )
151
148
return os .path .normpath (path )
152
149
153
- def compute_validate (self , language_id : str , scope_uri : str , config : Dict [str , Any ]) -> Literal ['off' , 'on' , 'probe' ]:
150
+ def compute_validate (
151
+ self , language_id : str , scope_uri : str , config : Dict [str , Any ]
152
+ ) -> Literal ['off' , 'on' , 'probe' ]:
154
153
validate = config .get ('validate' )
155
154
if isinstance (validate , list ):
156
155
for validate_langugage_id in validate :
@@ -162,5 +161,5 @@ def compute_validate(self, language_id: str, scope_uri: str, config: Dict[str, A
162
161
if isinstance (probe , list ):
163
162
for probe_language_id in probe :
164
163
if probe_language_id == language_id :
165
- return 'probe' ;
166
- return 'off' ;
164
+ return 'probe'
165
+ return 'off'
0 commit comments