5 Commits

Author SHA1 Message Date
Kevin Rambaud
7d19d812a3 Merge a37097cf18 into 6c511a8d7d 2024-12-02 07:21:53 +00:00
mattn
6c511a8d7d Merge pull request #558 from kola-web/master
support treesitter
2024-08-10 11:07:49 +09:00
kola
033476412e Change treesitter judgment method 2024-08-10 09:32:53 +08:00
kola
8f1581550d my_utils.lua -> emmet_utils.lua 2024-08-10 09:29:20 +08:00
kola
c5c5188a0b support treesitter 2024-08-09 18:06:47 +08:00
2 changed files with 31 additions and 2 deletions

View File

@@ -379,8 +379,12 @@ function! emmet#getFileType(...) abort
endif endif
endif endif
let pos = emmet#util#getcurpos() if get(g:, 'loaded_nvim_treesitter', 0)
let type = synIDattr(synID(max([pos[1], 1]), max([pos[2], 1]), 1), 'name') let type = luaeval('require"emmet_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 " ignore htmlTagName as it seems to occur too often
if type == 'htmlTagName' if type == 'htmlTagName'

25
lua/emmet_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