hrsh7th / cmp-nvim-lsp-signature-help

cmp-nvim-lsp-signature-help
635 stars 26 forks source link

Signature help triggers after pressing `,` inside an object #41

Open joshuali925 opened 1 year ago

joshuali925 commented 1 year ago

To reproduce use the following init.lua

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "williamboman/mason.nvim",
        build = ":MasonUpdate",
        dependencies = { "williamboman/mason-lspconfig.nvim", "neovim/nvim-lspconfig" },
        config = function()
            require("mason").setup()
            require("mason-lspconfig").setup({ ensure_installed = { "tsserver" } })
            require("lspconfig").tsserver.setup({})
        end,
    },
    {
        "hrsh7th/nvim-cmp",
        dependencies = { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-nvim-lsp-signature-help" },
        opts = { sources = { { name = "nvim_lsp" }, { name = "nvim_lsp_signature_help" } } },
    },
})

vim.cmd.colorscheme("habamax")

then create a js file vim repro.js, wait for tsserver, then type:

Object.freeze({
        foo: 'bar',

see completion menu opens, suggesting o: T.

image

The problem is that

  1. I've configured the enter key to trigger completion, but in this case i want a new line. since the item is preselected, pressing enter will complete the item
  2. the suggestion is based on parameter of Object.freeze(o), it's no longer valid when cursor is inside the curly brackets

If it's not easy to fix, is there a way to configure entry_filter to not display suggestion in this case? maybe like this

                        entry_filter = function()
                            local col = vim.api.nvim_win_get_cursor(0)[2]
                            return vim.api.nvim_get_current_line():sub(col, col) ~= ","
                        end,

But wanted to see if there's a better way. Thanks

antoinemadec commented 6 months ago

@joshuali925 regarding the "enter selects the arg name instead of adding a new line" problem, I had the same issue.

Here is how I fixed it: https://github.com/antoinemadec/dotfiles/commit/6b4b700637d84613338446134dbf87eb4df1b422

youssef-lr commented 1 month ago

Thanks a lot @antoinemadec!

adworacz commented 5 days ago

I've run into this as well. It'd be great to either fix this or expose a setting that we could enable/disable this behavior.