Skip to content
This repository was archived by the owner on Oct 31, 2021. It is now read-only.

Commit 7d08637

Browse files
authored
Merge pull request #9 from chromium/kythe-migration
Catch up with backend changes due to Kythe migration
2 parents 179860a + f30e52c commit 7d08637

File tree

5 files changed

+69
-47
lines changed

5 files changed

+69
-47
lines changed

autoload/crcs.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ function! crcs#SetupCodesearchBuffer(bufname, dirname, buftype)
100100
endif
101101

102102
if a:buftype ==# 'call'
103-
syn region csNode concealends matchgroup=csConceal start=/\^N{/ end=/}N_/ contains=csNode,csExpander,csSymbol,csMarkedupCode nextgroup=csExpander transparent
103+
syn region csNode concealends matchgroup=csConceal start=/\^N{/ end=/}N_/ contains=csNode,csExpander,csSymbol,csMarkedupCode,csFilename nextgroup=csExpander transparent
104104
syn match csExpander /\[[-+\*]\]/ nextgroup=csSymbol
105-
syn region csSymbol concealends matchgroup=csConceal start=/\^S{/ end=/}S_/ contained
105+
syn region csSymbol concealends matchgroup=csConceal start=/\^S{/ end=/}S_/ nextgroup=csFilename contained
106+
syn region csFilename concealends matchgroup=csConceal start=/\^F{/ end=/}F_/ contains=NONE nextgroup=csMarkedupCode
106107

107108
hi def link csExpander Special
108109
hi def link csSymbol Directory

render/render.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ def JumpTargetAt(self, line, column):
9494
line -= 1
9595
column -= 1
9696
if line not in self.jump_map_:
97-
line = max([l for l in self.jump_map_.keys() if l < line])
97+
candidates = [l for l in self.jump_map_.keys() if l < line]
98+
if len(candidates) == 0:
99+
return None
100+
line = max(candidates)
98101
filename, target_line, offset_column = self.jump_map_[line]
99102
if offset_column < column:
100103
overhead = CountBlockMarkupOverhead(
@@ -285,14 +288,14 @@ def __init__(self, name, order):
285288
self.bin = []
286289

287290
collectors = {
288-
cs.EdgeEnumKind.HAS_DEFINITION: Bin('Definition', 1),
289-
cs.EdgeEnumKind.HAS_DECLARATION: Bin('Declaration', 2),
290-
cs.EdgeEnumKind.CALLED_AT: Bin('Calls', 3),
291-
cs.EdgeEnumKind.INSTANTIATED_AT: Bin('Instantiations', 4),
292-
cs.EdgeEnumKind.OVERRIDDEN_BY: Bin('Overridden by', 5),
293-
cs.EdgeEnumKind.OVERRIDES: Bin('Overrides', 6),
294-
cs.EdgeEnumKind.EXTENDED_BY: Bin('Extended by', 7),
295-
cs.EdgeEnumKind.EXTENDS: Bin('Extends', 8),
291+
cs.KytheXrefKind.DEFINITION: Bin('Definition', 1),
292+
cs.KytheXrefKind.DECLARATION: Bin('Declaration', 2),
293+
cs.KytheXrefKind.CALLED_BY: Bin('Calls', 3),
294+
cs.KytheXrefKind.INSTANTIATION: Bin('Instantiations', 4),
295+
cs.KytheXrefKind.OVERRIDDEN_BY: Bin('Overridden by', 5),
296+
cs.KytheXrefKind.OVERRIDES: Bin('Overrides', 6),
297+
cs.KytheXrefKind.EXTENDED_BY: Bin('Extended by', 7),
298+
cs.KytheXrefKind.EXTENDS: Bin('Extends', 8),
296299

297300
# Everything else.
298301
0: Bin('References', 100)
@@ -345,10 +348,10 @@ def RenderNode(mapper, node, level):
345348
with TaggedBlock(mapper, 'N'):
346349
# Rendered text looks like:
347350
#
348-
# [-] namespace::Bar()
351+
# [-] namespace::Bar() (filename.cc)
349352
# 38 InvokeBaz(1, 2, true);
350353
#
351-
# [+] Quux()
354+
# [+] Quux() (filename.cc)
352355
# 10 Bar()
353356
#
354357

@@ -364,15 +367,19 @@ def RenderNode(mapper, node, level):
364367
indent=' ' * (level * NODE_INDENT), expander=expander))
365368

366369
# Symbol
367-
with TaggedBlock(mapper, 'S'):
368-
if hasattr(node, 'call_scope_range'):
369-
start_line = node.call_scope_range.start_line
370-
elif hasattr(node, 'call_site_range'):
371-
start_line = node.call_site_range.start_line
372-
else:
373-
start_line = 1
374-
mapper.SetTargetForPos(node.file_path, start_line)
375-
mapper.write(AbbreviateCppSymbol(node.display_name))
370+
if hasattr(node, 'file_path') and hasattr(node, 'identifier'):
371+
with TaggedBlock(mapper, 'S'):
372+
if hasattr(node, 'call_scope_range'):
373+
start_line = node.call_scope_range.start_line
374+
elif hasattr(node, 'call_site_range'):
375+
start_line = node.call_site_range.start_line
376+
else:
377+
start_line = 1
378+
mapper.SetTargetForPos(node.file_path, start_line)
379+
mapper.write(AbbreviateCppSymbol(node.identifier))
380+
mapper.write(' ')
381+
with TaggedBlock(mapper, 'F'):
382+
mapper.write(node.file_path)
376383

377384
# Render snippet
378385
if hasattr(node, 'snippet') and hasattr(node, 'snippet_file_path'):

third_party/codesearch-py

Submodule codesearch-py updated 111 files

vimsupport.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020

2121
try:
2222
from codesearch import CodeSearch, CompoundRequest, SearchRequest, \
23-
XrefSearchRequest, CallGraphRequest, EdgeEnumKind, XrefSearchResponse, \
23+
XrefSearchRequest, CallGraphRequest, KytheXrefKind, XrefSearchResponse, \
2424
AnnotationType, AnnotationTypeValue, NoSourceRootError, \
25-
InstallTestRequestHandler
25+
InstallTestRequestHandler, XrefNode
2626
from render.render import RenderCompoundResponse, RenderNode, LocationMapper, DisableConcealableMarkup
2727
except ImportError:
28-
vim.command('echoerr "{}"'.format(r"""Can't import 'codesearch' module.
28+
vim.command('echoerr "{}"'.format("""\
29+
Can't import 'codesearch' module.
2930
3031
Looks like the 'codesearch-py' module can't be located. This is pulled into the
3132
vim-codesearch plugin via Git Submodules. In case your package manager didn't
@@ -55,7 +56,8 @@ def inner_call_wrapper(*args, **kwargs):
5556
return default
5657
except NoSourceRootError:
5758
vim.command('echoerr "{}"'.format(
58-
r"""Couldn't determine Chromium source location.
59+
"""\
60+
Couldn't determine Chromium source location.
5961
6062
In order to show search results and link to corresponding files in the working
6163
directory, this plugin needs to know the location of your Chromium checkout.
@@ -383,18 +385,21 @@ def GetCallers():
383385
if not hasattr(c, 'file_path') or not hasattr(c, 'call_site_range'):
384386
continue
385387
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))
388389
return '\n'.join(lines)
389390

390391

391392
def _XrefSearchResultsToQuickFixList(cs, results):
392393
lines = []
394+
assert isinstance(results, list)
393395
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)
395400
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))
398403
return lines
399404

400405

@@ -404,7 +409,8 @@ def _GetLocationsForXrefType(t):
404409
return []
405410

406411
cs = _GetCodeSearch()
407-
results = cs.GetXrefsFor(signature, [t])
412+
node = XrefNode.FromSignature(cs, signature)
413+
results = node.Traverse(t)
408414
return _XrefSearchResultsToQuickFixList(cs, results)
409415

410416

@@ -413,24 +419,32 @@ def _GetCallTargets():
413419
if not signature:
414420
return []
415421
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
417432
return _XrefSearchResultsToQuickFixList(cs, results)
418433

419434

420435
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,
434448
'call targets': _GetCallTargets,
435449
}
436450

File renamed without changes.

0 commit comments

Comments
 (0)