my implementation of callHierarchy
wellcomez opened this issue · 0 comments
wellcomez commented
My implemention is used for clangd, if anyone needs, you can pull request and submit.
def callHierarchyPrepare(self, sym: SymbolInformation):
s = SymbolParser(sym)
col = s.symbol_col
line = s.symbol_line
ret = self.endpoint.call_method(
"textDocument/prepareCallHierarchy",
textDocument=TextDocumentIdentifier(uri=sym.location.uri),
position={
"character": col,
"line": line
})
ret = list(map(lambda x: PrepareReturn.create(x, sym), ret))
return ret
def workspace_symbol(self):
return self.endpoint.call_method("workspace/symbol", query="run")
def callIncoming(self, param: PrepareReturn) -> list[PrepareReturn]:
sss = dict(param)
ret = self.endpoint.call_method("callHierarchy/incomingCalls",
item=sss)
def convert(s):
try:
from_ = s["from"]
return PrepareReturn(data=from_["data"],
kind=from_["kind"],
range=Range.parse_obj(from_["range"]),
selectionRange=Range.parse_obj(
from_["selectionRange"]),
uri=from_["uri"],
name=from_["name"])
except Exception as e:
print(e)
return None
return list(filter(lambda x: x != None, map(convert, ret)))
def callHierarchyPrepare(self, sym: SymbolInformation):
s = SymbolParser(sym) # move col to begin of function name
col = s.symbol_col
line = s.symbol_line
ret = self.endpoint.call_method(
"textDocument/prepareCallHierarchy",
textDocument=TextDocumentIdentifier(uri=sym.location.uri),
position={
"character": col,
"line": line
})
ret = list(map(lambda x: PrepareReturn.create(x, sym), ret))
return ret
My code but doesn't suit for common usage
def get_caller(self, sym: Symbol, once=False):
if sym.is_call():
ctx = self.client.lsp_client.callHierarchyPrepare(sym.sym)
callser: list[CallNode] = []
for a in ctx:
c = CallNode(a)
callser.extend(self.__get_caller_next(c, once, level=0))
return callser
return []
my output look like
-> WillStartRequest /chrome/buildcef/chromium/src/components/navigation_interception/intercept_navigation_throttle.cc:30
-> CheckIfShouldIgnoreNavigation /chrome/buildcef/chromium/src/components/navigation_interception/intercept_navigation_throttle.cc:63
-> RunCheckAsync /chrome/buildcef/chromium/src/components/navigation_interception/intercept_navigation_throttle.cc:79
-> Resume /chrome/buildcef/chromium/src/content/public/browser/navigation_throttle.cc:87
-> Resume /chrome/buildcef/chromium/src/content/browser/renderer_host/navigation_request.cc:6494
-> ResumeProcessingNavigationEvent /chrome/buildcef/chromium/src/content/browser/renderer_host/navigation_throttle_runner.cc:124
-> ProcessInternal /chrome/buildcef/chromium/src/content/browser/renderer_host/navigation_throttle_runner.cc:258
-> ExecuteNavigationEvent /chrome/buildcef/chromium/src/content/browser/renderer_host/navigation_throttle_runner.cc:30
-> WillStartRequest /chrome/buildcef/chromium/src/content/public/browser/navigation_throttle.h:140