eclipse-cdt / cdt-lsp

Eclipse CDT™ LSP Extensions for CDT
Eclipse Public License 2.0
23 stars 11 forks source link

Show variable references in call hierarchy #272

Open i-garrison opened 4 months ago

i-garrison commented 4 months ago

Currently CDT editor can show references to variable reads and writes annotated in call hierarchy.

Please add this feature to CDT LSP plugin. Since read and write access to variable is visible in function body provided by LSP it should technically be possible to bind these to function call hierarchies.

Lack of this feature can be partially worked around by wrapping variables into read/write accessor functions, but there are downsides:

ghentschke commented 4 months ago

Is this what you mean: image

i-garrison commented 4 months ago

Yes this is what I'd like to have with CDT-LSP plugin too. Both r/w marking and also access to counter in foo call hierarchy.

ghentschke commented 4 months ago

Please be aware of that the call hierarchy is (currently) limited to function calls. See this clangd issue

i-garrison commented 4 months ago

Yes clangd does not provide that out of the box, still this can be implemented similar to what CDT editor does: it gets all variable references, finds containing functions and then stitches these to form displayed call tree. Would imagine it should be possible with CDT LSP plugin to do similar thing; you probably can store reference to function body for each variable reference and then while scanning for references build a tree going up from that function asking LSP for callers. Detecting if particular variable reference is read or write should be doable too.

ghentschke commented 4 months ago

Would imagine it should be possible with CDT LSP plugin to do similar thing

IMO a better solution would be to fix it on the server side. That's what its made and used for.

i-garrison commented 4 months ago

Would imagine it should be possible with CDT LSP plugin to do similar thing

IMO a better solution would be to fix it on the server side. That's what its made and used for.

Yes LSP server-side implementation is an option too, but looking at referenced clangd issue I do not think it will be available in clangd any time soon.