clangd / vscode-clangd

Visual Studio Code extension for clangd
https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-clangd
MIT License
629 stars 106 forks source link

Please add an option to disable auto-completion like any other plugins #588

Closed lhmouse closed 6 months ago

lhmouse commented 7 months ago

This follows https://github.com/clangd/vscode-clangd/issues/390#issuecomment-1975056244 by @HighCommander4, but details about the current behavior are https://github.com/clangd/vscode-clangd/issues/390#issuecomment-1645383861 by @MK-Alias (and thanks for the screenshots!).

I have a habit of typing the immediate ( after the name of a function. Because vscode-clangd auto-completes it, I always have to remember to backspace my own parenthesis. This behavior is inconsistent with any other editor or IDE, and I am too stupid to get rid of my habit, so please provide an option to disable it. Thanks in advance.

HighCommander4 commented 7 months ago

To clarify, are you looking for an option to disable code completion altogether, or an option to disable the insertion of ( when accepting a function completion specifically?

lhmouse commented 7 months ago

To clarify, are you looking for an option to disable code completion altogether, or an option to disable the insertion of ( when accepting a function completion specifically?

I am looking for the former.

Of course, the root of the issue is the latter, but it's bundled in clangd itself. I have seen the other issue at https://github.com/llvm/llvm-project/issues/63565, and I believe it would take years to finally land into, for example, Debian stable APT repositories. On the other hand, vscode extensions can be much more actively updated.

HighCommander4 commented 7 months ago

Thanks for clarifying.

(Not sure if it's relevant in your use case, but LLVM does have a set of APT packages (including a clangd package) that are updated daily at https://apt.llvm.org.)


Since you wrote earlier:

Please add an option to disable auto-completion like any other plugins

could you give an example of another plugin (especially an LSP client plugin) which has this kind of option?

lhmouse commented 7 months ago

(Not sure if it's relevant in your use case, but LLVM does have a set of APT packages (including a clangd package) that are updated daily at https://apt.llvm.org.)

Thanks for the information. I can try it.

could you give an example of another plugin (especially an LSP client plugin) which has this kind of option?

The Microsfot C/C++ extension has an option to disable C/C++ auto-completion: 73452

The 'C/C++ Clang Command Adapter' extension also has such an option; however it parses clang output directly, instead of using a language server: 73453

HighCommander4 commented 7 months ago

Thanks. I checked the implementation of this option in vscode-cpptools (the server is proprietary but the client's source code is available). It looks like it's implemented on the server side; the value of the checkbox is just propagated to the server in the initialization options. (And I'm guessing it has the effect of the server sending an empty response to completion requests?)

So, if vscode-clangd used a simlar implementation, you would still need an updated server for the option to work.

I think it would be better to have a way of implementing the option entirely on the client side, but it's not clear to me how to accomplish this with the vscode-languageclient API.

(I looked at the vscode-clang plugin as well. There, the option is implemented entirely on the client side, but since this plugin does not use the LSP, it uses a different API surface than LSP plugins, so I don't think the way it does things is applicable to vscode-clangd.)

lhmouse commented 7 months ago

I know almost nothing about LSP; am I correct to say that auto-completion is fully controlled by the server (and not the client), and if the server sends a completion response, there is nothing we can do on the client side?

HighCommander4 commented 7 months ago

I think it would be better to have a way of implementing the option entirely on the client side, but it's not clear to me how to accomplish this with the vscode-languageclient API.

Actually, I realized this can be done relatively easily using middleware.

lhmouse commented 7 months ago

it seems this has annoyed me again. is this the case for you?

I created this file:

#include <new>
using namespace std;

void
test()
  {

  }

Now, in test(), I typed return<space> and got

#include <new>
using namespace std;

void
test()
  {
    return_temporary_buffer( )
  }

wat? please do not auto-complete that for me.

It looks like this was because I set clangd.serverCompletionRanking to false. Solved now.

HighCommander4 commented 6 months ago

Proposed patch: https://github.com/clangd/vscode-clangd/pull/591

lhmouse commented 6 months ago

Thanks!