@@ -313,20 +313,7 @@ def _top_definition(self, definition):
313
313
return d
314
314
return definition
315
315
316
- def _extract_range (self , definition ):
317
- """Provides the definition range of a given definition
318
-
319
- For regular symbols it returns the start and end location of the
320
- characters making up the symbol.
321
-
322
- For scoped containers it will return the entire definition of the
323
- scope.
324
-
325
- The scope that jedi provides ends with the first character of the next
326
- scope so it's not ideal. For vscode we need the scope to end with the
327
- last character of actual code. That's why we extract the lines that
328
- make up our scope and trim the trailing whitespace.
329
- """
316
+ def _extract_range_jedi_0_9_0 (self , definition ):
330
317
from jedi import common
331
318
from jedi .parser .utils import load_parser
332
319
# get the scope range
@@ -366,6 +353,63 @@ def _extract_range(self, definition):
366
353
'end_line' : definition .line - 1 ,
367
354
'end_column' : definition .column
368
355
}
356
+
357
+ def _extract_range_jedi_0_10_1 (self , definition ):
358
+ from jedi import common
359
+ from jedi .parser .python import parse
360
+ # get the scope range
361
+ try :
362
+ if definition .type in ['class' , 'function' ]:
363
+ tree_name = definition ._name .tree_name
364
+ scope = tree_name .get_definition ()
365
+ start_line = scope .start_pos [0 ] - 1
366
+ start_column = scope .start_pos [1 ]
367
+ # get the lines
368
+ code = scope .get_code (include_prefix = False )
369
+ lines = common .splitlines (code )
370
+ # trim the lines
371
+ lines = '\n ' .join (lines ).rstrip ().split ('\n ' )
372
+ end_line = start_line + len (lines ) - 1
373
+ end_column = len (lines [- 1 ]) - 1
374
+ else :
375
+ symbol = definition ._name .tree_name
376
+ start_line = symbol .start_pos [0 ] - 1
377
+ start_column = symbol .start_pos [1 ]
378
+ end_line = symbol .end_pos [0 ] - 1
379
+ end_column = symbol .end_pos [1 ]
380
+ return {
381
+ 'start_line' : start_line ,
382
+ 'start_column' : start_column ,
383
+ 'end_line' : end_line ,
384
+ 'end_column' : end_column
385
+ }
386
+ except Exception as e :
387
+ return {
388
+ 'start_line' : definition .line - 1 ,
389
+ 'start_column' : definition .column ,
390
+ 'end_line' : definition .line - 1 ,
391
+ 'end_column' : definition .column
392
+ }
393
+
394
+ def _extract_range (self , definition ):
395
+ """Provides the definition range of a given definition
396
+
397
+ For regular symbols it returns the start and end location of the
398
+ characters making up the symbol.
399
+
400
+ For scoped containers it will return the entire definition of the
401
+ scope.
402
+
403
+ The scope that jedi provides ends with the first character of the next
404
+ scope so it's not ideal. For vscode we need the scope to end with the
405
+ last character of actual code. That's why we extract the lines that
406
+ make up our scope and trim the trailing whitespace.
407
+ """
408
+ if jedi .__version__ in ('0.9.0' , '0.10.0' ):
409
+ return self ._extract_range_jedi_0_9_0 (definition )
410
+ else :
411
+ return self ._extract_range_jedi_0_10_1 (definition )
412
+
369
413
def _get_definitionsx (self , definitions , identifier = None , ignoreNoModulePath = False ):
370
414
"""Serialize response to be read from VSCode.
371
415
0 commit comments