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

typescript-language-server completions don't show expandable indicator until selected #1665

Open
2 tasks done
llllvvuu opened this issue Jul 25, 2023 · 0 comments · May be fixed by #1666
Open
2 tasks done

typescript-language-server completions don't show expandable indicator until selected #1665

llllvvuu opened this issue Jul 25, 2023 · 0 comments · May be fixed by #1666
Labels
bug Something isn't working

Comments

@llllvvuu
Copy link

llllvvuu commented Jul 25, 2023

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

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
vim.opt.completeopt = "menu,menuone,noselect"
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Tab>'] = cmp.mapping(function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      else
        fallback()
      end
    end, { 'i', 's' }),
  },

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

lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
require'lspconfig'.tsserver.setup {
  capabilities = capabilities,
  settings = {
    completions = {
      completeFunctionCalls = true,
    },
  },
}
EOF

Description

See "Steps to reproduce"

Steps to reproduce

In a new directory:

tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./*"]
    }
  }
}

foo.ts:

export const foooooo = 5
export const foooooo1 = 5
export const foooooo2 = 5
export const foooooo3 = 5

In a new file bar.ts:

  • Write console. -> cycle through function completions. ~ will only appear once an item has been selected:
fn_completion.mp4
  • Write console.log(foo -> cycle through auto-import completions. ~ will only appear once an item has been selected:
auto_import.mp4

Expected behavior

Should show ~ upfront in menu

Actual behavior

See "Steps to reproduce"

Additional context

In typescript-language-server you can tell upfront from completionItem.data.entryNames[0].source that there will be an auto-import, but this seems to be their internal convention and not an LSP convention. additionalTextEdits is not populated until completion is resolved.

Similarly, in typescript-language-server, function snippets do not update insertText until completion resolve. But it does set InsertTextFormat.Snippet upfront.

So, I would propose that in:

nvim-cmp/lua/cmp/entry.lua

Lines 245 to 246 in c4e491a

elseif completion_item.insertTextFormat == types.lsp.InsertTextFormat.Snippet then
is_expandable = self:get_insert_text() ~= word

the following change be made:

-      is_expandable = self:get_insert_text() ~= word
+      is_expandable = self:get_insert_text() ~= completion_item.label

since I assume the indicator is supposed to indicate that you'll get a result which is different from just the label? But IDK how common this even is. The following might be preferable:

-      is_expandable = self:get_insert_text() ~= word
+      is_expandable = true
@llllvvuu llllvvuu added the bug Something isn't working label Jul 25, 2023
@llllvvuu llllvvuu changed the title TypeScript completions don't show expandable indicator until selected typescript-language-server completions don't show expandable indicator until selected Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant