EmranMR / tree-sitter-blade

tree-sitter grammar for Laravel blade files
MIT License
186 stars 8 forks source link

File Extension Detection Needing Fixed #6

Closed EmranMR closed 1 year ago

EmranMR commented 1 year ago

The file-types in the package.json needs to change to blade.php however double barrelled names are apparently not supported by tree-sitter. As an alternative the array suffix has been used for time being during the development of this parser

"file-types: ["blade.php"]
unansweredocd commented 1 year ago

What I do in Neovim is that I first tell Neovim that blade is a filetype by doing

vim.filetype.add({
  pattern = {
    [".*%.blade.php"] = "blade",
  },
})

I then set the following, locally, to make sure that your tree-sitter parser is picked up and recognized.

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.blade = {
  install_info = {
    url = "~/tree-sitter-blade", -- local path or git repo
    files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
    -- optional entries:
    branch = "main", -- default branch in case of git repo if different from master
    generate_requires_npm = false, -- if stand-alone parser without npm dependencies
    requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
  }
}

If I then open up example-file.blade.php, and run :InspectTree, I notice that the blade parser is being recognized.

And if I do :lua print(vim.bo.filetype), I get blade.

EmranMR commented 1 year ago

What I do in Neovim is that I first tell Neovim that blade is a filetype by doing

vim.filetype.add({
  pattern = {
    [".*%.blade.php"] = "blade",
  },
})

I then set the following, locally, to make sure that your tree-sitter parser is picked up and recognized.

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.blade = {
  install_info = {
    url = "~/tree-sitter-blade", -- local path or git repo
    files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
    -- optional entries:
    branch = "main", -- default branch in case of git repo if different from master
    generate_requires_npm = false, -- if stand-alone parser without npm dependencies
    requires_generate_from_grammar = false, -- if folder contains pre-generated src/parser.c
  }
}

If I then open up example-file.blade.php, and run :InspectTree, I notice that the blade parser is being recognized.

And if I do :lua print(vim.bo.filetype), I get blade.

@unansweredocd thanks for sharing this! I actually think a lot of people would benefit from this so I might even include it in the README. Especially the ones new to NeoVim.

Nova is the same, it’s the editor in charge of deciding what syntax is used for what file-type.

The only problem is working on or contributing to this project from developer point of view using purely cli and terminal alone. Hopefully the tree-sitter core team adds the functionality sometime soon🤞until then we just have to use a tree-sitter based editors for debug/dev 😊

EmranMR commented 1 year ago

example-file extension has been changed to a .blade as a workaround in 00081bf, until this feature is added by tree-sitter core