diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2023-06-06 09:50:40 +0200 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2023-06-06 09:51:15 +0200 |
| commit | ffc791e58370bc2119f6608ad00910ae203a758d (patch) | |
| tree | 5c4b266753cb3f4533e6f95c8b49a9798577bc70 /lua | |
| parent | 992ab25765c3a53044e65774ae4329492fa241f7 (diff) | |
| download | nvim-conf-ffc791e58370bc2119f6608ad00910ae203a758d.tar.gz nvim-conf-ffc791e58370bc2119f6608ad00910ae203a758d.zip | |
add linter, add select to quickfix
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/alpha/lsp/null-ls.lua | 2 | ||||
| -rw-r--r-- | lua/alpha/select_to_quickfix.lua | 53 | ||||
| -rw-r--r-- | lua/config/keymaps.lua | 2 |
3 files changed, 57 insertions, 0 deletions
diff --git a/lua/alpha/lsp/null-ls.lua b/lua/alpha/lsp/null-ls.lua index be3d4e9..931d55a 100644 --- a/lua/alpha/lsp/null-ls.lua +++ b/lua/alpha/lsp/null-ls.lua @@ -11,6 +11,8 @@ null_ls.setup { null_ls.builtins.diagnostics.luacheck, null_ls.builtins.formatting.stylua, + null_ls.builtins.diagnostics.yamllint, + -- php_actions.getter_setter, -- php_actions.file_creator, diff --git a/lua/alpha/select_to_quickfix.lua b/lua/alpha/select_to_quickfix.lua new file mode 100644 index 0000000..ebd1561 --- /dev/null +++ b/lua/alpha/select_to_quickfix.lua @@ -0,0 +1,53 @@ +local api = vim.api + +local function create_quickfix_entry(selection) + local filename, linenumber = selection:match "([^:]+):(%d+)" + + return { + filename = vim.fn.getcwd() .. "/" .. filename, + lnum = tonumber(linenumber), + col = 1, + text = filename, + } +end + +local function add_selections_to_quickfix(selections) + local quickfix_list = {} + + for _, selection in ipairs(selections) do + local entry = create_quickfix_entry(selection) + table.insert(quickfix_list, entry) + end + + vim.fn.setqflist(quickfix_list, "r") +end + +local function get_selections() + local _, end_line, _, _ = unpack(vim.fn.getpos "'>") + local _, start_line, _, _ = unpack(vim.fn.getpos "'<") + local lines = api.nvim_buf_get_lines(0, start_line - 1, end_line, false) + + local selections = {} + for _, line in ipairs(lines) do + for selection in line:gmatch "%S+" do + table.insert(selections, selection) + end + end + + return selections +end + +local function select_to_quickfix() + local selections = get_selections() + + if #selections > 0 then + add_selections_to_quickfix(selections) + print "Selections added to quickfix list" + else + print "No selections found" + end +end + +return { + handle = select_to_quickfix, +} diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index a8bcda0..22b786d 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -69,3 +69,5 @@ map( map("n", "<leader>vn", vim.diagnostic.goto_next, { desc = "Goes to next diagnostic error" }) map("n", "<leader>vp", vim.diagnostic.goto_prev, { desc = "Goes to prev diagnostic error" }) + +map("v", "<leader>q", require('alpha.select_to_quickfix').handle) |