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(entry/get_replace_range): handle TextEdit.range #1140

Merged
merged 1 commit into from
Aug 20, 2022

Conversation

lvimuser
Copy link
Contributor

@lvimuser lvimuser commented Aug 19, 2022

fixes cmp.mapping.confirm when ConfirmBehavior is set to Replace


Some servers send a TextEdit in the following form

{
  newText = '"javascript.suggest.names": ${1:true}',
  range = {
    end = {
      character = 0,
      line = 2
    },
    start = {
      character = 0,
      line = 2
    }
  }
}

Before/after:

a.mp4

I've seen this behavior on cssls/html/jsonls/gopls.

See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textEdit and LunarVim/LunarVim#2876 (comment).

Repro:

vimrc.vim

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = cmp.mapping.preset.insert{
    ["<CR>"] = cmp.mapping.confirm({ select = true, behavior = cmp.ConfirmBehavior.Replace }),
    ["<C-space>"] = cmp.mapping(function()
      cmp.complete(cmp.ContextReason.Manual)
    end),
  },

  sources = cmp.config.sources({
    { name = "nvim_lsp" },
  }),
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'lspconfig'.jsonls.setup {
  capabilities = capabilities,
}
EOF

tsserver.json

{
"$schema": "https://raw.githubusercontent.com/tamago324/nlsp-settings.nvim/main/schemas/_generated/tsserver.json",
}

fixes cmp.mapping.confirm when ConfirmBehavior is set to Replace
@hrsh7th
Copy link
Owner

hrsh7th commented Aug 20, 2022

LGTM. Thank you!

@hrsh7th hrsh7th merged commit 27bc575 into hrsh7th:main Aug 20, 2022
williamboman added a commit to williamboman/nvim-cmp that referenced this pull request Sep 23, 2022
…indow

* upstream/main: (36 commits)
  feat: add `filter` option to sources (hrsh7th#1067)
  Restore rockspec
  Fix grammar mistake: "setup" -> "set up" (hrsh7th#1155)
  fix(timer): close timers before Neovim exits (hrsh7th#1166)
  Add incsearch_redraw_keys settings (hrsh7th#1162)
  Fix hrsh7th#1149 (temporary fix)
  Fix hrsh7th#1146
  Re-fix hrsh7th#1144
  Fix hrsh7th#1144
  Fix hrsh7th#1142
  Fix hrsh7th#1135
  Fix onetime configuration handling
  fix(entry/get_replace_range): handle TextEdit.range (hrsh7th#1140)
  Refactor a bit
  Restore filetype setting
  Fix hrsh7th#1139
  Add FAQ for clangd's command-line arguments. Fixes hrsh7th#999
  The default highlight groups shouldn't be default=true. Fixes hrsh7th#972
  Fix hrsh7th#1102
  Use `cmp.config.sources` (hrsh7th#1105)
  ...
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