nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

Module gets removed when auto-completing from ansible LSP

Open Sandromuc opened this issue 3 months ago • 0 comments

FAQ

  • [x] I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

return {
  -- LSP Manager & Configuration
  {
    "neovim/nvim-lspconfig",
    dependencies = {
      "williamboman/mason.nvim",
      "williamboman/mason-lspconfig.nvim",
      "hrsh7th/nvim-cmp",
      "hrsh7th/cmp-nvim-lsp",
    },
    config = function()
      -- Enable keybindings and capabilities when an LSP server attaches to a buffer
      local on_attach = function(client, bufnr)
        -- Enable completion triggered by <c-x><c-o>
        vim.bo[bufnr].omnifunc = 'v:lua.vim.lsp.omnifunc'

        -- Keymaps for LSP functions
        local opts = { buffer = bufnr }
        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) -- Go to definition
        vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) -- Show documentation
        vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts) -- Rename symbol
        vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts) -- Code actions
      end

      -- Enhance LSP capabilities for autocompletion
      local capabilities = require('cmp_nvim_lsp').default_capabilities()

      -- Setup Mason to manage LSP servers
      require('mason').setup({})
      require('mason-lspconfig').setup({
        ensure_installed = { "pyright", "ansiblels" }, -- Automatically install pyright
        -- This handler automatically sets up servers that are installed via Mason
        handlers = {
          function(server_name)
            -- This is the key change: using vim.lsp.config
            local server_config = {
              name = server_name,
              on_attach = on_attach,
              capabilities = capabilities,
            }

            if server_name == "ansiblels" then
              server_config.settings = {
                ansible = {
                  useFullyQualifiedCollectionNames = true,
                  validation = {
                    enabled = true,
                    lint = {
                      enabled = true,
                    }
                  }
                }
              }
            end
            -- Enable the server for the current buffer
            vim.lsp.config(server_config)
            vim.lsp.enable(server_name)
          end,
        }
      })

      -- Configure autocompletion (nvim-cmp)
      local cmp = require('cmp')
      cmp.setup({
        snippet = {
          expand = function(args)
            -- You can add a snippet engine like LuaSnip here if needed
          end,
        },
        mapping = cmp.mapping.preset.insert({
          ['<C-b>'] = cmp.mapping.scroll_docs(-4),
          ['<C-f>'] = cmp.mapping.scroll_docs(4),
          ['<C-Space>'] = cmp.mapping.complete(),
          ['<C-e>'] = cmp.mapping.abort(),
          ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Confirm with Enter
          ['<Tab>'] = cmp.mapping(function(fallback)
            if cmp.visible() then
              cmp.select_next_item()
            else
              fallback()
            end
            end, { 'i', 's' }),
          ['<S-Tab>'] = cmp.mapping(function(fallback)
            if cmp.visible() then
              cmp.select_prev_item()
            else
              fallback()
            end
            end, { 'i', 's' }),

        }),
        sources = cmp.config.sources({
          { name = 'nvim_lsp' }, -- Completions from LSP
        }),
        -- This helps with the dots issue
        completion = {
          completeopt = 'menu,menuone,noinsert,noselect'
        },
        preselect = cmp.PreselectMode.None,
        experimental = {
          ghost_text = false,
        },
      })
    end
  }
}

Description

nvim 0.11 ansiblels 1.2.3

Steps to reproduce

As soon as i confirm a module with a dot in it my line gets replace to a empty string. If i select the module and hit escape it works but it is a bad workaround.

Image

Expected behavior

the module should be autocompleted

Actual behavior

Confirmed module gets deleted or replaced by empty string

Additional context

No response

Sandromuc avatar Sep 29 '25 11:09 Sandromuc