2

I use nvim with coc and clangd as the language server on a ubuntu 22.04 machine. I mainly use it to code in c++ when I code.

What I want is to automatically generate doxygen style comments to describe classes, functions and such. The preferred way is to automatically generate the snippet when I type /// or /** in insert mode and it should be context sensitive (as in automatically get the parameter names), like visual studio does for C#.

In short, I want

  1. Integration with code completion, showing the description of stuff as it suggests the completion as it does with the standard library. At the moment, coc just dumps the comment above the function and isn't really smart about filtering things based on the cursor position and such. For example it describes what std::string is like so, and I would like that same feature for my own types and functions:

enter image description here

enter image description here

  1. Code completion for the documentation comments, such as @pa should complete to @param and then complete parameter names, preferably already suggesting the next one.

  2. Automatically generate the correct snippet when I type /**<CR> or ///<CR> in insert mode, even if there is stuff like template and/or requires in front of a function name.

  3. Integrate with the language server so that rename causes the doxygen references to that same identifier to also be renamed. For example renaming a parameter should automatically also rename the doxygen comment parameter name.

I had hoped that such a thing would be integrated with clangd's completer, but I looked here and didn't find anything. So I searched for a vim plugin, but the only thing I could find was

this 13 year old script.
But that doesn't seem to work with Plug. Or maybe it does? It doesn't have any installation instructions besides putting it into ~/.vim/plugin, and I'm not sure that works anyway. And it doesn't seem automated at all or offer any of the features I want, particularly the autocomplete hints.

EDIT
I tried installing it with Plug, then I found out that it doesn't update the comment but rather just creates a new one whenever the command is invoked.
Edit End

I also found this 9 years old question on SO. But I'd really rather just install some plugins and configure it rather than spending another day writing snippets that I don't know the syntax of. On top of that they will also not update the comments, parameter names, etc.

None of those things provide some sort of integration with the clang language server, where I would get those comments shown as I type for example a function call or get the function name completion in coc. They would also not be renamed if I used the rename refactoring offered by coc through clang.

All of those features are available in many gui applications like visual studio, code lite and even the ancient and discontinued code blocks editor. Sublime Text has the DoxyDoxygen plugin. How do I get that in nvim?

2
  • Have you actually tried any of the "didn't work" things you mention in your question?
    – Friedrich
    Jul 10 at 8:10
  • It's rather dumb in that it doesn't update existing comments with new parameter names. it just creates a new block every time.
    – FalcoGer
    Jul 10 at 15:13

1 Answer 1

1

Shameless plug. In lh-cpp/(gotoimpl_with_libclang branch) I have an updated version of my old :DOX command that generates Doxygen comments. Unlike what you're looking for, it's not interactive (e.g. comments won't be updated if you add another parameter).

It will require other plugins (see the README), python bindings of libclang, and a correct C++ code (otherwise the analysis of the function signature may fail).

Regarding LSP, indeed there is no integration as... the Language Server Protocol offers nothing related to code analysis or the generation of comments (last time I've checked). Hence the need to introduce yet-another-dependency in order to analyze function signatures.

9
  • I have tried it, but it does too much. I would like to disable some features. There is no need for syntax highlighting, I already use treesitter. I'll see how it behaves.
    – FalcoGer
    Jul 10 at 14:46
  • It doesn't seem to place nice with me. I get loads of errors, like E119: Not enough arguments for function: lh#cpp#AnalysisLib_Function#get_function_info when calling :DOX from nvim
    – FalcoGer
    Jul 10 at 14:54
  • @D.BenKnoble I don't understand. If I've typed this character it was an error. Jul 10 at 16:23
  • 1
    @LucHermitte ok, I’ve corrected in the link (see edit history). No worries.
    – D. Ben Knoble
    Jul 11 at 12:24
  • 1
    t'en fais pas :)
    – D. Ben Knoble
    Jul 11 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.