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

add custom emmet/parseMarkup handler #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arafatamim
Copy link

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

@aca aca self-assigned this Oct 31, 2022
@aca
Copy link
Owner

aca commented Oct 31, 2022

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

@arafatamim
Copy link
Author

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,
}
...

@Cryxto
Copy link

Cryxto commented Apr 15, 2023

I think this pull request related to this issue :
#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

@olrtg
Copy link
Collaborator

olrtg commented Jun 30, 2023

Here's an update about that #55 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants