Merge pull request #8 from kyazdani42/add-parsers

feat: add most parsers
This commit is contained in:
Thomas Vigouroux 2020-04-20 22:26:12 +02:00 committed by GitHub
commit 669b6ab8c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,10 +12,71 @@ local repositories = {
url = "https://github.com/tree-sitter/tree-sitter-c", url = "https://github.com/tree-sitter/tree-sitter-c",
files = { "src/parser.c" } files = { "src/parser.c" }
}, },
cpp = {
url = "https://github.com/tree-sitter/tree-sitter-cpp",
files = { "src/parser.c", "src/scanner.cc" }
},
rust = { rust = {
url = "https://github.com/tree-sitter/tree-sitter-rust", url = "https://github.com/tree-sitter/tree-sitter-rust",
files = { "src/parser.c", "src/scanner.c" }, files = { "src/parser.c", "src/scanner.c" },
} },
lua = {
url = "https://github.com/nvim-treesitter/tree-sitter-lua",
files = { "src/parser.c", "src/scanner.cc" }
},
python = {
url = "https://github.com/tree-sitter/tree-sitter-python",
files = { "src/parser.c", "src/scanner.cc" },
},
go = {
url = "https://github.com/tree-sitter/tree-sitter-go",
files = { "src/parser.c" },
},
ruby = {
url = "https://github.com/tree-sitter/tree-sitter-ruby",
files = { "src/parser.c", "src/scanner.cc" },
},
bash = {
url = "https://github.com/tree-sitter/tree-sitter-bash",
files = { "src/parser.c", "src/scanner.cc" },
},
php = {
url = "https://github.com/tree-sitter/tree-sitter-php",
files = { "src/parser.c", "src/scanner.cc" },
},
java = {
url = "https://github.com/tree-sitter/tree-sitter-java",
files = { "src/parser.c" },
},
html = {
url = "https://github.com/tree-sitter/tree-sitter-html",
files = { "src/parser.c", "src/scanner.cc" },
},
julia = {
url = "https://github.com/tree-sitter/tree-sitter-julia",
files = { "src/parser.c", "src/scanner.c" },
},
json = {
url = "https://github.com/tree-sitter/tree-sitter-json",
files = { "src/parser.c" },
},
css = {
url = "https://github.com/tree-sitter/tree-sitter-css",
files = { "src/parser.c", "src/scanner.c" },
},
ocaml = {
url = "https://github.com/tree-sitter/tree-sitter-ocaml",
files = { "src/parser.c", "src/scanner.cc" },
},
swift = {
url = "https://github.com/tree-sitter/tree-sitter-swift",
files = { "src/parser.c" },
},
-- TODO: find a way to install c-sharp and typescript properly
-- csharp = {
-- url = "https://github.com/tree-sitter/tree-sitter-c-sharp",
-- files = { "src/parser.c", "src/scanner.c" },
-- },
} }
local function get_package_path() local function get_package_path()
@ -47,8 +108,10 @@ end
local function iter_cmd(cmd_list, i, ft) local function iter_cmd(cmd_list, i, ft)
if i == #cmd_list then return print('Treesitter parser for '..ft..' has been installed') end if i == #cmd_list then return print('Treesitter parser for '..ft..' has been installed') end
local attr = cmd_list[i + 1] local attr = cmd_list[i + 1]
print(attr.info) if attr.info then print(attr.info) end
handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code) handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code)
handle:close() handle:close()
if code ~= 0 then return api.nvim_err_writeln(attr.err) end if code ~= 0 then return api.nvim_err_writeln(attr.err) end
@ -56,7 +119,7 @@ local function iter_cmd(cmd_list, i, ft)
end)) end))
end end
local function run_install(cache_folder, package_path, ft, files, url) local function run_install(cache_folder, package_path, ft, repo)
local project_repo = cache_folder..'/tree-sitter-'..ft local project_repo = cache_folder..'/tree-sitter-'..ft
local parser_lib_name = package_path.."/parser/"..ft..".so" local parser_lib_name = package_path.."/parser/"..ft..".so"
local command_list = { local command_list = {
@ -71,7 +134,7 @@ local function run_install(cache_folder, package_path, ft, files, url)
info = 'Downloading...', info = 'Downloading...',
err = 'Error during download, please verify your internet connection', err = 'Error during download, please verify your internet connection',
opts = { opts = {
args = { 'clone', url }, args = { 'clone', repo.url },
cwd = cache_folder, cwd = cache_folder,
}, },
}, },
@ -80,7 +143,7 @@ local function run_install(cache_folder, package_path, ft, files, url)
info = 'Compiling...', info = 'Compiling...',
err = 'Error during compilation', err = 'Error during compilation',
opts = { opts = {
args = { '-o', 'parser.so', '-shared', '-lstdc++', unpack(files), '-Os', '-I./src' }, args = { '-o', 'parser.so', '-shared', '-lstdc++', unpack(repo.files), '-Os', '-I./src' },
cwd = project_repo cwd = project_repo
} }
}, },
@ -132,7 +195,7 @@ function M.install_parser(ft)
local cache_folder, err = get_cache_dir() local cache_folder, err = get_cache_dir()
if err then return api.nvim_err_writeln(err) end if err then return api.nvim_err_writeln(err) end
run_install(cache_folder, package_path, ft, repository.files, repository.url) run_install(cache_folder, package_path, ft, repository)
end end
return M return M