support treesitter

This commit is contained in:
kola
2024-08-09 18:05:31 +08:00
parent 3fb2f63799
commit c5c5188a0b
2 changed files with 31 additions and 2 deletions

View File

@@ -379,8 +379,12 @@ function! emmet#getFileType(...) abort
endif
endif
let pos = emmet#util#getcurpos()
let type = synIDattr(synID(max([pos[1], 1]), max([pos[2], 1]), 1), 'name')
if exists('g:loaded_nvim_treesitter') == 1
let type = luaeval('require"my_utils".get_node_at_cursor()')
else
let pos = emmet#util#getcurpos()
let type = synIDattr(synID(max([pos[1], 1]), max([pos[2], 1]), 1), 'name')
endif
" ignore htmlTagName as it seems to occur too often
if type == 'htmlTagName'

25
lua/my_utils.lua Normal file
View File

@@ -0,0 +1,25 @@
local M = {}
M.get_node_at_cursor = function()
local ts_utils = require("nvim-treesitter.ts_utils")
local node = ts_utils.get_node_at_cursor()
if not node then
return nil
end
while node do
local node_type = node:type()
if node_type == "element" then
return "html"
elseif node_type == "stylesheet" then
return "css"
end
node = node:parent()
end
return ""
end
return M