diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-07-23 17:42:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-23 11:42:37 -0400 |
| commit | 79644ab67731c7ba956c354bf0545282f34e10cc (patch) | |
| tree | e65dbf73b3442ab1aa9fc59fc56a35b4c9edf1e0 /lua/telescope/previewers/utils.lua | |
| parent | 664690029fdb302bee8d3f27a458383e8477add7 (diff) | |
chore: use stylua for formatting (#1040)
* chore: stylua job and config
* reformat with stylua
Diffstat (limited to 'lua/telescope/previewers/utils.lua')
| -rw-r--r-- | lua/telescope/previewers/utils.lua | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/lua/telescope/previewers/utils.lua b/lua/telescope/previewers/utils.lua index 5ede0e0..54435fd 100644 --- a/lua/telescope/previewers/utils.lua +++ b/lua/telescope/previewers/utils.lua @@ -1,10 +1,10 @@ -local context_manager = require('plenary.context_manager') +local context_manager = require "plenary.context_manager" -local has_ts, _ = pcall(require, 'nvim-treesitter') -local _, ts_configs = pcall(require, 'nvim-treesitter.configs') -local _, ts_parsers = pcall(require, 'nvim-treesitter.parsers') +local has_ts, _ = pcall(require, "nvim-treesitter") +local _, ts_configs = pcall(require, "nvim-treesitter.configs") +local _, ts_parsers = pcall(require, "nvim-treesitter.parsers") -local Job = require('plenary.job') +local Job = require "plenary.job" local utils = {} @@ -30,33 +30,41 @@ utils.job_maker = function(cmd, bufnr, opts) -- if any of them are missing, cache will be skipped if opts.bufname ~= opts.value or not opts.bufname or not opts.value then local command = table.remove(cmd, 1) - Job:new({ - command = command, - args = cmd, - env = opts.env, - cwd = opts.cwd, - on_exit = vim.schedule_wrap(function(j) - if not vim.api.nvim_buf_is_valid(bufnr) then return end - if opts.mode == "append" then - vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, j:result()) - elseif opts.mode == "insert" then - vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result()) - end - if opts.callback then opts.callback(bufnr, j:result()) end - end) - }):start() + Job + :new({ + command = command, + args = cmd, + env = opts.env, + cwd = opts.cwd, + on_exit = vim.schedule_wrap(function(j) + if not vim.api.nvim_buf_is_valid(bufnr) then + return + end + if opts.mode == "append" then + vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, j:result()) + elseif opts.mode == "insert" then + vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result()) + end + if opts.callback then + opts.callback(bufnr, j:result()) + end + end), + }) + :start() else - if opts.callback then opts.callback(bufnr) end + if opts.callback then + opts.callback(bufnr) + end end end local function has_filetype(ft) - return ft and ft ~= '' + return ft and ft ~= "" end --- Attach default highlighter which will choose between regex and ts utils.highlighter = function(bufnr, ft) - if not(utils.ts_highlighter(bufnr, ft)) then + if not (utils.ts_highlighter(bufnr, ft)) then utils.regex_highlighter(bufnr, ft) end end @@ -82,8 +90,10 @@ local treesitter_attach = function(bufnr, ft) end vim.treesitter.highlighter.new(ts_parsers.get_parser(bufnr, lang)) local is_table = type(config.additional_vim_regex_highlighting) == "table" - if config.additional_vim_regex_highlighting and - (not is_table or vim.tbl_contains(config.additional_vim_regex_highlighting, lang)) then + if + config.additional_vim_regex_highlighting + and (not is_table or vim.tbl_contains(config.additional_vim_regex_highlighting, lang)) + then vim.api.nvim_buf_set_option(bufnr, "syntax", ft) end return true @@ -94,10 +104,10 @@ end -- Attach ts highlighter utils.ts_highlighter = function(bufnr, ft) if not has_ts then - has_ts, _ = pcall(require, 'nvim-treesitter') + has_ts, _ = pcall(require, "nvim-treesitter") if has_ts then - _, ts_configs = pcall(require, 'nvim-treesitter.configs') - _, ts_parsers = pcall(require, 'nvim-treesitter.parsers') + _, ts_configs = pcall(require, "nvim-treesitter.configs") + _, ts_parsers = pcall(require, "nvim-treesitter.parsers") end end |
