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

fix: make sure nvim-cmp keymaps are registered #2087

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tronikelis
Copy link

Context

When editing files with the https://github.com/microsoft/compose-language-service LSP, the popup would always appear on new lines like so:

Completion appears on fully whitespace line

As you can see, this interferes with my fallback Tab keymap which indents the code and its very annoying

2024-11-09.17-20-25.mp4

This is with keyword_length = 1

The underlying issue

I think the underlying issue is:

  1. docker compose LSP acts differently (this does not happen on other lsps)
  2. nvim-cmp, even with keyword_length = 1 still shows the menu when there are no keywords (fully whitespace line), unless this is the expected behavior

Workaround

I started using this config to workaround the issue

enabled = function()
    return #vim.trim(vim.api.nvim_get_current_line()) ~= 0
end,

But then I saw that sometimes my completion selection just stopped working altogether like so:

Completion stops
2024-11-09.17-08-10.mp4

This PR

This pr makes the workaround actually work

With this PR
2024-11-09.17-07-44.mp4

@tronikelis tronikelis force-pushed the fix/make_sure_nvim_is_initialized branch from e255ad7 to 7491c46 Compare November 9, 2024 19:16
@tronikelis tronikelis changed the title fix: make sure nvim keymaps are registered fix: make sure nvim-cmp keymaps are registered Nov 10, 2024
@hrsh7th
Copy link
Owner

hrsh7th commented Nov 21, 2024

IMO, you can use get_trigger_characters option.

check out it.

require('cmp').setup({
  ...
  completion = {
    get_trigger_characters = function(trigger_characters)
      return vim.iter(trigger_characters):filter(function(char)
        return not chat:match('^%s*$')
      end)
    end
  }
  ...
})

@tronikelis
Copy link
Author

IMO, you can use get_trigger_characters option.

check out it.

require('cmp').setup({
  ...
  completion = {
    get_trigger_characters = function(trigger_characters)
      return vim.iter(trigger_characters):filter(function(char)
        return not chat:match('^%s*$')
      end)
    end
  }
  ...
})

Damn, nice, seems to work, but I am not finding this in the doc?

@tronikelis
Copy link
Author

With your config option there is a problem,

When completing a function the signature help and completion window does not open by itself anymore (which I want)

@tronikelis
Copy link
Author

Do you see any problems with this fix?

@tronikelis
Copy link
Author

this seems to work

get_trigger_characters = function(trigger_characters)
    if #vim.trim(vim.api.nvim_get_current_line()) == 0 then
        return {}
    end

    return trigger_characters
end,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants