hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.47k stars 370 forks source link

command line completion appends unwanted forward slash #1788

Closed jam1015 closed 3 months ago

jam1015 commented 6 months ago

I'm using nvim-cmp.

Here is the issue I'm facing;

In the command line completion for : if I start with / or . , path source completion gets triggered. If I tab through the entries to a directory, a trailing / is not appended, and when I type in the trailing / , then I can autocomplete the files and directories contained in the directory I just appended / to.

But if I don't start with . or / then cmdline source completion is used, and when I select a directory, a trailing / is appended and I have to delete it and retype it to autocomplete files and directories on the next level. Adding a second / starts autocomplete using the path source from the root directory, /.

One think I've tried doing is disabling the cmdline source for certain commands, which is not ideal;

So my question is; does anyone know how to stop the cmdline source for nvim-cmp to not append trailing slashes to directory names? Or some more elegant way to make it autocomplete into the next directory level?

here is a minimal config to test what I'm talking about

    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", -- latest stable release
        lazypath,
      })
    end
    vim.opt.rtp:prepend(lazypath)

    require("lazy").setup(
      {
        {
          "hrsh7th/nvim-cmp",
          dependencies = {
            { "hrsh7th/cmp-path",   },
            { "hrsh7th/cmp-cmdline",},
            {
              "L3MON4D3/LuaSnip", -- tag = "v<CurrentMajor>.*",
              dependencies = { "rafamadriz/friendly-snippets" },
              config = function()
                require("plugin_configs.LuaSnip")
              end,

              event = "VeryLazy"
            },
            { "saadparwaiz1/cmp_luasnip" }
          },
          config = function()
            local cmp = require 'cmp'
            cmp.setup.cmdline(':', {
              mapping = cmp.mapping.preset.cmdline(
                {
                }),
              sources = cmp.config.sources({
                { name = 'path' }
              }, {
                { name = 'cmdline' }
              })
            })
          end,
        },
      }
    )
    vim.cmd([[colorscheme elflord]])

Thanks in advance for any insight!

hrsh7th commented 3 months ago

fixed in https://github.com/hrsh7th/cmp-cmdline/commit/d250c63aa13ead745e3a40f61fdd3470efde3923