windwp / nvim-ts-autotag

Use treesitter to auto close and auto rename html tag
MIT License
1.69k stars 90 forks source link

support for django (htmldjango)? #48

Closed shaeinst closed 2 years ago

shk3t commented 2 years ago

Still have this problem (nvim v0.7). Have filetypes = { "htmldjango", ... in config files. It seems to be trying to do something, considering mode indicator blinking. Peek 2022-05-13 00-34 I really love this plugin, but this issue makes me disappointed.

yujinyuz commented 2 years ago

I also have the same experience with @shket-228

ambadyanands commented 2 years ago

Confirming that the issue still persists, it'd be good to reopen the issue. Or should I create a new one?

shaeinst commented 2 years ago

are you sure guys? try as following config

-- enable html parser in htmldjango file
local import_parsers, parsers = pcall(require, 'nvim-treesitter.parsers')
if import_parsers then
    local parsername = parsers.filetype_to_parsername
    parsername.htmldjango = 'html' 
end

local import_tag, autotag = pcall(require, "nvim-ts-autotag")
if not import_tag then return end
autotag.setup({
    autotag = {
        enable = true,
    },
    filetypes = {
        'html', 'htmldjango',
    },
})
ambadyanands commented 2 years ago

@shaeinst Thanks a lot, enabling html parser for htmldjango filetype did the trick.

I think nvim-treesitter should do this by default. Will try opening an issue there, thanks again.

comiluv commented 1 year ago

I'm still having problems. I already have filetypes = { 'htmldjango', 'html', ... } in nvim-treesitter config. I tried both lua require"nvim-treesitter.parsers".filetype_to_parsername.htmldjango = 'html' and lua vim.treesitter.language.register("html", "htmldjango") but none of these worked. Only way I could get autotag to work is to set ft=html but this would cause LSPs to fail.

shaeinst commented 1 year ago

for neovim >= 0.9

-- safely import tree-sitter
local treesitter_imported_ok, treesitter =  pcall(require, 'nvim-treesitter.configs')
if not treesitter_imported_ok then return end

local register = vim.treesitter.language.register
register('html', 'htmldjango') -- enable html parser in htmldjango file

local import_tag, autotag = pcall(require, "nvim-ts-autotag")
if not import_tag then return end
autotag.setup({
    autotag = {
        enable = true,
    },
    filetypes = {
        'html', 'htmldjango',
    },
})

reference

Coleej commented 1 year ago

@shaeinst , don't you lose syntax highlighting for the templating aspects of the htmldjango file?

an4s911 commented 9 months ago

Does this have a fix yet?

I am still facing the same issue. I tried all the solutions mentioned above in this thread. None of them worked.

aketawi commented 8 months ago

Not sure what exactly this entails since I don't have much experience in Lua, but: After hacking around for a little while I've found that removing "htmldjango" from the HBS_TAG.filetypes seems to do the trick. Perhaps it's overwriting the definition in HTML_TAG?

https://github.com/windwp/nvim-ts-autotag/blob/531f48334c422222aebc888fd36e7d109cb354cd/lua/nvim-ts-autotag/internal.lua#L69 It was last changed in this commit: https://github.com/windwp/nvim-ts-autotag/commit/25698e4033cd6cd3745454bfc837dd670eba0480 and I can't find the reason why.

Dunno if we should file this as a bug or if this has a reason to exist, but for the time being, to enable django support you can just remove it on line 69 of lua/nvim-ts-autotag/internal.lua.

@an4s911 @comiluv @shk3t @shaeinst you might find this helpful.

Alan-Manning commented 6 months ago

i still cannot get this working, i have tried all of the above and nothing. If anybody has fixed please post