Nvim-lspconfig: omni completion results duplicate $ character

Created on 12 Feb 2020  路  9Comments  路  Source: neovim/nvim-lspconfig

When triggering omni completion CTRL-X_CTRL-O on the $ character, all matches will ignore the first $ and duplicate it. For example, when using the intelephense LS, if I trigger omni completion it will result in $$GLOBALS. The expected behavior is $GLOBALS.

bug needs-repro

All 9 comments

@JamesGreenaway I don't use php. So would you show me some projects to test?

  1. Set up neovim with LSP and intelephense.
  2. Create a php file:
<?php
$ <--- run omni-completion after this character and choose the first result.
?>

The first result should be $GLOBAL.

  1. The file should then look like this:
<?php
$$GLOBAL
?>

Let me know if you need a screenshot.

I can't reproduce it.
https://terminalizer.com/view/2a0a07ae3096

setlocal omnifunc=v:lua.vim.lsp.omnifunc

it only happens when I set:

autocmd Filetype php setlocal omnifunc=v:lua.vim.lsp.omnifunc

@JamesGreenaway Would you show me minimal vimrc for this issue?

Perhaps I have set it up incorrectly. I followed the instructions in the help file.

  1. Install the nvim-lsp plugin.  It provides common configuration for
     various servers so you can get started quickly.
     https://github.com/neovim/nvim-lsp
  2. Install a language server.  Try ":LspInstall <tab>" or use your system
     package manager to install the relevant language server:
     https://microsoft.github.io/language-server-protocol/implementors/servers/
  3. Add `nvim_lsp.xx.setup{鈥` to your vimrc, where "xx" is the name of the
     relevant config.  See the nvim-lsp README for details.

To check LSP clients attached to the current buffer:  >

  :lua print(vim.inspect(vim.lsp.buf_get_clients()))
<
                                                        *lsp-config*
Inline diagnostics are enabled automatically, e.g. syntax errors will be
annotated in the buffer.  But you probably want to use other features like
go-to-definition, hover, etc.  Example config: >

  nnoremap <silent> gd    <cmd>lua vim.lsp.buf.declaration()<CR>
  nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
  nnoremap <silent> K     <cmd>lua vim.lsp.buf.hover()<CR>
  nnoremap <silent> gD    <cmd>lua vim.lsp.buf.implementation()<CR>
  nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
  nnoremap <silent> 1gD   <cmd>lua vim.lsp.buf.type_definition()<CR>
  nnoremap <silent> gr    <cmd>lua vim.lsp.buf.references()<CR>

Nvim provides the |vim.lsp.omnifunc| 'omnifunc' handler which allows
|i_CTRL-X_CTRL-O| to consume LSP completion. Example config (note the use of
|v:lua| to call Lua from Vimscript): >

  " Use LSP omni-completion in Python files.
  autocmd Filetype python setlocal omnifunc=v:lua.vim.lsp.omnifunc

This is what I put in my vimrc:

call plug#begin('~/.vim/plugged')
Plug 'neovim/nvim-lsp'
call plug#end()

lua << EOF
local nvim_lsp = require'nvim_lsp'
nvim_lsp.intelephense.setup{}
EOF

autocmd Filetype php setlocal omnifunc=v:lua.vim.lsp.omnifunc

It seems that the Lua script and the autocmd duplicate the omnifunc.

Can you confirm what is best practice?

It seems that the Lua script and the autocmd duplicate the omnifunc.

You probably want to use the on_attach hook instead of using an autocmd:

local on_attach = function(client, bufnr)
  -- Set the omnifunc for this buffer.
  vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")

  -- Configure some mappings for this buffer.
  local opts = { noremap=true, silent=true }
  vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
end

nvim_lsp.intelephense.setup({ on_attach=on_attach })

@JamesGreenaway Is this still an issue?

Nope.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matklad picture matklad  路  5Comments

DarkDefender picture DarkDefender  路  3Comments

nomasprime picture nomasprime  路  5Comments

agriffis picture agriffis  路  5Comments

cideM picture cideM  路  6Comments