tree-sitter / tree-sitter-embedded-template

Tree-sitter grammar for embedded template languages like ERB, EJS
MIT License
60 stars 17 forks source link

Cannot get syntax highlighting #17

Closed hamidreza4dev closed 1 year ago

hamidreza4dev commented 1 year ago

Hi, I installed the plugin but I can't have syntax highlighting. I also typed these commands: :TSInstall ejs :TSBufEnable hightlight

My config repo : https://github.com/hamidreza4dev/dotfiles

image image
hamidreza4dev commented 1 year ago

Changing the file extension to html and changing it again to ejs solves the problem. Do you have any opinion at all?

p-m-p commented 1 year ago
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.embedded_template = {
  install_info = {
    url = "https://github.com/tree-sitter/tree-sitter-embedded-template",
    files = {"src/parser.c"},
    requires_generate_from_grammar = false,
  },
}

local ft_to_parser = require"nvim-treesitter.parsers".filetype_to_parsername
ft_to_parser.ejs = "embedded_template"

vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
  pattern = "*.ejs",
  command = "set filetype=ejs"
})

This works for me without having to install any other plugins. I think issue is that ejs is not a recognized file type so needs to be mapped to the embedded_template file type.

hamidreza4dev commented 1 year ago
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.embedded_template = {
  install_info = {
    url = "https://github.com/tree-sitter/tree-sitter-embedded-template",
    files = {"src/parser.c"},
    requires_generate_from_grammar = false,
  },
}

local ft_to_parser = require"nvim-treesitter.parsers".filetype_to_parsername
ft_to_parser.ejs = "embedded_template"

vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
  pattern = "*.ejs",
  command = "set filetype=ejs"
})

This works for me without having to install any other plugins. I think issue is that ejs is not a recognized file type so needs to be mapped to the embedded_template file type.

This code worked and syntax highlighting was fixed. Do you have an idea to get auto-completion using cmp-nvim ?

p-m-p commented 1 year ago

I'm no expert but you can see my personal configs here https://github.com/p-m-p/nvim-config/blob/main/plugin/cmp.lua