20
20
21
21
try :
22
22
from codesearch import CodeSearch , CompoundRequest , SearchRequest , \
23
- XrefSearchRequest , CallGraphRequest , EdgeEnumKind , XrefSearchResponse , \
23
+ XrefSearchRequest , CallGraphRequest , KytheXrefKind , XrefSearchResponse , \
24
24
AnnotationType , AnnotationTypeValue , NoSourceRootError , \
25
- InstallTestRequestHandler
25
+ InstallTestRequestHandler , XrefNode
26
26
from render .render import RenderCompoundResponse , RenderNode , LocationMapper , DisableConcealableMarkup
27
27
except ImportError :
28
- vim .command ('echoerr "{}"' .format (r"""Can't import 'codesearch' module.
28
+ vim .command ('echoerr "{}"' .format ("""\
29
+ Can't import 'codesearch' module.
29
30
30
31
Looks like the 'codesearch-py' module can't be located. This is pulled into the
31
32
vim-codesearch plugin via Git Submodules. In case your package manager didn't
@@ -55,7 +56,8 @@ def inner_call_wrapper(*args, **kwargs):
55
56
return default
56
57
except NoSourceRootError :
57
58
vim .command ('echoerr "{}"' .format (
58
- r"""Couldn't determine Chromium source location.
59
+ """\
60
+ Couldn't determine Chromium source location.
59
61
60
62
In order to show search results and link to corresponding files in the working
61
63
directory, this plugin needs to know the location of your Chromium checkout.
@@ -383,18 +385,21 @@ def GetCallers():
383
385
if not hasattr (c , 'file_path' ) or not hasattr (c , 'call_site_range' ):
384
386
continue
385
387
lines .append ('{}:{}:{}: {}' .format (
386
- os .path .join (cs .GetSourceRoot (), c .file_path ), c .call_site_range .
387
- start_line , c .call_site_range .start_column , c .display_name ))
388
+ os .path .join (cs .GetSourceRoot (), c .file_path ), c .call_site_range .start_line , c .call_site_range .start_column , c .display_name ))
388
389
return '\n ' .join (lines )
389
390
390
391
391
392
def _XrefSearchResultsToQuickFixList (cs , results ):
392
393
lines = []
394
+ assert isinstance (results , list )
393
395
for r in results :
394
- for m in r .match :
396
+ assert isinstance (r , XrefNode )
397
+ if not hasattr (r .single_match , 'line_number' ) or not hasattr (r .single_match , 'line_text' ):
398
+ continue
399
+ filepath = os .path .join (cs .GetSourceRoot (), r .filespec .name )
395
400
lines .append ('{}:{}:1: {}' .format (
396
- os . path . join ( cs . GetSourceRoot () , r .file . name ), m .line_number ,
397
- m .line_text ))
401
+ filepath , r .single_match .line_number ,
402
+ r . single_match .line_text ))
398
403
return lines
399
404
400
405
@@ -404,7 +409,8 @@ def _GetLocationsForXrefType(t):
404
409
return []
405
410
406
411
cs = _GetCodeSearch ()
407
- results = cs .GetXrefsFor (signature , [t ])
412
+ node = XrefNode .FromSignature (cs , signature )
413
+ results = node .Traverse (t )
408
414
return _XrefSearchResultsToQuickFixList (cs , results )
409
415
410
416
@@ -413,24 +419,32 @@ def _GetCallTargets():
413
419
if not signature :
414
420
return []
415
421
cs = _GetCodeSearch ()
416
- results = cs .GetCallTargets (signature )
422
+ node = XrefNode .FromSignature (cs , signature )
423
+ dcl_list = node .Traverse ([KytheXrefKind .DECLARATION , KytheXrefKind .DEFINITION ])
424
+ if len (dcl_list ) == 0 :
425
+ return []
426
+
427
+ overrides = []
428
+ for dcl in dcl_list :
429
+ overrides .extend (dcl .Traverse (KytheXrefKind .OVERRIDDEN_BY ))
430
+
431
+ results = dcl_list + overrides
417
432
return _XrefSearchResultsToQuickFixList (cs , results )
418
433
419
434
420
435
REFERENCE_TYPES = {
421
- 'call' : EdgeEnumKind .CALL ,
422
- 'called at' : EdgeEnumKind .CALLED_AT ,
423
- 'caller' : EdgeEnumKind .CALLED_AT ,
424
- 'declaration' : EdgeEnumKind .HAS_DECLARATION ,
425
- 'definition' : EdgeEnumKind .HAS_DEFINITION ,
426
- 'extended by' : EdgeEnumKind .EXTENDED_BY ,
427
- 'extends' : EdgeEnumKind .EXTENDS ,
428
- 'instantiations' : EdgeEnumKind .INSTANTIATED_AT ,
429
- 'overridden by' : EdgeEnumKind .OVERRIDDEN_BY ,
430
- 'overrides' : EdgeEnumKind .OVERRIDES ,
431
- 'references' : EdgeEnumKind .REFERENCED_AT ,
432
- 'subclasses' : EdgeEnumKind .EXTENDED_BY ,
433
- 'superclasses' : EdgeEnumKind .EXTENDS ,
436
+ 'called at' : KytheXrefKind .CALLED_BY ,
437
+ 'caller' : KytheXrefKind .CALLED_BY ,
438
+ 'declaration' : KytheXrefKind .DECLARATION ,
439
+ 'definition' : KytheXrefKind .DEFINITION ,
440
+ 'extended by' : KytheXrefKind .EXTENDED_BY ,
441
+ 'extends' : KytheXrefKind .EXTENDS ,
442
+ 'instantiations' : KytheXrefKind .INSTANTIATION ,
443
+ 'overridden by' : KytheXrefKind .OVERRIDDEN_BY ,
444
+ 'overrides' : KytheXrefKind .OVERRIDES ,
445
+ 'references' : KytheXrefKind .REFERENCE ,
446
+ 'subclasses' : KytheXrefKind .EXTENDED_BY ,
447
+ 'superclasses' : KytheXrefKind .EXTENDS ,
434
448
'call targets' : _GetCallTargets ,
435
449
}
436
450
0 commit comments