Giter Site home page Giter Site logo

Comments (13)

ranebrown avatar ranebrown commented on August 16, 2024 1

Fair enough. Thanks for taking a look.

from cmp-nvim-ultisnips.

anstadnik avatar anstadnik commented on August 16, 2024

I've just checked, and for me everything works. I use ray-x/lsp_signature.nvim, and with both floating_window = true and floating_window = false I can jump back and forth inside the snippet. Could you provide a minimal init.nvim?

from cmp-nvim-ultisnips.

vsedov avatar vsedov commented on August 16, 2024

Yeah sure, ive made a quick init_min.vim - you still get the same issue here, so say you have a language server like jedi-language-server it has internal snipits which are enabled by the compatibilities thing on lsp. so like map would give map(func,item) its done via jedi if im not mistaken.

set termguicolors

call plug#begin('~/.vim/plugged')

if has('nvim')
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'rafamadriz/friendly-snippets'
Plug 'hrsh7th/cmp-nvim-lua'
Plug 'ray-x/lsp_signature.nvim'
Plug 'SirVer/ultisnips'
Plug 'quangnguyen30192/cmp-nvim-ultisnips'
Plug 'https://github.com/numToStr/Sakura.nvim'
endif



call plug#end()

set mouse=a

colorscheme sakura

if ! has('nvim')
  finish
endif



lua <<EOF

vim.g.UltiSnipsRemoveSelectModeMappings = 0

 require'lsp_signature'.setup({
    floating_window = true,
 })


require'nvim-treesitter.configs'.setup {
  highlight = {
  enable = true,              
  additional_vim_regex_highlighting = false,
  },
}
local nvim_lsp = require('lspconfig')

local cmp = require("cmp")
local has_any_words_before = function()
  if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
    return false
  end
  local line, col = unpack(vim.api.nvim_win_get_cursor(0))
  return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

local press = function(key)
  vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), "n", true)
end

cmp.setup {

    snippet = {
      expand = function(args)
         vim.fn["UltiSnips#Anon"](args.body)
      end
    },
    completion = {
      autocomplete = {require("cmp.types").cmp.TriggerEvent.TextChanged},
      completeopt = "menu,menuone,noselect"
    },

	mapping = {

		
			["<C-e>"] = cmp.mapping.close(),
			["<CR>"] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
			

			["<C-Space>"] = cmp.mapping(function(fallback)
				if cmp.visible() then
					if vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then
						return press("<C-R>=UltiSnips#ExpandSnippet()<CR>")
					end

					cmp.select_next_item()
				elseif has_any_words_before() then
					press("<Space>")
				else
					fallback()
				end
			end, {
				"i",
				"s",
			}),

			["<Tab>"] = cmp.mapping(function(fallback)
				if vim.fn["UltiSnips#CanJumpForwards"]() == 1 then
					press("<ESC>:call UltiSnips#JumpForwards()<CR>")
				elseif cmp.visible() then
					cmp.select_next_item()
				elseif has_any_words_before() then
					press("<Tab>")
				else
					fallback()
				end
			end, {
				"i",
				"s",
			}),
			["<S-Tab>"] = cmp.mapping(function(fallback)
				if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then
					press("<ESC>:call UltiSnips#JumpBackwards()<CR>")
				elseif cmp.visible() then
					cmp.select_prev_item()
				else
					fallback()
				end
			end, {
				"i",
				"s",
			}),
		},

	   



    sources = {{name = 'nvim_lsp'}, {name = 'buffer'}, {name='ultisnips'}}
}


local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

capabilities.textDocument.completion.completionItem.resolveSupport = {
	properties = {
		"documentation",
		"detail",
		"additionalTextEdits",
	},
}

capabilities.textDocument.codeAction = {
	-- dynamicRegistration = false;
	codeActionLiteralSupport = {
		codeActionKind = {
			valueSet = {
				"quickfix",
				"refactor",
				"refactor.extract",
				"refactor.inline",
				"refactor.rewrite",
				"source",
				"source.organizeImports",
			},
		},
	},
}



require'lspconfig'.jedi_language_server.setup({
	cmd = { "jedi-language-server" },
	filetypes = { "python" },
	on_attach = enhance_attach,
	capabilities = capabilities,
})


EOF

So run down of what i do

i type map and use enter to expand the snipit, i write the first part of the snippit and i press which is cmp.mapping.close(), then try tabbing to go to the next one, normally without the float on lsp_sig it works, but with float even here it doesnt, all the utilsnips snippets work, just the language server stuff doesnt work right with the float thats all .

from cmp-nvim-ultisnips.

quangnguyen30192 avatar quangnguyen30192 commented on August 16, 2024

@vsedov sorry for the late response, does the plugin work for you now?

from cmp-nvim-ultisnips.

vsedov avatar vsedov commented on August 16, 2024

Nah all good, I should have closed this issue, sorry about that. Everything is working now : ) .

from cmp-nvim-ultisnips.

ranebrown avatar ranebrown commented on August 16, 2024

What was the solution? I'm seeing the same problem when using lsp_signature floating window.

from cmp-nvim-ultisnips.

quangnguyen30192 avatar quangnguyen30192 commented on August 16, 2024

Could you check the following?

I've just checked, and for me everything works. I use ray-x/lsp_signature.nvim, and with both floating_window = true and floating_window = false I can jump back and forth inside the snippet. Could you provide a minimal init.nvim?

from cmp-nvim-ultisnips.

vsedov avatar vsedov commented on August 16, 2024

What was the solution? I'm seeing the same problem when using lsp_signature floating window.

Hmm truth be told i have forgotten what i did, If I'm not mistaken it was how lsp sig was being called, if you are directly using a cfg or not, and if its within the attach function in your lsp config .

Another thing id checks if its being called through opt or not.

from cmp-nvim-ultisnips.

ranebrown avatar ranebrown commented on August 16, 2024

Here is a minimal config. I was testing using clangd (:LspInstall clangd) after the initial nvim -u minimal_config.lua. Expanding the lsp provided snippet for the sum function makes it so you can't jump between the tab stops. Setting lsp_signtature floating window to false makes it work as expected.

Minimal init
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])

local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"

local function load_plugins()
    require("packer").startup({
        function(use)
            use({ "wbthomason/packer.nvim" })
            use({ "SirVer/ultisnips" })
            use({
                "hrsh7th/nvim-cmp",
                requires = {
                    "hrsh7th/cmp-nvim-lsp",
                    "quangnguyen30192/cmp-nvim-ultisnips",
                },
                config = function()
                    local cmp = require("cmp")
                    local cmp_ultisnips_mappings = require(
                        "cmp_nvim_ultisnips.mappings"
                    )

                    cmp.setup({
                        snippet = {
                            expand = function(args)
                                vim.fn["UltiSnips#Anon"](args.body)
                            end,
                        },
                        mapping = {
                            ["<Tab>"] = cmp.mapping(function(fallback)
                                cmp_ultisnips_mappings.compose({
                                    "jump_forwards",
                                    "select_next_item",
                                })(fallback)
                            end, {
                                "i",
                                "s",
                                "c",
                            }),
                            ["<S-Tab>"] = cmp.mapping(function(fallback)
                                cmp_ultisnips_mappings.compose({
                                    "jump_backwards",
                                    "select_prev_item",
                                })(fallback)
                            end, {
                                "i",
                                "s",
                                "c",
                            }),
                        },
                        sources = {
                            { name = "nvim_lsp", priority = 100, group_index = 1 },
                            { name = "ultisnips", priority = 80, group_index = 1 },
                        },
                    })
                end,
            })
            use({
                "nvim-treesitter/nvim-treesitter",
                config = function()
                    require("nvim-treesitter.configs").setup({
                        ensure_installed = {"cpp" },
                        highlight = { enable = true },
                    })
                end,
                run = ":TSUpdate",
            })
            use({ "williamboman/nvim-lsp-installer" })
            use({
                "neovim/nvim-lspconfig",
                config = function()
                    local on_attach = function(client)
                        if client.resolved_capabilities.signature_help then
                            require("lsp_signature").on_attach({
                                floating_window = true,
                                hint_enable = false,
                                hi_parameter = "IncSearch",
                            })
                        end
                    end

                    local function make_config()
                        local capabilities = vim.lsp.protocol.make_client_capabilities()
                        capabilities = require("cmp_nvim_lsp").update_capabilities(
                            capabilities
                        )
                        return {
                            capabilities = capabilities,
                            on_attach = on_attach,
                        }
                    end
                    local lsp_installer = require("nvim-lsp-installer")
                    local lsp_installer_path = "/tmp/nvim/lsp_servers/"
                    lsp_installer.settings({
                        install_root_dir = lsp_installer_path,
                    })

                    lsp_installer.on_server_ready(function(server)
                        local default_opts = make_config()

                        -- server specific options
                        local server_opts = {
                            ["clangd"] = function()
                                local custom_opts = make_config()
                                custom_opts.cmd = {
                                    lsp_installer_path .. "/clangd/clangd",
                                    "--background-index",
                                    "--clang-tidy",
                                }
                                return custom_opts
                            end,
                        }

                        -- call server setup (equivalent to lspconfig's setup function)
                        server:setup(
                            server_opts[server.name] and server_opts[server.name]()
                                or default_opts
                        )
                        vim.cmd([[ do User LspAttachBuffers ]])
                        vim.diagnostic.config({
                            underline = false,
                            virtual_text = false,
                            signs = true,
                            update_in_insert = false,
                            float = { border = "rounded" },
                        })
                    end)
                end,
            })
            use({ "ray-x/lsp_signature.nvim" })
        end,
        config = {
            package_root = package_root,
            compile_path = install_path .. "/plugin/packer_compiled.lua",
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({
        "git",
        "clone",
        "https://github.com/wbthomason/packer.nvim",
        install_path,
    })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end
Test file
#include <iostream>

auto sum(int a, int b) -> int
{
    return a+b;
}

auto main(int argc, char *argv[]) -> int
{

    return 0;
}

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

@ranebrown I can't reproduce your issue using your config (I am able to jump to the next / previous tabstop normally). What are the necessary steps to reproduce your issue and what is the expected behaviour?

from cmp-nvim-ultisnips.

ranebrown avatar ranebrown commented on August 16, 2024
  1. Save above files as minimal_init.lua and test.cpp
  2. nvim -u minimal_init.lua after packer install run :LspInstall clangd
  3. quit
  4. nvim -u minimal_init.lua test.cpp
  5. Go to main function and start typing sum select LSP snippet for sum() from cmp menu and expand with C-y
  6. Type 1 for first argument. Hit tab to go to next argument and it inserts a literal tab.

Expected behavior is to jump to the second argument position while showing the lsp signature floating window. The jumping works correctly if lsp signature floating window is disabled.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

Thanks for your reproduction steps, could reproduce it now.

from cmp-nvim-ultisnips.

smjonas avatar smjonas commented on August 16, 2024

I don't think this is related to cmp-nvim-ultisnips since it also happens with this config (I removed the mappings and plugin). Closing for now.

Minimal config
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])

local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"

local function load_plugins()
    require("packer").startup({
        function(use)
            use({ "wbthomason/packer.nvim" })
            use({ "SirVer/ultisnips" })
            use({
                "hrsh7th/nvim-cmp",
                requires = {
                    "hrsh7th/cmp-nvim-lsp",
                },
                config = function()
                    local cmp = require("cmp")

                    cmp.setup({
                        snippet = {
                            expand = function(args)
                                vim.fn["UltiSnips#Anon"](args.body)
                            end,
                        },
                        sources = {
                            { name = "nvim_lsp", priority = 100, group_index = 1 },
                        },
                    })
                end,
            })
            use({
                "nvim-treesitter/nvim-treesitter",
                config = function()
                    require("nvim-treesitter.configs").setup({
                        ensure_installed = {"cpp" },
                        highlight = { enable = true },
                    })
                end,
                run = ":TSUpdate",
            })
            use({ "williamboman/nvim-lsp-installer" })
            use({
                "neovim/nvim-lspconfig",
                config = function()
                    local on_attach = function(client)
                        if client.resolved_capabilities.signature_help then
                            require("lsp_signature").on_attach({
                                floating_window = true,
                                hint_enable = false,
                                hi_parameter = "IncSearch",
                            })
                        end
                    end

                    local function make_config()
                        local capabilities = vim.lsp.protocol.make_client_capabilities()
                        capabilities = require("cmp_nvim_lsp").update_capabilities(
                            capabilities
                        )
                        return {
                            capabilities = capabilities,
                            on_attach = on_attach,
                        }
                    end
                    local lsp_installer = require("nvim-lsp-installer")
                    local lsp_installer_path = "/tmp/nvim/lsp_servers/"
                    lsp_installer.settings({
                        install_root_dir = lsp_installer_path,
                    })

                    lsp_installer.on_server_ready(function(server)
                        local default_opts = make_config()

                        -- server specific options
                        local server_opts = {
                            ["clangd"] = function()
                                local custom_opts = make_config()
                                custom_opts.cmd = {
                                    lsp_installer_path .. "/clangd/clangd",
                                    "--background-index",
                                    "--clang-tidy",
                                }
                                return custom_opts
                            end,
                        }

                        -- call server setup (equivalent to lspconfig's setup function)
                        server:setup(
                            server_opts[server.name] and server_opts[server.name]()
                                or default_opts
                        )
                        vim.cmd([[ do User LspAttachBuffers ]])
                        vim.diagnostic.config({
                            underline = false,
                            virtual_text = false,
                            signs = true,
                            update_in_insert = false,
                            float = { border = "rounded" },
                        })
                    end)
                end,
            })
            use {
              "ray-x/lsp_signature.nvim",
              config = function()
                require"lsp_signature".setup {
                  floating_window = false,
                }
              end
            }
        end,
        config = {
            package_root = package_root,
            compile_path = install_path .. "/plugin/packer_compiled.lua",
        },
    })
end

if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system({
        "git",
        "clone",
        "https://github.com/wbthomason/packer.nvim",
        install_path,
    })
    load_plugins()
    require("packer").sync()
else
    load_plugins()
    require("packer").sync()
end

from cmp-nvim-ultisnips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.