emmet-ls icon indicating copy to clipboard operation
emmet-ls copied to clipboard

add custom `emmet/parseMarkup` handler

Open arafatamim opened this issue 2 years ago • 4 comments

why? Exposes some APIs to be used by the frontend to enable the user to customize certain behaviors, for example, filtering out the completion result if the starting node is parsed as a div

arafatamim avatar Oct 27 '22 19:10 arafatamim

Thanks for the PR. @arafatamim Can you elaborate about the usage for this? Documenting about the feature would be really great.

aca avatar Oct 31 '22 04:10 aca

Here's how I use it in nvim-cmp to filter out results that don't start with valid HTML tags. I'm aware this is a band-aid solution, but figured it might be useful for some people.

...
{
   name = "nvim_lsp",
   entry_filter = function(entry, ctx)
   local kinds = require("cmp.types").lsp.CompletionItemKind
   if kinds[entry:get_kind()] == "Snippet" then
      local lsp = vim.split(entry.source:get_debug_name(), ":")[2]
      if lsp == "emmet_ls" then
         local line = ctx.cursor_line
         local words = vim.split(line, " ")
         local last_fragment = words[#words]
         if vim.startswith(last_fragment, "#") or vim.startswith(last_fragment, ".") then
            return true
         end
         local parsed_markup = entry.source.source.client.request_sync(
         "emmet/parseMarkup",
         { text = last_fragment }
         )
         if parsed_markup["result"] == nil then
            return false
         end
         local starting_tag = parsed_markup["result"]["data"]["children"][1]["name"]
         return vim.tbl_contains(html_tags, starting_tag)
      end
   end
   return true
   end,
}
...

arafatamim avatar Oct 31 '22 07:10 arafatamim

I think this pull request related to this issue : https://github.com/aca/emmet-ls/issues/55 for example asdf expands into <asdf></asdf>. The emmet-ls is turn non html arbitary word into tag, which kinda annoying. But maybe after the fix, user that relies on Mason (it use npm) cannot get it fixed because on npm version stll use 0.3.1 version

Cryxto avatar Apr 15 '23 03:04 Cryxto

Here's an update about that https://github.com/aca/emmet-ls/issues/55#issuecomment-1615250107

olrtg avatar Jun 30 '23 23:06 olrtg