diff options
| author | Santos Gallegos <stsewd@protonmail.com> | 2021-07-04 16:12:17 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-04 21:12:17 +0000 |
| commit | be8f65608796e50aa2e2da5452849c263558f0ed (patch) | |
| tree | 39f6057de9026ab312c3bb838e773910129b5575 /lua/nvim-treesitter/utils.lua | |
| parent | 90f15d9bf750e35666e029174481dafbe5fde817 (diff) | |
Use stylua for autoformat code (#1480)
Diffstat (limited to 'lua/nvim-treesitter/utils.lua')
| -rw-r--r-- | lua/nvim-treesitter/utils.lua | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index 947bd56f..dcd1e135 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -6,20 +6,23 @@ local M = {} function M.setup_commands(mod, commands) for command_name, def in pairs(commands) do - local call_fn = string.format("lua require'nvim-treesitter.%s'.commands.%s['run<bang>'](<f-args>)", - mod, command_name) - local parts = vim.tbl_flatten({ + local call_fn = string.format( + "lua require'nvim-treesitter.%s'.commands.%s['run<bang>'](<f-args>)", + mod, + command_name + ) + local parts = vim.tbl_flatten { "command!", def.args, command_name, call_fn, - }) + } api.nvim_command(table.concat(parts, " ")) end end function M.get_path_sep() - return fn.has('win32') == 1 and '\\' or '/' + return fn.has "win32" == 1 and "\\" or "/" end -- Returns a function that joins the given arguments with separator. Arguments @@ -29,40 +32,40 @@ print(M.generate_join(" ")("foo", "bar")) --]] -- prints "foo bar" function M.generate_join(separator) - return function (...) - return table.concat({...}, separator) + return function(...) + return table.concat({ ... }, separator) end end M.join_path = M.generate_join(M.get_path_sep()) -local join_space = M.generate_join(" ") +local join_space = M.generate_join " " function M.get_package_path() -- Path to this source file, removing the leading '@' - local source = string.sub(debug.getinfo(1, 'S').source, 2) + local source = string.sub(debug.getinfo(1, "S").source, 2) -- Path to the package root return fn.fnamemodify(source, ":p:h:h:h") end function M.get_cache_dir() - local cache_dir = fn.stdpath('data') + local cache_dir = fn.stdpath "data" - if luv.fs_access(cache_dir, 'RW') then + if luv.fs_access(cache_dir, "RW") then return cache_dir - elseif luv.fs_access('/tmp', 'RW') then - return '/tmp' + elseif luv.fs_access("/tmp", "RW") then + return "/tmp" end - return nil, join_space('Invalid cache rights,', fn.stdpath('data'), 'or /tmp should be read/write') + return nil, join_space("Invalid cache rights,", fn.stdpath "data", "or /tmp should be read/write") end -- Returns $XDG_DATA_HOME/nvim/site, but could use any directory that is in -- runtimepath function M.get_site_dir() local path_sep = M.get_path_sep() - return M.join_path(fn.stdpath('data'), path_sep, 'site') + return M.join_path(fn.stdpath "data", path_sep, "site") end -- Try the package dir of the nvim-treesitter plugin first, followed by the @@ -75,7 +78,7 @@ function M.get_parser_install_dir(folder_name) local package_path_parser_dir = M.join_path(package_path, folder_name) -- If package_path is read/write, use that - if luv.fs_access(package_path_parser_dir, 'RW') then + if luv.fs_access(package_path_parser_dir, "RW") then return package_path_parser_dir end @@ -87,24 +90,24 @@ function M.get_parser_install_dir(folder_name) if not luv.fs_stat(parser_dir) then local ok, error = pcall(vim.fn.mkdir, parser_dir, "p", "0755") if not ok then - return nil, join_space('Couldn\'t create parser dir', parser_dir, ':', error) + return nil, join_space("Couldn't create parser dir", parser_dir, ":", error) end return parser_dir end -- parser_dir exists, use it if it's read/write - if luv.fs_access(parser_dir, 'RW') then + if luv.fs_access(parser_dir, "RW") then return parser_dir end -- package_path isn't read/write, parser_dir exists but isn't read/write -- either, give up - return nil, join_space('Invalid cache rights,', package_path, 'or', parser_dir, 'should be read/write') + return nil, join_space("Invalid cache rights,", package_path, "or", parser_dir, "should be read/write") end function M.get_parser_info_dir() - return M.get_parser_install_dir('parser-info') + return M.get_parser_install_dir "parser-info" end -- Gets a property at path @@ -112,12 +115,14 @@ end -- @param path the '.' separated path -- @returns the value at path or nil function M.get_at_path(tbl, path) - if path == '' then return tbl end - local segments = vim.split(path, '.', true) + if path == "" then + return tbl + end + local segments = vim.split(path, ".", true) local result = tbl for _, segment in ipairs(segments) do - if type(result) == 'table' then + if type(result) == "table" then result = result[segment] end end @@ -173,11 +178,13 @@ function M.identity(a) end function M.constant(a) - return function() return a end + return function() + return a + end end function M.to_func(a) - return type(a) == 'function' and a or M.constant(a) + return type(a) == "function" and a or M.constant(a) end return M |
