ms-jpq / coq_nvim

Fast as FUCK nvim completion. SQLite, concurrent scheduler, hundreds of hours of optimization.
GNU General Public License v3.0
3.52k stars 97 forks source link

Incorrect suggestion expansion #543

Open AlphaKeks opened 1 year ago

AlphaKeks commented 1 year ago

Sometimes when accepting suggestions it expands into the wrong thing. Let's say I have a Vec in rust and want to call .into_iter() on it. When I start typing, the LSP correctly suggests it. Now when I accept the suggestion it does not expand it into .into_iter (which would be what I expect) but into .into_iter (as IntoIterator).

suggestion

expansion

I'm using neovim 0.8 and this is my config:

vim.g.coq_settings = {
  auto_start = "shut-up",
  display = {
    ghost_text = {
      enabled = true
    },
    pum = {
      source_context = { "(", ")" }
    }
  },
  keymap = {
    recommended = false,
    manual_complete = "<C-Space>",
    jump_to_mark = "<C-j>",
    pre_select = true
  }
}

local coq_ok, coq = pcall(require, "coq")
if coq_ok then
  local autopairs_ok, autopairs = pcall(require, "nvim-autopairs")
  if autopairs_ok then
    vim.keymap.set("i", "<esc>", [[pumvisible() ? "<C-e><esc>" : "<esc>"]], { expr = true })
    vim.keymap.set("i", "<C-c>", [[pumvisible() ? "<C-e><C-c>" : "<C-c>"]], { expr = true })
    vim.keymap.set("i", "<Tab>", [[pumvisible() ? "<C-n>" : "<Tab>"]], { expr = true })
    vim.keymap.set("i", "<S-Tab>", [[pumvisible() ? "<C-p>" : "<bs>"]], { expr = true })

    vim.keymap.set("i", "<cr>", function()
      if vim.fn.pumvisible() ~= 0 then
        if vim.fn.complete_info({ "selected" }).selected ~= -1 then
          return autopairs.esc("<C-y>")
        else
          return autopairs.esc("<C-e>") .. autopairs.autopairs_cr()
        end
      else
        return autopairs.autopairs_cr()
      end
    end, { expr = true })
  else
    autopairs = {
      ["("] = ")",
      ["["] = "]",
      ["{"] = "}",
      ["\""] = "\"",
      ["'"] = "'",
      ["`"] = "`",
    }

    for k, v in pairs(autopairs) do
      vim.keymap.set("i", k, function()
        return k .. v .. "<Left>"
      end, { expr = true })
    end
  end
end

I tested it with and without nvim-autopairs installed. It doesn't seem to have any effect on the behavior. A full list of my plugins:

                packer.nvim - Total plugins: 21
 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 • Comment.nvim
 • LuaSnip
 • catppuccin
 • coq.artifacts
 • coq.thirdparty
 • coq_nvim
 • feline.nvim
 • gitsigns.nvim
 • harpoon
 • impatient.nvim
 • mason.nvim
 • null-ls.nvim
 • nvim-lspconfig
 • nvim-treesitter
 • nvim-ts-autotag
 • nvim-web-devicons
 • packer.nvim
 • playground
 • plenary.nvim
 • telescope.nvim
 • vim-be-good
dgalbraith33 commented 1 year ago

+1 I'm experiencing this with ccls as well.

The suggested result for a variable often includes the type: variable_name : type

And the suggested result for a function includes the return type: function_name() -> return_type

I have a relatively minimal config:

local coq = require('coq')

require('lspconfig')['ccls'].setup(coq.lsp_ensure_capabilities({
  init_options = {
    cache = {
      directory = "/tmp/ccls"
    },
    compilationDatabaseDirectory = "builddir",
    client = {
      snippetSupport = true
    },
    highlight = {
      lsRanges = true
    }
  }
}))

require('lspconfig')['rust_analyzer'].setup(coq.lsp_ensure_capabilities({

}))

vim.g.coq_settings = {
  clients = {
    lsp = {
      weight_adjust = 1.5
    },
    snippets = {
      enabled = false
    }
  },
  display = {
    pum = {
      -- Helps prevent flickering at the risk of having stale results.
      fast_close = false 
    }
  }
}