Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter hints for call to overloaded function #172

Closed
HighCommander4 opened this issue Oct 2, 2019 · 17 comments
Closed

Parameter hints for call to overloaded function #172

HighCommander4 opened this issue Oct 2, 2019 · 17 comments

Comments

@HighCommander4
Copy link

In the following code:

void foo(int);
void foo(std::string);

void bar() {
   foo/*cursor*/
}

If I invoke completion with the cursor at the indicated location, I get a single entry that says

foo(...)    [2 overloads]

It would be nicer to show the two overloads as separate entries, so I can see the signature for each, pick the one I want to call, and then get parameter hints for the selected function's parameters.

@kadircet
Copy link
Member

kadircet commented Oct 2, 2019

Once you put parentheses, you should get a signature help showing both.

Also you can change the behaviour by passing --completion-style=detailed into clangd. But IIRC, we are only turning this to bundled in the presence of signature help functionality.

@HighCommander4
Copy link
Author

Once you put parentheses, you should get a signature help showing both.

I tried this, but I get the same result ([2 overloads]) with or without parentheses.

@HighCommander4
Copy link
Author

I can confirm that using --completion-style=detailed gives the desired behaviour.

@HighCommander4
Copy link
Author

HighCommander4 commented Oct 3, 2019

I am using VSCode as a client. Does this suggest that clangd is expecting VSCode to do something more helpful, that it's not doing?

@HighCommander4
Copy link
Author

Ok, I see: VSCode has a separate command ("Trigger Parameter Hints", shortcut Ctrl+Shift+Space) which shows the individual signatures when activated. I was expecting that to activate automatically when the completion entry is selected, but it looks like it doesn't.

I think this is just a case of sub-optimal usability on the client side then. I still prefer the --completion-styled=detailed behaviour, because you might as well see all the signatures up-front, but I guess that's what the flag is for.

@LeeProkhor
Copy link

How can I set --completion-style=detailed on Ubuntu? Where is conf file?

@HighCommander4
Copy link
Author

How can I set --completion-style=detailed on Ubuntu? Where is conf file?

It's a command-line argument to clangd. The method of setting it depends on the client. For vscode, it can be added to "clangd.arguments" in the vscode user or workspace settings.

@LeeProkhor
Copy link

Thanks, I use neovim and installed clangd using by kabouzeid/nvim-lspinstall plugin.
In my .config/nvim/init.lua file I added nvim-lspconfig and nvim-compe plugins for C++ coding, they work OK,
but if method has several overloads (say 3 overloads as on picture below) I can't expand them.
If I understood right, I should set --completion-style=detailed [ (https://github.com//issues/172) ]
but I can't figure out where is clangd config-file, where I have to add --completion-style=detailed ("clangd.arguments")
overloads

@HighCommander4
Copy link
Author

HighCommander4 commented Jun 27, 2021

It's not going to be a clangd config file, it's going to be a neovim-related config file.

I'm not really familiar with neovim, but a quick read of the nvim-lspconfig readme suggests the file to specify the language server setup is "init.vim".

@HighCommander4
Copy link
Author

Looking at example config snippets in e.g. this issue, it looks like the snippet you'll want is something like:

require'lspconfig'.clangd.setup {
  cmd = { "clangd", "--completion-style=detailed" }
}

@LeeProkhor
Copy link

LeeProkhor commented Jun 28, 2021

Thanks, tried it. Don't have any errors, but still not expand overloaded methods.

@HighCommander4
Copy link
Author

Can you share clangd logs? That should at least allow us to confirm that clangd is seeing the command-line parameter.

@LeeProkhor
Copy link

I am afraid my system doesn't have clangd logs, cause I installed clangd not from repos, but via kabouzeid/nvim-lspinstall plugin.
So I can't find where is clangd logs placed even.

@LeeProkhor
Copy link

I found where is clangd log on my machine. It was in ~/.cache/nvim/lsp.log
Here is my log

lsp.log

@HighCommander4
Copy link
Author

HighCommander4 commented Jul 9, 2021

Ok, so the important line is this one near the top:

[ ERROR ] 2021-07-09T15:14:23+0300 ] /usr/local/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ] "rpc" "/home/rock/.local/share/nvim/lspinstall/cpp/./clangd/bin/clangd" "stderr" "I[15:14:23.122] Working directory: /home/rock/.local/share/nvim/lspinstall/cpp\nI[15:14:23.122] argv[0]: /home/rock/.local/share/nvim/lspinstall/cpp/./clangd/bin/clangd\nI[15:14:23.122] argv[1]: --background-index\nI[15:14:23.154] Starting LSP over stdin/stdout\n"

Clangd is being started with the --background-index command-line argument, but not --completion-style=detailed.

So, whatever you did to configure --completion-style=detailed didn't take effect.

@LeeProkhor
Copy link

Thanks HighCommander4.
I added this code:

require'lspconfig'.clangd.setup {
  cmd = { "clangd", "--completion-style=detailed" } 
}

to my ~/.config/nvim/init.lua file, but it looks like there isn't any effect.

@HighCommander4
Copy link
Author

HighCommander4 commented Jul 10, 2021

Yup, I understand. I tried to figure out how to configure neovim to provide a command-line argument to clangd based on their documentation, and that's what I came up with, but clearly I'm missing something.

I suggest you ask for further help from people who are actually familar with neovim, such as in the https://github.com/neovim/nvim-lspconfig issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants