-
Notifications
You must be signed in to change notification settings - Fork 410
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
Multiline snippet ghost text with dynamic window position flip #1955
base: main
Are you sure you want to change the base?
Conversation
This is so awesome! I will test it shortly! Can you share how you have set up CMP @xzbdmw . I want to try and avoid making a mistake in the setup on my part. I was using Copilot.lua with the cmp extension for my ghost text |
Hey I think you don’t need to change anything. should work out of box, and there is no extra config option in cmp . this is my keymap, and near cursor(vedio effect, optional) |
please add an option to toggle between multiline and singleline ghost text, not everyone like to have multiline previews. |
@xzbdmw It works really well and swaps every time there is a multiline ghost text! My completion menu does not seem to follow the mouse as much as yours and I am not completely sure about the hiding of the menu when there is a space (but keeping the ghost text). If you want to take a look at my cmp config: https://github.com/michaelbrusegard/dotfiles/blob/25f81267d8f3d9253153b54bf92dd6e757ac089a/macos/.config/nvim/init.lua#L551 Maybe you have some feedback or suggestions, I am very new to neovim btw |
@cybergaz That shoud be easy(I’m waiting for maintainer’s reply) |
Screen.Recording.2024-06-10.at.23.01.39.movThis is how it looks, but the menu doesnt hide on space (while keeping the ghost text) and it doesnt move with the cursor. It may be my config is wrong for all I know |
That’s because copilot suggestion contains space, so it just matches
you can try |
@xzbdmw Thank you, that worked with the cursor. Are there any convenient way to make the keybinds. I feel like when I have the completion complete with return or tab it can be annoying if I actually want to use any of those |
d6fc977
to
1002d1c
Compare
@xzbdmw |
Have you updated to the latest commit? works as expect to me. iShot_2024-09-02_02.13.09.mp4 |
You are right... I had removed the follow cursor option from my config. Probably by accident once |
Hey - this is great functionality - just combined it with a snippet I created to prevent ghost_text from firing in the middle of words. One edge case I've encountered when using it: I've had issues with the completion menu appearing when at the top of the file. The multiline ghost_text displays correctly but I assume the menu is rendering outside the visible bounds? I'm currently applying this PR via a custom build step that fetches and applies it as a patch - don't think that's the cause but including for visibility: Utils: local M = {}
-- Function to apply a patch to a plugin from a URL
function M.apply_patch(plugin_name, patch_url, patch_name)
local plugin_dir = vim.fn.stdpath('data') .. '/lazy/' .. plugin_name
local patch_path = plugin_dir .. '/' .. patch_name .. '.patch'
vim.fn.system({'curl', '-L', patch_url, '-o', patch_path})
local result = vim.fn.system({'git', '-C', plugin_dir, 'apply', patch_path})
if vim.v.shell_error ~= 0 then
vim.notify('Failed to apply patch: ' .. result, vim.log.levels.ERROR)
else
vim.notify('Patch applied successfully to ' .. plugin_name, vim.log.levels.INFO)
end
end
return M Completions: local utils = require("mike.utils")
return {
-- Other plugin setup here...
{
'hrsh7th/nvim-cmp',
dependencies = {
'hrsh7th/cmp-nvim-lsp',
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'hrsh7th/cmp-cmdline',
'hrsh7th/cmp-nvim-lsp-signature-help',
{
'windwp/nvim-autopairs',
event = 'InsertEnter',
opts = {
disable_filetype = { 'TelescopePrompt', 'vim' },
},
},
},
build = function ()
utils.apply_patch('nvim-cmp', 'https://github.com/hrsh7th/nvim-cmp/pull/1955.patch', '1955')
end,
config = function ()
-- Setup stuff here ...
-- Conditional ghost_text
-- Consolidated list of characters that should toggle ghost_text
local toggle_chars = {
'"', "'", '`', '<', '>', '{', '}', '[', ']', '(', ')', ' ', ''
}
local cmp_config = require('cmp.config')
local function toggle_ghost_text()
if vim.api.nvim_get_mode().mode ~= "i" then
return
end
-- Get the current cursor column and line content
local cursor_col = vim.fn.col('.') -- Get cursor column
local line = vim.fn.getline('.') -- Get current line content
-- Get the character after the cursor
local char_after = line:sub(cursor_col, cursor_col)
-- Check if the character after the cursor is in the toggle list (pair characters, spaces, or end of line)
local should_enable_ghost_text = vim.tbl_contains(toggle_chars, char_after)
-- Enable or disable ghost_text based on the conditions
cmp_config.set_onetime({
experimental = {
ghost_text = should_enable_ghost_text,
},
})
end
vim.api.nvim_create_autocmd({ "InsertEnter", "CursorMovedI" }, {
callback = toggle_ghost_text,
})
-- Final setup here...
end,
}
} |
@mikecsmith If the completion menu can't be fit in area that above the cursor, the menu still stays below, do you have some way to reproduce that issue? iShot_2024-09-13_05.46.43.mp4 |
I can't reproduce it this morning - it's working perfectly. Apologies - suspect it may have been something in my configs that caused it! |
Currently running off this branch with high satisfaction, combined with copilot |
Add comment of adoption of neovim snippet code
add support for all selection order if top space is not enough, do not flip window take border into consider set every possible winconfig see if it is multiline for 'noselect'
I've rebased with master that has perf improvement. |
waiting for merge, we need this feature |
I've integrate with mini-snippets (try it out! It is really good) with a source, so that snippets defined by mini.snippets has the same look as lsp snippets in this pr. There is a video in echasnovski/mini.nvim#1428 (comment) |
follow up of #1886
fix #1886 (comment)
close #495
should behave the same as vscode now. Custom snippet not supported yet, only lsp snippet and copilot-similar source will trigger multi-line ghost-text, but should be easy to add.
The functionality is all implemented,
@hrsh7th do let me know what do you think, Thanks!
iShot_2024-06-09_07.56.42.mp4