emmet-ls
emmet-ls copied to clipboard
add custom `emmet/parseMarkup` handler
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
Thanks for the PR. @arafatamim Can you elaborate about the usage for this? Documenting about the feature would be really great.
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,
}
...
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
Here's an update about that https://github.com/aca/emmet-ls/issues/55#issuecomment-1615250107