scalameta / metals-feature-requests

Issue tracker for Metals feature requests
37 stars 4 forks source link

Omit signature details from label in completion items #235

Open suliatis opened 3 years ago

suliatis commented 3 years ago

Is your feature request related to a problem? Please describe.

The completion items provided by metals contain the signature information along with the item name. It can make the completion floating window very big, also I already use a completion preview window for the same reason so for me the signature info shown duplicated.

It looks like this in nvim with nvim-cmp or similar with any completion plugin:

Screen Shot 2021-10-03 at 12 36 03

Describe the solution you'd like

I would like a configuration option for metals so I can disable the signature info and achieve a look like this, with elmls:

Screen Shot 2021-10-03 at 12 36 49

Describe alternatives you've considered

I tried different completion plugins for nvim like completion-nvim, coc.nvim and nvim-cmp all of them looks the same. I also dug through the lsp and metals docs if it is configurable in some way but I did not find any related config option.

At this point my assumption is this should be a metals specific behaviour, because other lsp servers I tried only provide the name for the completion items, but I'm not sure. Also I only using neovim, I have no idea how this works in VSCode or if my suggestion has any negative consequences for other editors.

Additional contex

No response

Search terms

completion, signature, configuration

ckipp01 commented 3 years ago

Hey @suliatis, good question!

So the behaviour you're explaining is the completionItem/resolve. So this is sent from the client to the server and the server simply responds to the request. I'm glad you asked this as it actually pointed out a couple things to me.

First of all, we do have a setting for this that will return off the resolve, although it's sort of hidden, and in nvim-metals the bare_config actually had an issue so it wouldn't have worked anyways. However, that's fixed now so ensure you're on the latest and then you can do the following:

  Metals_config = require("metals").bare_config
  Metals_config.init_options.compilerOptions.isCompletionItemResolve = false

The compilerOptions.isCompletionResolve setting will ensure that when Metals starts and sends its capabilities to the client, it won't say it's a resolveProvider. Then as you can see here in cmp-nvim-lsp it will check for that value and no longer send the resolve in:

https://github.com/hrsh7th/cmp-nvim-lsp/blob/f93a6cf9761b096ff2c28a4f0defe941a6ffffb5/lua/cmp_nvim_lsp/source.lua#L54-L56

With that all being said, this will get rid of the extra documentation in the float, but it won't fully solve your problem. In this case when completion items go back to the client they hold quite a bit of info, and not all of it is shown in the actual original window. So when you scroll through your completion items, you'll still get another window showing you the detail section of the completionItem. I originally thought the labelDetailsSupport which you can pass in as an override to cmp-nvim-lsp would turn this off, but that doesn't seem to be the case. So I actually have no idea what that setting does:

https://github.com/hrsh7th/cmp-nvim-lsp/blob/f93a6cf9761b096ff2c28a4f0defe941a6ffffb5/lua/cmp_nvim_lsp/init.lua#L31

I do see a couple references to labelDetails in nvim-cmp, but no idea how to fully turn that off. I'd recommend changing there, but again my assumption was using the following would have done it:

 require("cmp_nvim_lsp").update_capabilities(
    capabilities,
    { labelDetailsSupport = false }
  )

So overall, I'd recommend asking in nvim-cmp how to fully turn that off.

suliatis commented 3 years ago

Hi @ckipp01,

thank you for your detailed response. I tried the config changes you mentioned, it worked though I'm afraid it is not exactly what I wanted to achieve. I don't want to get rid of the hovering documentation window which appears on the right side. My problem is with the signature info in the completion menu which does not disappear if I the isCompletionItemResolve to false. So I would like to see only the names in the completion menu.

ckipp01 commented 3 years ago

Hey @suliatis reading through again I think I originally misunderstood what you wanted. I'm not really sure what you're asking for is going to be possible. Most completion plugins take the full label and display it. So for example the completion for map will look like this:

   {
      "label": "map[B](f: Int \u003d\u003e B): Option[B]",
      "kind": 2,
      "detail": "[B](f: Int \u003d\u003e B): Option[B]",
      "preselect": true,
      "sortText": "00000",
      "filterText": "map",
      "insertTextFormat": 2,
      "textEdit": {
        "range": {
          "start": {
            "line": 10,
            "character": 4
          },
          "end": {
            "line": 10,
            "character": 6
          }
        },
        "newText": "map($0)"
      },
      "data": {
        "symbol": "scala/Option#map().",
        "target": "file:/Users/ckipp/Documents/scala-workspace/sanity/?id\u003dsanity"
      }
    },

As you can imagine there are going to be times where just simplifying the label to the name of a method or something won't work, as you wouldn't be able to tell the difference right away and it may appear like you just have 3 of the same methods in your list. Either way, the way we put that label together will always have the signature if I'm not mistaken. I'll open this back up because maybe someone else may have some insight, but this would require a change in the way we create our completion labels if I'm not mistaken.

ckipp01 commented 3 years ago

Just tying these together since this just came up in the nvim-metals repo as well: https://github.com/scalameta/nvim-metals/discussions/241#discussion-3610517

kubukoz commented 1 year ago

Hey, I was wondering why Metals puts everything into label and stumbled upon this.

VS Code displays labelDetails separately:

image

could Metals do this for type annotations when labelDetailsSupport is on?

speaking of other ways to simplify completion UX, I think there's duplication of package info sometimes, at least in Scala 2.x:

image
frou commented 1 year ago

Hello folks

It seems like there was a deliberate change in Metals back in 2019 to duplicate the string contents of the details part of a Completion Item (right side) into the label part (left side). That was basically a hack to workaround UI issues in certain editors.

Here's that PR: https://github.com/scalameta/metals/pull/581


Until I found this existing feature request, I was about to submit a similar feature requesting asking for a new Metals user configuration value to be able to turn the hack off, e.g. "keepCompletionsSeparated": true

Here are some screenshots (from Sublime Text) I prepared:

Current (Unnecessarily wide/busy looking. Lots of a duplicated information):

before

Desired (mocked up):

after