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

Char before inserted completion is deleted, if line is indented by tabs #352

Closed
crater2150 opened this issue Oct 13, 2021 · 14 comments
Closed

Comments

@crater2150
Copy link

When completing from the nvim-lsp source (using Scala Metals language server), one char before the inserted completion is deleted, e.g. the dot before a method or a parenthesis in front of the completed word.
After long config bisecting, I found that this curiously only happens, if the line is indented by tabs, not if it is indented by spaces.

Here is a recording of the behaviour (showing the difference between space and tab indents):
https://asciinema.org/a/RvlyJNxrJ9R8oQU1XT4kvfNmk

The full configuration used (https://gist.github.com/crater2150/256d81bf766144e4158176e632bb8ac8, mostly from Readme + Metals config):

call plug#begin(expand('<sfile>:p:h') . '/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/nvim-cmp'
Plug 'nvim-lua/plenary.nvim'
Plug 'scalameta/nvim-metals'

Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'

call plug#end()

set completeopt=menu,menuone,noselect

lua <<EOF
  -- Setup nvim-cmp.
  local cmp = require'cmp'

  cmp.setup({
    snippet = {
      expand = function(args)
        vim.fn["vsnip#anonymous"](args.body)
      end,
    },
    mapping = {
      ['<C-d>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.close(),
      ['<CR>'] = cmp.mapping.confirm({ select = true }),
    },
    sources = {
      { name = 'nvim_lsp' },
      { name = 'vsnip' },
      { name = 'buffer' },
    }
  })

  -- Setup lsp.
  metals_config = require("metals").bare_config
  metals_config.init_options.statusBarProvider = "on"
  metals_config.settings = { showImplicitArguments = true }
  metals_config.on_attach = on_attach
  metals_config.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
EOF
augroup lsp
	au!
	au FileType scala,sbt lua require("metals").initialize_or_attach({})
augroup end

I'm not sure if this is specific to the metals language server, as I don't use any others currently. I may be able to try out something else tomorrow evening.
The small Scala example used in the recording can be found at https://github.com/crater2150/nvim-cmp-bug-demo

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 16, 2021

I don't met this problem with gopls.

The golang is always uses the Tab for indentation.

@crater2150
Copy link
Author

I've now tried with python (pyright) and typescript (tsserver), and also couldn't reproduce it.
But I also tried with Metals using manual completion via setlocal omnifunc=v:lua.vim.lsp.omnifunc, which also doesn't show the problem (rest of config identical, I can reproduce the error in the same buffer with autocompletion, but not with <C-x><C-o>).

Also the problem doesn't occur, if i use nvim-compe, but it's not an alternative for me, because of hrsh7th/nvim-compe#527

Is there any additional debug information I could provide?

@elianiva
Copy link
Contributor

elianiva commented Nov 1, 2021

I found this issue on both tsserver and gopls. Though I doesn't seem to be consistent? Most of the time it happens when I type some characters and then confirm the first suggestion. I've attached a screencast to better explain it.

simplescreenrecorder-2021-11-01_21.12.27.mp4

Minimal init.lua

edit: apparently it only happens when native_menu is being used, using cmp custom popup implementation fixed it

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 3, 2021

@elianiva Thank you for your information. It's very helpful and I could reproduce.

In the first place, I feel that the native menu of nvim-cmp is not working properly.

I will fix it...

@hrsh7th hrsh7th mentioned this issue Nov 3, 2021
2 tasks
@hrsh7th
Copy link
Owner

hrsh7th commented Nov 3, 2021

I'm sorry. The native menu just didn't work because the main branch was buggy a while ago.

I will re-test it.

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 3, 2021

Oh... after updating gopls, I'd reproduce it too.

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 3, 2021

@elianiva Thank you. I've fixed it by a881adb

Hm... but I think the original issue report does not relate to this fix...

@crater2150
Copy link
Author

Hm... but I think the original issue report does not relate to this fix...

Can confirm, my issue is still present with the current commit.

@dolenam317
Copy link

I don't met this problem with gopls.

The golang is always uses the Tab for indentation.

I am having this same issue with gopls as well.

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 16, 2021

@dolenam317 Could you provide the reproduction steps and minimal configuration?

@hrsh7th hrsh7th closed this as completed Apr 2, 2022
@crater2150
Copy link
Author

This issue is still present with the current main branch, why was it closed?

@Shougo
Copy link

Shougo commented Apr 6, 2022

@dolenam317 Could you provide the reproduction steps and minimal configuration?

Please see this.
You need to upload the minimal configuration and the reproduction steps.

@Shougo
Copy link

Shougo commented Apr 6, 2022

#352 (comment)

I think the config can be more reduced.

@crater2150
Copy link
Author

It looks like the problem has gone away with the update to neovim 0.7

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

No branches or pull requests

5 participants