feature update: use cmp built in types and cursor; add pro tip to readme #30

Merged
kaiiserni merged 2 commits from cmp_update into main 2024-10-02 15:47:11 -04:00
kaiiserni commented 2024-05-19 15:26:37 -04:00 (Migrated from github.com)

Description

I previously made a PR (accepted) which introduced cmp source integration and a couple of convenience methods. #28

This pull request contains a minor update to make better use of built in cmp types and multi line markers, cursor, etc. I had added my own marker previously, so it doesn't change much. But I feel it is cleaner this way.

I also tried to simulate the built in continuous inline completions with cmp and came up with a solution which has been working nicely for me for the last couple of days now, so I thought I could share this as a "pro tip" in the README, although this may perhaps be better suited for a wiki in the future.

The new README suggestion is demonstrated in this video:

https://github.com/supermaven-inc/supermaven-nvim/assets/87830/9871857a-56d3-44f9-abfc-b727f01d3565

Please let me know if there is anything else I need to address before accepting this pull request.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

I have tested it thoroughly on Lua and TypeScript projects, and it works as expected, providing both single and multi-line suggestions.

Configuration:

  • Neovim version (nvim --version): 0.9.5
  • Operating system and version: macOS 14.4.1 (Sonoma)

Checklist

  • [ x ] My code follows the style guidelines of this project (stylua)
  • [ x ] I have performed a self-review of my own code
  • [ x ] I have commented my code, particularly in hard-to-understand areas
  • [ x ] I have made corresponding changes to the documentation
# Description I previously made a PR (accepted) which introduced cmp source integration and a couple of convenience methods. #28 This pull request contains a minor update to make better use of built in cmp types and multi line markers, cursor, etc. I had added my own marker previously, so it doesn't change much. But I feel it is cleaner this way. I also tried to simulate the built in continuous inline completions with cmp and came up with a solution which has been working nicely for me for the last couple of days now, so I thought I could share this as a "pro tip" in the README, although this may perhaps be better suited for a wiki in the future. The new README suggestion is demonstrated in this video: https://github.com/supermaven-inc/supermaven-nvim/assets/87830/9871857a-56d3-44f9-abfc-b727f01d3565 Please let me know if there is anything else I need to address before accepting this pull request. ## Type of change - New feature (non-breaking change which adds functionality) - This change requires a documentation update ## How Has This Been Tested? I have tested it thoroughly on Lua and TypeScript projects, and it works as expected, providing both single and multi-line suggestions. **Configuration**: - Neovim version (`nvim --version`): 0.9.5 - Operating system and version: macOS 14.4.1 (Sonoma) ## Checklist - [ x ] My code follows the style guidelines of this project (stylua) - [ x ] I have performed a self-review of my own code - [ x ] I have commented my code, particularly in hard-to-understand areas - [ x ] I have made corresponding changes to the documentation
kaiiserni commented 2024-05-19 15:38:10 -04:00 (Migrated from github.com)

@victorw-xyz fwiw, I also took the liberty of listing Supermaven in the official list of cmp sources: https://github.com/hrsh7th/nvim-cmp/wiki/List-of-sources

@victorw-xyz fwiw, I also took the liberty of listing Supermaven in the official list of cmp sources: https://github.com/hrsh7th/nvim-cmp/wiki/List-of-sources
partounian commented 2024-10-01 17:55:22 -04:00 (Migrated from github.com)

would be nice if this could be merged in

would be nice if this could be merged in
sm-victorw commented 2024-10-02 15:42:58 -04:00 (Migrated from github.com)

Sorry it took so long to address this PR - regarding the protip, I think until we have a well structured README.md perhaps with a table of contents etc. we should avoid making large additions there unless they are relevant to most everyone trying to go through the document

Sorry it took so long to address this PR - regarding the protip, I think until we have a well structured `README.md` perhaps with a table of contents etc. we should avoid making large additions there unless they are relevant to most everyone trying to go through the document
williamgoulois commented 2024-10-03 04:49:12 -04:00 (Migrated from github.com)

@kaiiserni Thank you for your PR, could you share here the "pro tip" or some code snippets ? I am using supermaven as a cmp source and would love a better workflow !

@kaiiserni Thank you for your PR, could you share here the "pro tip" or some code snippets ? I am using supermaven as a cmp source and would love a better workflow !
sm-victorw commented 2024-10-03 11:37:04 -04:00 (Migrated from github.com)

@williamgoulois It remains in the commit history

"Pro tip: If you want to simulate continuous suggestions similar to the built in inline completions (which always jumps to the next suggestion); you can achieve this with a timer/poller."

local completion_timer = nil

local function stop_completion_polling()
  if completion_timer ~= nil then
    completion_timer:stop()
    completion_timer:close()
    completion_timer = nil
  end
end

local function check_suggestions()
  if supermaven.has_suggestion() then
    cmp.complete()
    stop_completion_polling()
  end
end

local function start_completion_polling()
  local ignored_filetypes = {
    -- IMPORTANT: filetypes you want to ignore
  }

  if not vim.tbl_contains(ignored_filetypes, vim.bo.filetype) then
    if completion_timer == nil then
      completion_timer = vim.loop.new_timer()
      completion_timer:start(100, 100, vim.schedule_wrap(check_suggestions))
    end
  end
end

vim.api.nvim_create_autocmd('InsertEnter', {
  callback = start_completion_polling,
})

vim.api.nvim_create_autocmd({ 'CursorMoved', 'InsertLeave' }, {
  callback = stop_completion_polling,
  pattern = '*',
  nested = true,
})


-- cmp.lua

cmp.setup {
  ...
  mapping = {
    ...
    ["<C-y>"] = cmp.mapping(function()
      cmp.confirm({  select = true })
      start_completion_polling()
    end),
    ...
  },
  ...
}

@williamgoulois It remains in the commit history "Pro tip: If you want to simulate continuous suggestions similar to the built in inline completions (which always jumps to the next suggestion); you can achieve this with a timer/poller." ```lua local completion_timer = nil local function stop_completion_polling() if completion_timer ~= nil then completion_timer:stop() completion_timer:close() completion_timer = nil end end local function check_suggestions() if supermaven.has_suggestion() then cmp.complete() stop_completion_polling() end end local function start_completion_polling() local ignored_filetypes = { -- IMPORTANT: filetypes you want to ignore } if not vim.tbl_contains(ignored_filetypes, vim.bo.filetype) then if completion_timer == nil then completion_timer = vim.loop.new_timer() completion_timer:start(100, 100, vim.schedule_wrap(check_suggestions)) end end end vim.api.nvim_create_autocmd('InsertEnter', { callback = start_completion_polling, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'InsertLeave' }, { callback = stop_completion_polling, pattern = '*', nested = true, }) -- cmp.lua cmp.setup { ... mapping = { ... ["<C-y>"] = cmp.mapping(function() cmp.confirm({ select = true }) start_completion_polling() end), ... }, ... } ```
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
supermaven-inc/supermaven-nvim!30
No description provided.