ms-jpq / coq_nvim

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

fix: making autocompletion work properly after dot and other characters #639

Open HicaroD opened 4 months ago

HicaroD commented 4 months ago

Description

Some developers were reporting problems with autocompletion. See the following issues:

I was having the same problem, but I found a possible solution. I want to know you guys opinion on it. I am pretty unexperienced with the codebase, but this solutions works as a charm for me.

Midia

Code written in C++ using clangd as LSP server.

Before: ezgif-7-b140af2a41

After: ezgif-7-a51a65c31b

No zoom, sorry!

More information

Neovim

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742
return {
  "neovim/nvim-lspconfig",
  lazy = false,
  dependencies = {
    -- { "ms-jpq/coq_nvim", branch = "coq" },
    { dir = "~/Documentos/Projects/coq_nvim" },
    { "ms-jpq/coq.artifacts", branch = "artifacts" },
  },
  init = function()
    vim.g.coq_settings = {
      auto_start = "shut-up",
      completion = {
        always = true,
        skip_after = { "{", "}", "[", "]", " ", ":" },
        smart = true,
      },
      keymap = {
        recommended = false,
        pre_select = true,
      },
    }
  end,
  config = function()
    local servers = {
      "clangd", -- C / C++
      "rust_analyzer", -- Rust
      "tsserver", -- Typescript / Javascript
      "jdtls", -- Java
      "eslint", -- Typescript / Javascript (Linter)
      "golangci_lint_ls", -- Golang
      "gopls", -- Golang
      "pyright", -- Python
      -- "lua_ls", -- Lua
      "emmet_ls", -- Emmet
      "cssls", -- CSS,
      "dartls", -- Dart / Flutter
    }

    local lspconfig = require("lspconfig")
    local coq = require("coq")

    for _, server in pairs(servers) do
      lspconfig[server].setup(coq.lsp_ensure_capabilities({}))
    end

    vim.api.nvim_set_keymap(
      "i",
      "<tab>",
      [[pumvisible() ? (complete_info().selected == -1 ? "\<C-e><CR>" : "\<C-y>") : "\<CR>"]],
      { expr = true, silent = true }
    )

    local utils = require("hicaro.utils")

    utils.keyset("n", "<C-e>", vim.diagnostic.open_float)
    utils.keyset("n", "[d", vim.diagnostic.goto_prev)
    utils.keyset("n", "]d", vim.diagnostic.goto_next)

    vim.api.nvim_create_autocmd("LspAttach", {
      desc = "LSP actions",
      callback = function(event)
        local opts = { buffer = event.buf }
        utils.keyset("n", "gd", ":vsp<cr> :lua vim.lsp.buf.definition()<CR>", opts)
        utils.keyset("n", "<leader>d", vim.lsp.buf.definition, opts)
        utils.keyset("n", "K", vim.lsp.buf.hover, opts)
        utils.keyset("n", "<leader>r", vim.lsp.buf.rename, opts)
        utils.keyset({ "n", "v" }, "<leader>lca", vim.lsp.buf.code_action, opts)
      end,
    })
  end,
}