Comments (4)
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.
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.
Happy to revisit this when #29 (textDocument/implementation) is implemented.
from clangd.
This is done now (for pure virtual methods only, and find-implementation works on all virtual methods)
from clangd.
Related Issues (20)
- clangd-indexer aborts while creating index file HOT 2
- Add header-insertion: never option to .clangd config HOT 3
- Template arguments in placeholder's type-constraint are not selected correctly. HOT 2
- clangd do not recognise headers located in pch HOT 2
- Call hierarchy points to an empty line HOT 3
- Issue with Clang Tools on Windows using Cygwin64 for a C++17 project with <mutex> HOT 8
- Unused header warning for placement new
- headers from pch are not recognized inside project HOT 8
- clangd does not detect C++17 or newer features when compiled with CMake 3.28 + Ninja on Windows HOT 8
- omit `self` when clangd compltes member function with explicit self HOT 4
- Include Cleaner fails for symbols forward-declared and aliased
- Include cleaner recommends removing includes needed for casts to related types
- Unsupported argument 'cortex-a76.cortex-a55' to option '-mcpu='clang(drv_unsupported_option_argument) HOT 1
- clangd find references, refactor rename works only with opened files HOT 6
- Clangd sometimes fails to deduce non-dependent type inside template HOT 3
- Clangd throws error on working code with CUDA HOT 6
- Include Cleaner doesn't include headers needed by default template arguments HOT 1
- Include Cleaner doesn't recognize uses of `operator bool`
- Include Cleaner recommends removing header needed by template instantiation
- Allocated memory is leaked HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clangd.