rename and finish ft->lang migration

This commit is contained in:
kiyan42 2020-06-22 11:56:55 +02:00 committed by Thomas Vigouroux
parent 30dbf73113
commit def8c20dd7
4 changed files with 36 additions and 36 deletions

View file

@ -95,7 +95,7 @@ local function disable_module(mod, bufnr, lang)
end end
local loaded_mod = require(string.format("nvim-treesitter.%s", mod)) local loaded_mod = require(string.format("nvim-treesitter.%s", mod))
loaded_mod.detach(bufnr, ft) loaded_mod.detach(bufnr)
end end
local function disable_mod_conf_autocmd(mod, lang) local function disable_mod_conf_autocmd(mod, lang)
@ -173,7 +173,7 @@ function M.is_enabled(mod, lang)
end end
for _, parser in pairs(module_config.disable) do for _, parser in pairs(module_config.disable) do
if ft == parser then return false end if lang == parser then return false end
end end
return true return true

View file

@ -21,14 +21,14 @@ local function install_info()
end end
end end
local function print_info_module(sorted_filetypes, mod) local function print_info_module(sorted_languages, mod)
local max_str_len = #sorted_filetypes[1] local max_str_len = #sorted_languages[1]
local header = string.format('%s%s', string.rep(' ', max_str_len + 2), mod) local header = string.format('%s%s', string.rep(' ', max_str_len + 2), mod)
api.nvim_out_write(header..'\n') api.nvim_out_write(header..'\n')
for _, ft in pairs(sorted_filetypes) do for _, lang in pairs(sorted_languages) do
local padding = string.rep(' ', max_str_len - #ft + #mod / 2 + 1) local padding = string.rep(' ', max_str_len - #lang + #mod / 2 + 1)
api.nvim_out_write(ft..":"..padding) api.nvim_out_write(lang..":"..padding)
if configs.is_enabled(mod, ft) then if configs.is_enabled(mod, lang) then
api.nvim_out_write('') api.nvim_out_write('')
else else
api.nvim_out_write('') api.nvim_out_write('')
@ -37,23 +37,23 @@ local function print_info_module(sorted_filetypes, mod)
end end
end end
local function print_info_modules(sorted_filetypes) local function print_info_modules(sorted_languages)
local max_str_len = #sorted_filetypes[1] local max_str_len = #sorted_languages[1]
local header = string.rep(' ', max_str_len + 2) local header = string.rep(' ', max_str_len + 2)
for _, mod in pairs(configs.available_modules()) do for _, mod in pairs(configs.available_modules()) do
header = string.format('%s%s ', header, mod) header = string.format('%s%s ', header, mod)
end end
api.nvim_out_write(header..'\n') api.nvim_out_write(header..'\n')
for _, ft in pairs(sorted_filetypes) do for _, lang in pairs(sorted_languages) do
local padding = string.rep(' ', max_str_len - #ft) local padding = string.rep(' ', max_str_len - #lang)
api.nvim_out_write(ft..":"..padding) api.nvim_out_write(lang..":"..padding)
for _, mod in pairs(configs.available_modules()) do for _, mod in pairs(configs.available_modules()) do
local pad_len = #mod / 2 + 1 local pad_len = #mod / 2 + 1
api.nvim_out_write(string.rep(' ', pad_len)) api.nvim_out_write(string.rep(' ', pad_len))
if configs.is_enabled(mod, ft) then if configs.is_enabled(mod, lang) then
api.nvim_out_write('') api.nvim_out_write('')
else else
api.nvim_out_write('') api.nvim_out_write('')
@ -67,12 +67,12 @@ end
local function module_info(mod) local function module_info(mod)
if mod and not configs.get_config()[mod] then return end if mod and not configs.get_config()[mod] then return end
local ft_by_len = parsers.available_parsers() local parserlist = parsers.available_parsers()
table.sort(ft_by_len, function(a, b) return #a > #b end) table.sort(parserlist, function(a, b) return #a > #b end)
if mod then if mod then
print_info_module(ft_by_len, mod) print_info_module(parserlist, mod)
else else
print_info_modules(ft_by_len) print_info_modules(parserlist)
end end
end end

View file

@ -7,8 +7,8 @@ local parsers = require'nvim-treesitter.parsers'
local M = {} local M = {}
local function iter_cmd(cmd_list, i, ft) local function iter_cmd(cmd_list, i, lang)
if i == #cmd_list + 1 then return print('Treesitter parser for '..ft..' has been installed') end if i == #cmd_list + 1 then return print('Treesitter parser for '..lang..' has been installed') end
local attr = cmd_list[i] local attr = cmd_list[i]
if attr.info then print(attr.info) end if attr.info then print(attr.info) end
@ -18,16 +18,16 @@ local function iter_cmd(cmd_list, i, ft)
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
iter_cmd(cmd_list, i + 1, ft) iter_cmd(cmd_list, i + 1, lang)
end)) end))
end end
local function run_install(cache_folder, package_path, ft, repo) local function run_install(cache_folder, package_path, lang, repo)
local project_name = 'tree-sitter-'..ft local project_name = 'tree-sitter-'..lang
local project_repo = cache_folder..'/'..project_name local project_repo = cache_folder..'/'..project_name
-- compile_location only needed for typescript installs. -- compile_location only needed for typescript installs.
local compile_location = cache_folder..'/'..(repo.location or project_name) local compile_location = cache_folder..'/'..(repo.location or project_name)
local parser_lib_name = package_path.."/parser/"..ft..".so" local parser_lib_name = package_path.."/parser/"..lang..".so"
local command_list = { local command_list = {
{ {
cmd = 'rm', cmd = 'rm',
@ -76,7 +76,7 @@ local function run_install(cache_folder, package_path, ft, repo)
} }
} }
iter_cmd(command_list, 1, ft) iter_cmd(command_list, 1, lang)
end end
-- TODO(kyazdani): this should work on windows too -- TODO(kyazdani): this should work on windows too
@ -95,16 +95,16 @@ local function install(...)
local cache_folder, err = utils.get_cache_dir() local cache_folder, err = utils.get_cache_dir()
if err then return api.nvim_err_writeln(err) end if err then return api.nvim_err_writeln(err) end
for _, ft in ipairs({ ... }) do for _, lang in ipairs({ ... }) do
if #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 then if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then
local yesno = fn.input(ft .. ' parser already available: would you like to reinstall ? y/n: ') local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ')
print('\n ') -- mandatory to avoid messing up command line print('\n ') -- mandatory to avoid messing up command line
if not string.match(yesno, '^y.*') then return end if not string.match(yesno, '^y.*') then return end
end end
local parser_config = parsers.get_parser_configs()[ft] local parser_config = parsers.get_parser_configs()[lang]
if not parser_config then if not parser_config then
return api.nvim_err_writeln('Parser not available for language '..ft) return api.nvim_err_writeln('Parser not available for language '..lang)
end end
local install_info = parser_config.install_info local install_info = parser_config.install_info
@ -113,7 +113,7 @@ local function install(...)
files={ install_info.files, 'table' } files={ install_info.files, 'table' }
} }
run_install(cache_folder, package_path, ft, install_info) run_install(cache_folder, package_path, lang, install_info)
end end
end end
@ -142,7 +142,7 @@ M.commands = {
"-nargs=+", "-nargs=+",
"-complete=custom,v:lua.ts_installable_parsers" "-complete=custom,v:lua.ts_installable_parsers"
}, },
description = '`:TSInstall {ft}` installs a parser under nvim-treesitter/parser/{name}.so' description = '`:TSInstall {lang}` installs a parser under nvim-treesitter/parser/{lang}.so'
} }
} }

View file

@ -12,13 +12,13 @@ local M = {
} }
function M.collect_locals(bufnr) function M.collect_locals(bufnr)
local ft = api.nvim_buf_get_option(bufnr, "ft") local lang = parsers.ft_to_lang(api.nvim_buf_get_option(bufnr, "ft"))
if not ft then return end if not lang then return end
local query = queries.get_query(ft, 'locals') local query = queries.get_query(lang, 'locals')
if not query then return end if not query then return end
local parser = parsers.get_parser(bufnr, ft) local parser = parsers.get_parser(bufnr, lang)
if not parser then return end if not parser then return end
local root = parser:parse():root() local root = parser:parse():root()