diff options
| author | kiyan42 <yazdani.kiyan@protonmail.com> | 2020-06-20 12:21:42 +0200 |
|---|---|---|
| committer | kiyan42 <yazdani.kiyan@protonmail.com> | 2020-06-20 12:31:52 +0200 |
| commit | df17a48c85b8e47bc4982b640dbb686e372cd81e (patch) | |
| tree | a3071e4c045485bf70b4d508887305d4f279a8c7 /lua/nvim-treesitter/parsers.lua | |
| parent | ad636f4f5306b7741bc55ad63e6b12f9379a2515 (diff) | |
refactor: parser list and lang->ft/ft->lang
- move parser list in `parsers.lua`
- most `ft` variable where changed to `lang`, `ft` is only used on
autocmd binding, and lang is used for everything else. Functions have
been defined to make the switch between `ft` and `lang`
Diffstat (limited to 'lua/nvim-treesitter/parsers.lua')
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 244 |
1 files changed, 241 insertions, 3 deletions
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 3789b7af..ae0fce27 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1,17 +1,255 @@ local api = vim.api local ts = vim.treesitter -local M = {} +local list = {} + +list.javascript = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-javascript", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.c = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c", + files = { "src/parser.c" } + } +} + +list.cpp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-cpp", + files = { "src/parser.c", "src/scanner.cc" } + } +} + +list.rust = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-rust", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.lua = { + install_info = { + url = "https://github.com/nvim-treesitter/tree-sitter-lua", + files = { "src/parser.c", "src/scanner.cc" } + } +} + +list.python = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-python", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.go = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-go", + files = { "src/parser.c" }, + } +} + +list.ruby = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ruby", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.bash = { + install_info = { + url = "https://github.com/nvim-treesitter/tree-sitter-bash", + files = { "src/parser.c", "src/scanner.cc" }, + }, + filetype = 'sh' +} + +list.php = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-php", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.java = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-java", + files = { "src/parser.c" }, + } +} + +list.html = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-html", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.julia = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-julia", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.json = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-json", + files = { "src/parser.c" }, + } +} + +list.css = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-css", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.ocaml = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ocaml", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.swift = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-swift", + files = { "src/parser.c" }, + } +} + +list.c_sharp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c-sharp", + files = { "src/parser.c", "src/scanner.c" }, + }, + filetype = 'cs' +} + +list.typescript = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-typescript", + files = { "src/parser.c", "src/scanner.c" }, + location = "tree-sitter-typescript/typescript" + } +} + +list.tsx = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-typescript", + files = { "src/parser.c", "src/scanner.c" }, + location = "tree-sitter-tsx/tsx" + }, + filetype = 'typescriptreact' +} + +list.scala = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-scala", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.haskell = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-haskell", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.markdown = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-markdown", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.toml = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-toml", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.vue = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.elm = { + install_info = { + url = "https://github.com//razzeee/tree-sitter-elm", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.yaml = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-yaml", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.nix = { + install_info = { + url = "https://github.com/cstrahan/tree-sitter-nix", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.regex = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-regex", + files = { "src/parser.c" } + } +} + +local M = { + list = list +} + +local ft_to_parsername = {} +for name, obj in pairs(M.list) do + if obj.filetype then + ft_to_parsername[obj.filetype] = name + else + ft_to_parsername[name] = name + end +end + +function M.ft_to_lang(ft) + return ft_to_parsername[ft] +end + +function M.lang_to_ft(lang) + return M.list[lang].filetype or lang +end + +function M.available_parsers() + return vim.tbl_keys(M.list) +end + +function M.get_parser_configs() + return M.list +end function M.has_parser(lang) - local lang = lang or api.nvim_buf_get_option(0, 'filetype') + local buf = api.nvim_get_current_buf() + local lang = lang or M.ft_to_lang(api.nvim_buf_get_option(buf, 'ft')) if not lang or #lang == 0 then return false end return #api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) > 0 end function M.get_parser(bufnr, lang) local buf = bufnr or api.nvim_get_current_buf() - local lang = lang or api.nvim_buf_get_option(buf, 'ft') + local lang = lang or M.ft_to_lang(api.nvim_buf_get_option(buf, 'ft')) if M.has_parser(lang) then if not M[buf] then |
