hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.77k stars 385 forks source link

Is there a way to set a custom filetype for documentation #1472

Open taDachs opened 1 year ago

taDachs commented 1 year ago

Hello there, I am currently working on a custom source for ros messages. The text I want to display as the documentation is a custom filetype (currently called "ros") with custom highlighting etc.

How can I set the filetype for the documentation window to a custom filetype? lsp.MarkupContent seems to only support markdown and plaintext

hrsh7th commented 1 year ago

You can use markdown's fenced code block.

\`\`\`ros
taDachs commented 1 year ago

I tried it like this:

function source:resolve(completion_item, callback)
  if completion_item.data.msg ~= nil then
    completion_item.documentation = {
      kind = require("cmp").lsp.MarkupKind.Markdown,
      value = "```\n" .. table.concat(completion_item.data.msg.definition, "\n") .. "\n```",
    }
  end

  callback(completion_item)
end

but that doesn't seem to work. Maybe because the highlighting is only available via treesitter? I am not too familiar with the internals of nvim-cmp, so there doesn't seem to be a way to set the filetype for the buffer the documentation is displayed in directly

taDachs commented 1 year ago

I have implemented a (hacky) way to set the ft per documentation entry. I opened PR #1490 if you are interested