rust-sailfish / sailfish

Simple, small, and extremely fast template engine for Rust
https://rust-sailfish.github.io/sailfish/
MIT License
800 stars 54 forks source link

Templates plugin on Neovim #140

Open antoinekahlouche opened 10 months ago

antoinekahlouche commented 10 months ago

I have troubles using the "rust-sailfish/sailfish" plugin.

I’m using Packer on Neovim : use 'rust-sailfish/sailfish' I checked and the package is installed but when I access a .stpl file, my :LspInfo doesn’t recognize the filetype. So the plugin is not loaded.

My LSP plugins are 'VonHeikemen/lsp-zero.nvim' with 'neovim/nvim-lspconfig'

I’m pretty sure I miss a step, can someone help me ?

gengjun commented 9 months ago

That plugin is not working for me, I just put this code to my lua vim config, it force nvim think .stpl is .html file

local autocmd = vim.api.nvim_create_autocmd
autocmd({
    "BufNewFile",
    "BufRead",
}, {
    pattern = "*.stpl",
    callback = function()
        if vim.fn.search("{{.\\+}}", "nw") ~= 0 then
            local buf = vim.api.nvim_get_current_buf()
            vim.api.nvim_buf_set_option(buf, "filetype", "html")
        end
    end,
})
antoinekahlouche commented 9 months ago

@gengjun thanks for your answer

I have no problem with Neovim detecting the HTML part, I think, with my setup, if it doesn't know the extension it looks inside and infers the language.

And if you want to enforce it, you can do something simpler :

vim.filetype.add({
    extension = {
        stpl = 'html',
    }
})

My problem is that the Rust part of my templates is not detected as Rust code. So I was hoping this plugin would help me

antoinekahlouche commented 9 months ago

I stumbled upon this video from TJ DeVries

So I tried the Tree Sitter Playground. It understands the HTML part because it's the current LSP. But for the rust part I get ERROR nodes. So, I'm a bit stuck in this path also.

alf5 commented 8 months ago

apologies I'm a neovim newbie. Are the vim files inside https://github.com/rust-sailfish/sailfish/tree/main/syntax/vim useful within NeoVim? if not, can they be used to help create a neovim plugin?