zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.59k stars 3.04k forks source link

How can I use code completion in Zed without having parameters added automatically? #15091

Closed fish1sheep closed 3 weeks ago

fish1sheep commented 3 months ago

Describe the feature

When I'm writing Python and C++ and using code completion to call a function, it includes a long list of parameters. Can I remove them? It's quite disruptive while typing.

SomeoneToIgnore commented 3 months ago

Is it a signature help pop-up you're talking about?

It could be configured via

// Show method signatures in the editor, when inside parentheses.
"auto_signature_help": false,
/// Whether to show the signature help after completion or a bracket pair inserted.
/// If `auto_signature_help` is enabled, this setting will be treated as enabled also.
"show_signature_help_after_edits": true,

settings (excerpt from the default ones).

Also, there's a cmd-i (ctrl-i) action to toggle these manually, if needed.

fish1sheep commented 3 months ago

Is it a signature help pop-up you're talking about?

It could be configured via

// Show method signatures in the editor, when inside parentheses.
"auto_signature_help": false,
/// Whether to show the signature help after completion or a bracket pair inserted.
/// If `auto_signature_help` is enabled, this setting will be treated as enabled also.
"show_signature_help_after_edits": true,

settings (excerpt from the default ones).

Also, there's a cmd-i (ctrl-i) action to toggle these manually, if needed.

When I press TAB to complete, there will be many parameters in the parentheses of the function. I just want to complete the function name instead of including the parameters. Would you like me to explain that further?

SomeoneToIgnore commented 3 months ago

I think I get it now. For the future, consider attaching a couple of screenshots or a short screen capture, that will save us a couple of paragraphs.

This is not something Zed controls (at least, yet) as the completion instructions are coming from the LSP servers.

Consider a random C++ example: image

On the left, I've completed the file_is_empty function and on the right, highlighted, are the corresponding LSP logs that the clangd language server sends is back:

// Send:
{"jsonrpc":"2.0","id":148,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///Users/someonetoignore/Downloads/llama.cpp/examples/main/main.cpp"},"position":{"line":247,"character":11},"context":{"triggerKind":3}}}

....

// Receive:
{"id":148,"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[{"detail":"bool","filterText":"file_is_empty","insertText":"file_is_empty(${1:const int &path})","insertTextFormat":2,"kind":3,"label":" file_is_empty","labelDetails":{"detail":"(const int &path)"},"score":1.4183518886566162,"sortText":"404a7372file_is_empty","textEdit":{"newText":"file_is_empty(${1:const int &path})","range":{"end":{"character":11,"line":247},"start":{"character":4,"line":247}}}}]}}

So we did request it completions, and got back something, that has to edit the original text file with

"textEdit":{"newText":"file_is_empty(${1:const int &path})","range":{"end":{"character":11,"line":247},"start":{"character":4,"line":247}}}}

and you can see that the parameters are inside there already.

I do not see anything generic, that would allow us to tell "omit the parameters" in the spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion but maybe I'm missing something.

So, your only options out of here are:

as I see nothing ready for this.

sleeping-at-night commented 3 months ago

As for C++, this feature might be corresponding to --function-arg-placeholders option when spawn clangd.

From a simple test in VS-code , I can confirm that this maybe the option for the mentioned feature. I add clangd arguments in clangd extension, as follow:

image

SomeoneToIgnore commented 3 months ago

Ok, then the last issue would be to pass it from Zed's side, which seems to be broken now? https://github.com/zed-industries/zed/issues/4295#issuecomment-2203511851

Either way, it would be worth trying this override with a custom binary and seeing if it works. It should at least attempt passing the config, according to this code: https://github.com/zed-industries/zed/blob/02ed10527ec703ef5238e3dd6052f6cf6a20685a/crates/languages/src/c.rs#L38-L51

fish1sheep commented 3 months ago

As for C++, this feature might be corresponding to --function-arg-placeholders option when spawn clangd.

From a simple test in VS-code , I can confirm that this maybe the option for the mentioned feature. I add clangd arguments in clangd extension, as follow:

image

Yes, that's what I want!

notpeter commented 1 month ago

I believe Zed can now properly pass arguments to clangd. Can you see if something like the following works:

{
  "lsp": {
    "clangd": {
      "binary": {
        "path": "/path/to/clangd",
        "args": [
          "--function-arg-placeholders=0"
        ]
      }
    }
  }
}

If so I'd love to add this as a example to the Zed C++ Language Docs.

fish1sheep commented 4 weeks ago

I believe Zed can now properly pass arguments to clangd. Can you see if something like the following works:

{
  "lsp": {
    "clangd": {
      "binary": {
        "path": "/path/to/clangd",
        "args": [
          "--function-arg-placeholders=0"
        ]
      }
    }
  }
}

If so I'd love to add this as a example to the Zed C++ Language Docs.

Hello, I would like to ask which version of ZED you are using. I want to know which version supports this feature. Thank you

fish1sheep commented 3 weeks ago
"lsp": {
    "clangd": {
      "binary": {
        "path": "/path/to/clangd",
        "arguments": [
          "--function-arg-placeholders=0"
        ]
      }
    }
  }

I solved it, thanks to the official documentation.