3

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

  1. If it's a local module, show the path.

  2. If it's an 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 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.