How to show paths for auto imports with neovim nvim-cmp

Viewed 544

Using neovim with nvim-cmp in ecmascript/typescript i want the menu to show 2 things that are not there by default.

  1. If its a local module, show the path.

  2. If its a import from a library, show the library name. (preferably in different color/font/icon than import from local component).

The docs shows a few examples of how to setup icons, but not how to show paths.

1 Answers

You can achieve something similar by adding these lines in the format function while calling nvim-cmp's setup:

  if entry.completion_item.detail ~= nil and entry.completion_item.detail ~= "" then
    vim_item.menu = entry.completion_item.detail
  else
    vim_item.menu = ({
      nvim_lsp = "[LSP]",
      luasnip = "[Snippet]",
      buffer = "[Buffer]",
      path = "[Path]",
    })[entry.source.name]
  end

result:

enter image description here

Related