mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
rename and finish ft->lang migration
This commit is contained in:
parent
30dbf73113
commit
def8c20dd7
4 changed files with 36 additions and 36 deletions
|
|
@ -95,7 +95,7 @@ local function disable_module(mod, bufnr, lang)
|
|||
end
|
||||
|
||||
local loaded_mod = require(string.format("nvim-treesitter.%s", mod))
|
||||
loaded_mod.detach(bufnr, ft)
|
||||
loaded_mod.detach(bufnr)
|
||||
end
|
||||
|
||||
local function disable_mod_conf_autocmd(mod, lang)
|
||||
|
|
@ -173,7 +173,7 @@ function M.is_enabled(mod, lang)
|
|||
end
|
||||
|
||||
for _, parser in pairs(module_config.disable) do
|
||||
if ft == parser then return false end
|
||||
if lang == parser then return false end
|
||||
end
|
||||
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ local function install_info()
|
|||
end
|
||||
end
|
||||
|
||||
local function print_info_module(sorted_filetypes, mod)
|
||||
local max_str_len = #sorted_filetypes[1]
|
||||
local function print_info_module(sorted_languages, mod)
|
||||
local max_str_len = #sorted_languages[1]
|
||||
local header = string.format('%s%s', string.rep(' ', max_str_len + 2), mod)
|
||||
api.nvim_out_write(header..'\n')
|
||||
for _, ft in pairs(sorted_filetypes) do
|
||||
local padding = string.rep(' ', max_str_len - #ft + #mod / 2 + 1)
|
||||
api.nvim_out_write(ft..":"..padding)
|
||||
if configs.is_enabled(mod, ft) then
|
||||
for _, lang in pairs(sorted_languages) do
|
||||
local padding = string.rep(' ', max_str_len - #lang + #mod / 2 + 1)
|
||||
api.nvim_out_write(lang..":"..padding)
|
||||
if configs.is_enabled(mod, lang) then
|
||||
api.nvim_out_write('✓')
|
||||
else
|
||||
api.nvim_out_write('✗')
|
||||
|
|
@ -37,23 +37,23 @@ local function print_info_module(sorted_filetypes, mod)
|
|||
end
|
||||
end
|
||||
|
||||
local function print_info_modules(sorted_filetypes)
|
||||
local max_str_len = #sorted_filetypes[1]
|
||||
local function print_info_modules(sorted_languages)
|
||||
local max_str_len = #sorted_languages[1]
|
||||
local header = string.rep(' ', max_str_len + 2)
|
||||
for _, mod in pairs(configs.available_modules()) do
|
||||
header = string.format('%s%s ', header, mod)
|
||||
end
|
||||
api.nvim_out_write(header..'\n')
|
||||
|
||||
for _, ft in pairs(sorted_filetypes) do
|
||||
local padding = string.rep(' ', max_str_len - #ft)
|
||||
api.nvim_out_write(ft..":"..padding)
|
||||
for _, lang in pairs(sorted_languages) do
|
||||
local padding = string.rep(' ', max_str_len - #lang)
|
||||
api.nvim_out_write(lang..":"..padding)
|
||||
|
||||
for _, mod in pairs(configs.available_modules()) do
|
||||
local pad_len = #mod / 2 + 1
|
||||
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('✓')
|
||||
else
|
||||
api.nvim_out_write('✗')
|
||||
|
|
@ -67,12 +67,12 @@ end
|
|||
local function module_info(mod)
|
||||
if mod and not configs.get_config()[mod] then return end
|
||||
|
||||
local ft_by_len = parsers.available_parsers()
|
||||
table.sort(ft_by_len, function(a, b) return #a > #b end)
|
||||
local parserlist = parsers.available_parsers()
|
||||
table.sort(parserlist, function(a, b) return #a > #b end)
|
||||
if mod then
|
||||
print_info_module(ft_by_len, mod)
|
||||
print_info_module(parserlist, mod)
|
||||
else
|
||||
print_info_modules(ft_by_len)
|
||||
print_info_modules(parserlist)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ local parsers = require'nvim-treesitter.parsers'
|
|||
|
||||
local M = {}
|
||||
|
||||
local function iter_cmd(cmd_list, i, ft)
|
||||
if i == #cmd_list + 1 then return print('Treesitter parser for '..ft..' has been installed') end
|
||||
local function iter_cmd(cmd_list, i, lang)
|
||||
if i == #cmd_list + 1 then return print('Treesitter parser for '..lang..' has been installed') end
|
||||
|
||||
local attr = cmd_list[i]
|
||||
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:close()
|
||||
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
|
||||
|
||||
local function run_install(cache_folder, package_path, ft, repo)
|
||||
local project_name = 'tree-sitter-'..ft
|
||||
local function run_install(cache_folder, package_path, lang, repo)
|
||||
local project_name = 'tree-sitter-'..lang
|
||||
local project_repo = cache_folder..'/'..project_name
|
||||
-- compile_location only needed for typescript installs.
|
||||
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 = {
|
||||
{
|
||||
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
|
||||
|
||||
-- TODO(kyazdani): this should work on windows too
|
||||
|
|
@ -95,16 +95,16 @@ local function install(...)
|
|||
local cache_folder, err = utils.get_cache_dir()
|
||||
if err then return api.nvim_err_writeln(err) end
|
||||
|
||||
for _, ft in ipairs({ ... }) do
|
||||
if #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 then
|
||||
local yesno = fn.input(ft .. ' parser already available: would you like to reinstall ? y/n: ')
|
||||
for _, lang in ipairs({ ... }) do
|
||||
if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then
|
||||
local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ')
|
||||
print('\n ') -- mandatory to avoid messing up command line
|
||||
if not string.match(yesno, '^y.*') then return end
|
||||
end
|
||||
|
||||
local parser_config = parsers.get_parser_configs()[ft]
|
||||
local parser_config = parsers.get_parser_configs()[lang]
|
||||
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
|
||||
|
||||
local install_info = parser_config.install_info
|
||||
|
|
@ -113,7 +113,7 @@ local function install(...)
|
|||
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
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ M.commands = {
|
|||
"-nargs=+",
|
||||
"-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'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ local M = {
|
|||
}
|
||||
|
||||
function M.collect_locals(bufnr)
|
||||
local ft = api.nvim_buf_get_option(bufnr, "ft")
|
||||
if not ft then return end
|
||||
local lang = parsers.ft_to_lang(api.nvim_buf_get_option(bufnr, "ft"))
|
||||
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
|
||||
|
||||
local parser = parsers.get_parser(bufnr, ft)
|
||||
local parser = parsers.get_parser(bufnr, lang)
|
||||
if not parser then return end
|
||||
|
||||
local root = parser:parse():root()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue