Comments (10)
Agree, returning the type as written is nice in some cases (it's usually terse!) but is catastrophically bad for auto and... mixed at best for things like value_type
.
The YCM + libclang logic looks more sensible at first glance, we may also be able to enhance some cases further with access to the C++ API.
from clangd.
Ah, so I'd forgotten the tricky issue here.
As you've seen there's no "type information" request in LSP, just the "hover" request with as unstructured response.
I think the idea behind our current hover responses is that pretty-printing the decl gives a sense of:
- the kind of thing that's being hovered (a variable?)
- a sense of where it came from (namespace?)
- its type (int?)
- its definition (= 42)
- its documentation, maybe
But it's not doing a great job of any of these, and then we've bound the response to :YcmCompleter GetType
where users rightly expect a detailed type and nothing else.
I think we need to internally build a structured representation of the hover information, with proper detailed type info. Then we can render a nicer hover response, and probably also provide something more suitable for GetType
as an extension.
Assigning to @kadircet as he's starting to look at improving hover.
from clangd.
Yes, textDocument/Hover
is one of my least favourite parts of the protocol in general.
Here's a proposal how structuring Hover
could work:
- Return an array of
MarkedString
s - First
MarkedString
can be a dictionary{ "language": "cpp", "value": type_information }
- Every other
MarkedString
should be used for documentation (YCM'sGetDoc
)- Alternatively, instead of sending an array of strings, send one large string with embedded new lines.
That is what jdt.ls returns when both type and documentation information is available. When one of those isn't available, it might return just the dictionary or just the list of strings.
from clangd.
We'll need to make sure that as well as having accessible structure, they look good when rendered by clients naive to that structure.
There's also the issue that the MarkedString[]
response is deprecated, so a MarkupContent
might be preferable.
So another option would be to add extensions to MarkupContent like:
{
"kind": "markdown",
"value": "function ns::**foo**(v)\n\nsome doc\n\n```cpp\nvoid foo(int v);\n```",
"name": "foo",
"scope": "ns::",
"type": "void(int)",
"category": "function",
"definition": "void foo(int v);",
"documentation": "some doc",
}
That way we can still provide a nicely-formatted string and tweak the layout over time, but YCM can properly support GetType
without any brittle parsing.
Alternatively, we could hide all this extra structure in clangd and just define new methods to get at the type.
from clangd.
I don't see MarkedString
declared deprecated anywhere in the protocol specifications, even though it is older than MarkupContent
.
I'm personally not a fan of markup hover response, because the editor I care about (vim) doesn't have a markup parser (at least by default).
from clangd.
I see this on the definition of MarkedString: @deprecated use MarkupContent instead.
MarkupContent can be plain text (and will be if the client doesn't advertise markdown support via capabilities)
from clangd.
This is partially addressed in llvm/llvm-project@287a874.
I say partially because we still miss pretty printing for auto types and handling of long initializer lists.
but at least, we know print the underlying type when hovering over auto typed variables.
Note that this also changes the hover output, so with next clangd release :YcmCompleter GetType
functionality might need to be adjusted, happy to chat about it more.
from clangd.
Is there any chance to resolve the type of a lambda auto parameter?
foo([](auto p){});
Btw is this a duplicate of #58?
from clangd.
Is there any chance to resolve the type of a lambda auto parameter?
foo([](auto p){});
I believe that depends on the signature of foo
. If the parameter type is a concrete function pointer type (e.g. void(*)(int)
) and the lambda has no captures (so that it can be converted to a function pointer), then yes, we should be able to determine what the type of the instantiated parameter p
for the call will be.
It's probably worth having this case on file as a separate issue, as it's kind of a special case / not the typical case of deducing auto
from an initializer.
from clangd.
As Kadir mentioned, type information is now split out from the declaration (for quite a while now!). I think that's the core issue here, so we should close this bug.
I've opened separate bugs for the other issues raised here:
from clangd.
Related Issues (20)
- `NOLINT` directives don't work for `unused-includes` HOT 6
- Weekly snapshot releases are not being published since 20240128 HOT 6
- std::expected is unexpected disabled when parsing cpp file drivered by g++ HOT 4
- clang-tidy misreports indentation with tabs and spaces HOT 3
- Memory Leak while editing in Vim + YouCompleteMe HOT 3
- clang-format in snippets HOT 1
- Clangd running on .proto files HOT 2
- Clangd -std=gnu++23 not passed when compiling headers, even if corresponding source has that flag HOT 3
- no button add implementation in vs code HOT 4
- Inappropriate RUNPATH of clangd binary HOT 5
- Performance issue: high disk usage and long background indexing time HOT 1
- Allow clangd to be forward compatible with .clang-format files
- `clangd` still shows some `clang-tidy` warnings from inside a macro coming from a system header HOT 1
- Macro results from index have completion kind `Text` (should be `Function` or `Constant`) HOT 7
- Macro symbol does not get background-indexed HOT 1
- Clangd ignoring "-fobjc-arc"?
- ignore the macro of same line
- Debian 12 arm64 HOT 1
- Adding include through code-actions uses absolute paths
- Questions for proprietary ARM compiler system headers
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.