1717
1818# Eol chars accepted by the LSP protocol
1919# the ordering affects performance
20- EOL_CHARS = [' \r \n ' , ' \r ' , ' \n ' ]
20+ EOL_CHARS = [" \r \n " , " \r " , " \n " ]
2121EOL_REGEX = re .compile (f'({ "|" .join (EOL_CHARS )} )' )
2222
2323log = logging .getLogger (__name__ )
2424
2525
2626def debounce (interval_s , keyed_by = None ):
2727 """Debounce calls to this function until interval_s seconds have passed."""
28+
2829 def wrapper (func ):
2930 timers = {}
3031 lock = threading .Lock ()
@@ -48,7 +49,9 @@ def run():
4849 timer = threading .Timer (interval_s , run )
4950 timers [key ] = timer
5051 timer .start ()
52+
5153 return debounced
54+
5255 return wrapper
5356
5457
@@ -78,7 +81,9 @@ def find_parents(root, path, names):
7881 # Search each of /a/b/c, /a/b, /a
7982 while dirs :
8083 search_dir = os .path .join (* dirs )
81- existing = list (filter (os .path .exists , [os .path .join (search_dir , n ) for n in names ]))
84+ existing = list (
85+ filter (os .path .exists , [os .path .join (search_dir , n ) for n in names ])
86+ )
8287 if existing :
8388 return existing
8489 dirs .pop ()
@@ -92,11 +97,11 @@ def path_to_dot_name(path):
9297 directory = os .path .dirname (path )
9398 module_name , _ = os .path .splitext (os .path .basename (path ))
9499 full_name = [module_name ]
95- while os .path .exists (os .path .join (directory , ' __init__.py' )):
100+ while os .path .exists (os .path .join (directory , " __init__.py" )):
96101 this_directory = os .path .basename (directory )
97102 directory = os .path .dirname (directory )
98103 full_name = [this_directory ] + full_name
99- return '.' .join (full_name )
104+ return "." .join (full_name )
100105
101106
102107def match_uri_to_workspace (uri , workspaces ):
@@ -128,6 +133,7 @@ def merge_dicts(dict_a, dict_b):
128133
129134 If override_nones is True, then
130135 """
136+
131137 def _merge_dicts_ (a , b ):
132138 for key in set (a .keys ()).union (b .keys ()):
133139 if key in a and key in b :
@@ -143,15 +149,16 @@ def _merge_dicts_(a, b):
143149 yield (key , a [key ])
144150 elif b [key ] is not None :
145151 yield (key , b [key ])
152+
146153 return dict (_merge_dicts_ (dict_a , dict_b ))
147154
148155
149156def escape_plain_text (contents : str ) -> str :
150157 """
151158 Format plain text to display nicely in environments which do not respect whitespaces.
152159 """
153- contents = contents .replace (' \t ' , ' \u00A0 ' * 4 )
154- contents = contents .replace (' ' , ' \u00A0 ' * 2 )
160+ contents = contents .replace (" \t " , " \u00A0 " * 4 )
161+ contents = contents .replace (" " , " \u00A0 " * 2 )
155162 return contents
156163
157164
@@ -160,17 +167,17 @@ def escape_markdown(contents: str) -> str:
160167 Format plain text to display nicely in Markdown environment.
161168 """
162169 # escape markdown syntax
163- contents = re .sub (r' ([\\*_#[\]])' , r' \\\1' , contents )
170+ contents = re .sub (r" ([\\*_#[\]])" , r" \\\1" , contents )
164171 # preserve white space characters
165172 contents = escape_plain_text (contents )
166173 return contents
167174
168175
169176def wrap_signature (signature ):
170- return ' ```python\n ' + signature + ' \n ```\n '
177+ return " ```python\n " + signature + " \n ```\n "
171178
172179
173- SERVER_SUPPORTED_MARKUP_KINDS = {' markdown' , ' plaintext' }
180+ SERVER_SUPPORTED_MARKUP_KINDS = {" markdown" , " plaintext" }
174181
175182
176183def choose_markup_kind (client_supported_markup_kinds : List [str ]):
@@ -181,10 +188,12 @@ def choose_markup_kind(client_supported_markup_kinds: List[str]):
181188 for kind in client_supported_markup_kinds :
182189 if kind in SERVER_SUPPORTED_MARKUP_KINDS :
183190 return kind
184- return ' markdown'
191+ return " markdown"
185192
186193
187- def format_docstring (contents : str , markup_kind : str , signatures : Optional [List [str ]] = None ):
194+ def format_docstring (
195+ contents : str , markup_kind : str , signatures : Optional [List [str ]] = None
196+ ):
188197 """Transform the provided docstring into a MarkupContent object.
189198
190199 If `markup_kind` is 'markdown' the docstring will get converted to
@@ -195,33 +204,24 @@ def format_docstring(contents: str, markup_kind: str, signatures: Optional[List[
195204 to the provided contents of the docstring if given.
196205 """
197206 if not isinstance (contents , str ):
198- contents = ''
207+ contents = ""
199208
200- if markup_kind == ' markdown' :
209+ if markup_kind == " markdown" :
201210 try :
202211 value = docstring_to_markdown .convert (contents )
203- return {
204- 'kind' : 'markdown' ,
205- 'value' : value
206- }
212+ return {"kind" : "markdown" , "value" : value }
207213 except docstring_to_markdown .UnknownFormatError :
208214 # try to escape the Markdown syntax instead:
209215 value = escape_markdown (contents )
210216
211217 if signatures :
212- value = wrap_signature (' \n ' .join (signatures )) + ' \n \n ' + value
218+ value = wrap_signature (" \n " .join (signatures )) + " \n \n " + value
213219
214- return {
215- 'kind' : 'markdown' ,
216- 'value' : value
217- }
220+ return {"kind" : "markdown" , "value" : value }
218221 value = contents
219222 if signatures :
220- value = '\n ' .join (signatures ) + '\n \n ' + value
221- return {
222- 'kind' : 'plaintext' ,
223- 'value' : escape_plain_text (value )
224- }
223+ value = "\n " .join (signatures ) + "\n \n " + value
224+ return {"kind" : "plaintext" , "value" : escape_plain_text (value )}
225225
226226
227227def clip_column (column , lines , line_number ):
@@ -230,7 +230,9 @@ def clip_column(column, lines, line_number):
230230
231231 https://microsoft.github.io/language-server-protocol/specification#position
232232 """
233- max_column = len (lines [line_number ].rstrip ('\r \n ' )) if len (lines ) > line_number else 0
233+ max_column = (
234+ len (lines [line_number ].rstrip ("\r \n " )) if len (lines ) > line_number else 0
235+ )
234236 return min (column , max_column )
235237
236238
@@ -242,14 +244,16 @@ def position_to_jedi_linecolumn(document, position):
242244 """
243245 code_position = {}
244246 if position :
245- code_position = {'line' : position ['line' ] + 1 ,
246- 'column' : clip_column (position ['character' ],
247- document .lines ,
248- position ['line' ])}
247+ code_position = {
248+ "line" : position ["line" ] + 1 ,
249+ "column" : clip_column (
250+ position ["character" ], document .lines , position ["line" ]
251+ ),
252+ }
249253 return code_position
250254
251255
252- if os .name == 'nt' :
256+ if os .name == "nt" :
253257 import ctypes
254258
255259 kernel32 = ctypes .windll .kernel32
0 commit comments