Git Product home page Git Product logo

Comments (4)

sam-mccall avatar sam-mccall commented on June 2, 2024

Formally speaking, a function can only have one definition (or none). This is what clangd returns: the definition if it's visible or indexed, otherwise the declaration.

Showing overrides of a virtual member function is a useful feature, and one we should certainly support somehow. We need to add more info to the index for this.

(There's a pending patch adding base-derived relationships to the index, we should be able to reuse that structure. So let's wait until that lands).

This seems like a better fit for lsp's textDocument/implementations method than for definition to me. The main counterargument i can see is that's a fairly new and unclear piece of the protocol, and many more editors support go to definition. I'm not sure that's a strong enough argument to stretch its semantics though.

from clangd.

smhc avatar smhc commented on June 2, 2024

The 'definition' command does support returning a list of locations. Some documentation does refer to an overridden virtual function as a 're-definition'. Regardless, the behaviour needs to be in the spec and agreed upon. Interestingly I couldn't find any mention of this problem in the LSP spec or associated project.

I have only found mention in the cquery LSP, which implements a "$cquery/derived" command for listing derived classes or virtual function overloads - which I assume does what I am referring to.

From a UI perspective you likely only want one command to jump to the best candidate implementation for a given function, regardless of whether there are overrides or not (sometimes this can be statically determined, other times not. I'm unsure if clang has this capability). Jumping to the base declaration and then another command to list all overrides might be a bit of a hassle when trying to navigate around a code base. Although I suppose an LSP client could do this automatically for you if it knew when it was appropriate.

I have worked on some code which uses pure virtual functions in base classes for almost all functions. This is done to better support unit testing. Unfortunately navigating this code base is quite difficult with an LSP as 'goto definition' almost always takes you to the base class declaration instead of what you are are really interested in.

from clangd.

sam-mccall avatar sam-mccall commented on June 2, 2024

Happy to revisit this when #29 (textDocument/implementation) is implemented.

from clangd.

sam-mccall avatar sam-mccall commented on June 2, 2024

This is done now (for pure virtual methods only, and find-implementation works on all virtual methods)

from clangd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.