ccls icon indicating copy to clipboard operation
ccls copied to clipboard

Getting a callgraph in standalone mode

Open iensen opened this issue 8 months ago • 2 comments

Is there a way to obtain a callgraph in standalone mode?

I tried to run the following:

evgenii@pop-os:~/Software/ccls/Release$ ccls '--init={"cache":{"directory":"/home/evgenii/ccls_project/.ccls_cache","retainInMemory":0},"compilationDatabaseDirectory":"/home/evgenii/ccls_project/","index":{"initialNoLinkage":false,"threads":10,"trackDependency":0}}'
Content-Length: 225

{"jsonrpc":"2.0","method":"$ccls/call","params":{"textDocument":{"uri":"file:///home/evgenii/ccls_project/main.cpp"},"position":{"line":9,"character":8},"callee":false,"callType":3,"qualified":true,"hierarchy":true},"id":107}


But this returns an error: {"jsonrpc":"2.0","id":107,"error":{"code":-32600,"message":"/home/evgenii/ccls_project/main.cpp is not opened"}}

I realized it's because the file is not opened, so I tried to add didOpen notification:

ccls '--init={"cache":{"directory":"/home/evgenii/ccls_project/.ccls_cache","retainInMemory":0},"compilationDatabaseDirectory":"/home/evgenii/ccls_project/","index":{"initialNoLinkage":false,"threads":10,"trackDependency":0}}'
Content-Length: 286

{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument": {"uri": "file:///home/evgenii/ccls_project/main.cpp", "languageId": "cpp", "version": 0, "text": "#include<stdio.h>\nint f2() {\n  return 0;\n}\nint f1() {\nreturn f2();\n}\n\nint main() {\n  return f1();\n}"}}}

However this just returns another error:

ccls: ./src/pipeline.cc:560: ccls::pipeline::launchStdin()::<lambda()>: Assertion !document->HasParseError()' failed.

`

I don't see anything wrong with my jsonrpc request. Any idea? Here is my main.cpp:

#include<stdio.h>

int f2() {
  return 0;
}

int f1() {
return f2();
}

int main() {
  return f1();
}

iensen avatar Apr 18 '25 21:04 iensen

Is there a way to obtain a callgraph in standalone mode?

If you implement a minimum client to calls initialize and didOpen, I think it is doable... You might get reply.error(ErrorCode::InvalidRequest, "not indexed"); when ccls hasn't indexed the requested file.

ccls: ./src/pipeline.cc:560: ccls::pipeline::launchStdin()::<lambda()>: Assertion !document->HasParseError()' failed.

Seems that the input message is not valid JSON...

MaskRay avatar Apr 19 '25 01:04 MaskRay

@MaskRay

Thank you! It makes sense. I realized I am missing "initialize".

I haven't got it to work yet, but I think I can, given enough time :)

I think it would be of a great help to provide an example of a 'minimum client' like you mentioned. I am using emacs with ccls server but I also would like to implement some tools outside of emacs to do some reports/statistics on the codebase. Since I already have the ccls project and cache I thought I could reuse it.

Feel free to close the issue if there is no further action planned on your side. I will update the thread when/if I get the minimum client to work.

iensen avatar Apr 22 '25 13:04 iensen