Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

my implementation of callHierarchy #65

Open
wellcomez opened this issue Jul 10, 2024 · 0 comments
Open

my implementation of callHierarchy #65

wellcomez opened this issue Jul 10, 2024 · 0 comments

Comments

@wellcomez
Copy link

wellcomez commented Jul 10, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant