Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path suggestions missing when cursor is followed by any other character #959

Open
2 tasks done
gonstoll opened this issue Jan 8, 2025 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working sources Specific source provider or the system as a whole

Comments

@gonstoll
Copy link

gonstoll commented Jan 8, 2025

Make sure you have done the following

  • Updated to the latest version of blink.cmp
  • Searched for existing issues and documentation (try <C-k> on https://cmp.saghen.dev)

Bug Description

This has been partially discussed in this discussion. Head over there for more context.

Problem

When triggering completion on a path, no suggestion will be given if the any character comes after the cursor.

Moreover, as mentioned in that discussion by @Saghen, it might be worth adding path as one of the fallbacks for the lsp source, although that sadly doesn't seem to solve this problem.

Demo

blink.cmp

Screen.Recording.2025-01-08.at.09.48.08.mov

To make it more clear:

import foo from './|/'
//                 ^ Cursor is here, and completion window doesn't suggest anything

Here, / can be anything. If I have a r, u, or any character, it won't even suggest things.

import foo from './|'
//                 ^ Cursor is here, and suggestions appear on the completion window

nvim-cmp

Screen.Recording.2025-01-08.at.09.46.29.mov
import foo from './|/'
//                 ^ Cursor is here, and suggestions appear on the completion window

Relevant configuration

sources = {
  default = {'lsp', 'path', 'snippets', 'buffer', 'lazydev'},
  providers = {
    lsp = {
      fallbacks = {'buffer', 'path'},
    },
    lazydev = {
      name = 'LazyDev',
      module = 'lazydev.integrations.blink',
      score_offset = 100, -- show at a higher priority than lsp
    },
    snippets = {
      name = 'Snippets',
      module = 'blink.cmp.sources.snippets',
      min_keyword_length = 3,
      opts = {
        friendly_snippets = false,
        search_paths = {vim.fn.stdpath('config') .. '/snippets/nvim'},
      },
    },
  },
}

neovim version

v0.10.3

blink.cmp version

0.10.0

@gonstoll gonstoll added the bug Something isn't working label Jan 8, 2025
@Saghen Saghen added the sources Specific source provider or the system as a whole label Jan 8, 2025
@gonstoll gonstoll mentioned this issue Jan 8, 2025
4 tasks
@gonstoll
Copy link
Author

Trying this out a bit more, today I noticed something rather strange.

It turns out, this only happens on typescriptreact/javascriptreact filetypes 🤔:

Screen.Recording.2025-01-10.at.17.21.08.mov

For context, this is how it used to behave with nvim-cmp:

Screen.Recording.2025-01-10.at.17.24.11.mov

How my nvim-cmp used to look:

return {
  'hrsh7th/nvim-cmp',
  event = 'VeryLazy',
  dependencies = {
    'hrsh7th/cmp-nvim-lsp',
    'hrsh7th/cmp-buffer',
    'hrsh7th/cmp-path',
    'hrsh7th/cmp-cmdline',
    'hrsh7th/cmp-calc',
    'hrsh7th/cmp-emoji',
    'garymjr/nvim-snippets',
  },
  config = function()
    local cmp = require('cmp')
    local lspkind = require('lspkind')
    local cmp_select_opts = {behavior = cmp.SelectBehavior.Select}

    cmp.setup({
      snippet = {
        expand = function(args)
          vim.snippet.expand(args.body)
        end,
      },
      preselect = cmp.PreselectMode.None,
      completion = {
        completeopt = 'menu,menuone,noinsert,noselect',
      },
      mapping = {
        ['<CR>'] = cmp.mapping.confirm({select = false, behavior = cmp.ConfirmBehavior.Insert}),
        ['<C-e>'] = cmp.mapping.abort(),
        ['<C-u>'] = cmp.mapping.scroll_docs(-4),
        ['<C-d>'] = cmp.mapping.scroll_docs(4),
        ['<Up>'] = cmp.mapping.select_prev_item(cmp_select_opts),
        ['<Down>'] = cmp.mapping.select_next_item(cmp_select_opts),
        ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select_opts),
        ['<C-n>'] = cmp.mapping.select_next_item(cmp_select_opts),
        ['<C-y>'] = cmp.mapping.complete(),
      },
      sources = cmp.config.sources({
        {name = 'lazydev', group_index = 0},
        {name = 'nvim_lsp', keyword_length = 1},
        {
          name = 'snippets',
          entry_filter = function()
            local ctx = require('cmp.config.context')
            local in_string = ctx.in_syntax_group('String') or ctx.in_treesitter_capture('string')
            local in_comment = ctx.in_syntax_group('Comment') or ctx.in_treesitter_capture('comment')
            return not in_string and not in_comment
          end,
        },
      }, {
        {name = 'buffer', keyword_length = 3},
        {name = 'emoji'},
        {name = 'calc'},
        {name = 'path'},
      }),
      formatting = {
        ---@type fun(entry: cmp.Entry, vim_item: vim.CompletedItem): vim.CompletedItem
        format = lspkind.cmp_format({
          mode = 'symbol_text',
        }),
        ---@type cmp.ItemField[]
        fields = {'abbr', 'kind'}, -- Remove 'menu' to avoid truncation
      },
    })

    cmp.setup.cmdline({'/', '?'}, {
      mapping = cmp.mapping.preset.cmdline(),
      sources = {
        {name = 'buffer'},
      },
    })

    cmp.setup.cmdline(':', {
      mapping = cmp.mapping.preset.cmdline(),
      sources = cmp.config.sources({
        {name = 'path'},
      }, {
        {name = 'cmdline'},
      }),
    })
  end,
}

@gonstoll
Copy link
Author

Trying out different configurations sets, I managed to find something that seems to help with this. If I set opts.fuzzy.use_typo_resistance = false, triggering suggestions in the middle of the path seems to work again:

Screen.Recording.2025-01-12.at.13.07.32.mov

Is this desirable tho? I'd like to keep use_typo_resistance turned on at all times, or at least have the ability of turning it off for certain filetypes (in this case, turning it of if vim.bo.filetype == 'typescriptreact')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sources Specific source provider or the system as a whole
Projects
None yet
Development

No branches or pull requests

2 participants