diff options
Diffstat (limited to 'lua/alpha')
| -rw-r--r-- | lua/alpha/animations.lua | 50 | ||||
| -rw-r--r-- | lua/alpha/completition/init.lua | 9 | ||||
| -rw-r--r-- | lua/alpha/globals.lua | 4 | ||||
| -rw-r--r-- | lua/alpha/lsp/attach.lua | 4 | ||||
| -rw-r--r-- | lua/alpha/lsp/init.lua | 6 | ||||
| -rw-r--r-- | lua/alpha/lsp/mason.lua | 7 | ||||
| -rw-r--r-- | lua/alpha/lsp/null-ls.lua | 23 | ||||
| -rw-r--r-- | lua/alpha/lsp/servers.lua | 32 | ||||
| -rw-r--r-- | lua/alpha/lsp/tools.lua | 6 | ||||
| -rw-r--r-- | lua/alpha/php/servers.lua | 3 | ||||
| -rw-r--r-- | lua/alpha/select_to_quickfix.lua | 53 | ||||
| -rw-r--r-- | lua/alpha/snips/ft/cucumber.lua | 7 | ||||
| -rw-r--r-- | lua/alpha/telescope/init.lua | 14 | ||||
| -rw-r--r-- | lua/alpha/telescope/my_actions.lua (renamed from lua/alpha/telescope/actions.lua) | 0 | ||||
| -rw-r--r-- | lua/alpha/telescope/setup.lua | 52 |
15 files changed, 239 insertions, 31 deletions
diff --git a/lua/alpha/animations.lua b/lua/alpha/animations.lua new file mode 100644 index 0000000..c0b7a6c --- /dev/null +++ b/lua/alpha/animations.lua @@ -0,0 +1,50 @@ +local redraw_buffer = function() + local Animation = require "animation" + local fps = 45 -- frames per second + local easing = require "animation.easing" + + local buffer = 0 + local len = 0 + local place_holder = {} + + local lines = vim.api.nvim_buf_get_lines(buffer, 0, -1, true) + + for _, line in ipairs(lines) do + len = len + string.len(line) + table.insert(place_holder, "") + end + + vim.api.nvim_buf_set_lines(buffer, 0, #lines, true, place_holder) + + local duration = math.ceil(len / fps * 1000) + + local i = 1 + local line_nr = 1 + local insertLine = "" + + local function callback() + if lines[line_nr] == nil then + return true + end + local char = string.sub(lines[line_nr], i, i) + if char == nil then + return true + end + insertLine = insertLine .. char + i = i + 1 + vim.api.nvim_buf_set_lines(buffer, line_nr - 1, line_nr, true, { insertLine }) + + if insertLine == lines[line_nr] then + i = 1 + line_nr = line_nr + 1 + insertLine = "" + end + end + + local animation = Animation(duration, fps, easing.line, callback) + animation:run() +end + +return { + redraw_buffer = redraw_buffer, +} diff --git a/lua/alpha/completition/init.lua b/lua/alpha/completition/init.lua index 02c9978..35ba27e 100644 --- a/lua/alpha/completition/init.lua +++ b/lua/alpha/completition/init.lua @@ -40,7 +40,7 @@ cmp.setup { { name = "nvim_lsp" }, { name = "path" }, { name = "luasnip" }, - { name = "nvim_lsp_signature_help" }, + { name = "copilot", group_index = 2 }, { name = "buffer", keyword_length = 4, @@ -49,7 +49,7 @@ cmp.setup { local bufs = {} for _, win in ipairs(vim.api.nvim_list_wins()) do local bufnr = vim.api.nvim_win_get_buf(win) - if vim.api.nvim_buf_get_option(bufnr, 'buftype') ~= 'terminal' then + if vim.api.nvim_buf_get_option(bufnr, "buftype") ~= "terminal" then bufs[bufnr] = true end end @@ -70,10 +70,11 @@ cmp.setup { with_text = true, menu = { buffer = "[buf]", - nvim_lsp = "[LSP]", + nvim_lsp = "[ ]", nvim_lua = "[api]", path = "[path]", luasnip = "[snip]", + copilot = "[ﮧ ]", ["vim-dadbod-completion"] = "[DB]", }, }, @@ -94,6 +95,8 @@ cmp.setup { }, } +vim.api.nvim_set_hl(0, "CmpItemKindCopilot", {fg ="#6CC644"}) + -- Set configuration for specific filetype. cmp.setup.filetype("gitcommit", { sources = cmp.config.sources({ diff --git a/lua/alpha/globals.lua b/lua/alpha/globals.lua index b575c0c..e445e72 100644 --- a/lua/alpha/globals.lua +++ b/lua/alpha/globals.lua @@ -13,11 +13,11 @@ dump = function(...) return unpack(args) end -RELOAD = function(...) +Reload = function(...) return require("plenary.reload").reload_module(...) end R = function(name) - RELOAD(name) + Reload(name) return require(name) end diff --git a/lua/alpha/lsp/attach.lua b/lua/alpha/lsp/attach.lua index 45ce904..bf5b645 100644 --- a/lua/alpha/lsp/attach.lua +++ b/lua/alpha/lsp/attach.lua @@ -29,6 +29,10 @@ return function(client, bufnr) vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint(bufnr, true) + end + -- Attach any filetype specific options to the client filetype_attach[filetype](client, bufnr) end diff --git a/lua/alpha/lsp/init.lua b/lua/alpha/lsp/init.lua index d280e53..03bd61d 100644 --- a/lua/alpha/lsp/init.lua +++ b/lua/alpha/lsp/init.lua @@ -1,14 +1,12 @@ -- LSP configuration --- install servers and tools -require "alpha.lsp.mason" - local lspconfig = require "lspconfig" local servers = require "alpha.lsp.servers" - for server, setup in pairs(servers) do lspconfig[server].setup(setup()) end +-- install servers and tools +require "alpha.lsp.mason" require "alpha.lsp.null-ls" diff --git a/lua/alpha/lsp/mason.lua b/lua/alpha/lsp/mason.lua index e164562..161a205 100644 --- a/lua/alpha/lsp/mason.lua +++ b/lua/alpha/lsp/mason.lua @@ -7,9 +7,8 @@ mason.setup() local mason_servers = {} --- TODO: can be improve checking the setup function to see if sets the cmd for server, _ in pairs(servers) do - local cmd = lspconfig[server].document_config.default_config.cmd[1] + local cmd = lspconfig[server].cmd[1] if vim.fn.executable(cmd) == 0 then table.insert(mason_servers, server) end @@ -21,5 +20,7 @@ mason_lspconfig.setup { -- filter the list for the ones not globally installed require("mason-tool-installer").setup { - ensure_installed = require "alpha.lsp.tools", + ensure_installed = vim.tbl_filter(function (tool) + return vim.fn.executable(tool) == 0 + end, require "alpha.lsp.tools"), } diff --git a/lua/alpha/lsp/null-ls.lua b/lua/alpha/lsp/null-ls.lua index be3d4e9..3428ec6 100644 --- a/lua/alpha/lsp/null-ls.lua +++ b/lua/alpha/lsp/null-ls.lua @@ -11,16 +11,18 @@ 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, null_ls.builtins.diagnostics.phpstan.with { to_temp_file = false, method = null_ls.methods.DIAGNOSTICS_ON_SAVE, - command = "./bin/phpstan", - condition = function () - return vim.fn.findfile("bin/phpstan") ~= "" - end + -- command = "./bin/phpstan", + -- condition = function () + -- return vim.fn.findfile("bin/phpstan") ~= "" + -- end }, null_ls.builtins.diagnostics.phpcs.with { method = null_ls.methods.DIAGNOSTICS_ON_SAVE, @@ -36,3 +38,16 @@ vim.keymap.set({ "n", "v" }, "<leader>vca", vim.lsp.buf.code_action, {desc = "LS vim.keymap.set("n", "<leader>vf", function() return vim.lsp.buf.format { async = true } end, {desc = "LSP (null ls) Format file"}) + +-- function to toogle and possible restart it +vim.api.nvim_create_user_command("NullLsToggle", function() + local sources = vim.tbl_map(function(el) + return el.name + end, null_ls.get_sources()) + vim.ui.select(sources, {}, function(selected) + if not selected then + return + end + null_ls.toggle(selected) + end) +end, {}) diff --git a/lua/alpha/lsp/servers.lua b/lua/alpha/lsp/servers.lua index f09f523..d2233a1 100644 --- a/lua/alpha/lsp/servers.lua +++ b/lua/alpha/lsp/servers.lua @@ -28,8 +28,28 @@ return { flags = lsp_flags, } end, - ["html"] = default, - ["jsonls"] = default, + ["html"] = function () + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable("html-languageserver") == 1 then + config.cmd = { "html-languageserver", "--stdio" } + end + + return config + end, + ["jsonls"] = function () + local config = { + on_attach = lsp_attach, + flags = lsp_flags, + } + if vim.fn.executable("json-languageserver") == 1 then + config.cmd = { "json-languageserver", "--stdio" } + end + + return config + end, ["lua_ls"] = function() return { on_attach = lsp_attach, @@ -51,7 +71,7 @@ return { }, hint = { enable = true, - } + }, }, }, } @@ -63,8 +83,14 @@ return { on_attach = lsp_attach, flags = lsp_flags, filetypes = { "php", "cucumber" }, + init_options = { + ["language_server_worse_reflection.inlay_hints.enable"] = true, + -- ["language_server_worse_reflection.inlay_hints.types"] = true, + -- ["language_server_worse_reflection.inlay_hints.params"] = true, + }, } end, + ["pyright"] = default, ["rust_analyzer"] = function() return { on_attach = lsp_attach, diff --git a/lua/alpha/lsp/tools.lua b/lua/alpha/lsp/tools.lua index 4eb40b3..7919521 100644 --- a/lua/alpha/lsp/tools.lua +++ b/lua/alpha/lsp/tools.lua @@ -1,6 +1,8 @@ return { + "codelldb", "go-debug-adapter", - "php-debug-adapter", "js-debug-adapter", - "codelldb", + "php-debug-adapter", + "phpcs", + "phpstan", } diff --git a/lua/alpha/php/servers.lua b/lua/alpha/php/servers.lua index ba3680c..9450152 100644 --- a/lua/alpha/php/servers.lua +++ b/lua/alpha/php/servers.lua @@ -30,8 +30,7 @@ local config = require("lspconfig").phpactor config.root_dir = vim.fn.getcwd() local client_id = vim.lsp.start(config) -local client = vim.lsp.get_client_by_id(client_id) -P(client) +vim.lsp.get_client_by_id(client_id) -- use client.request or request_sync -- look for the direct of the symbol return { 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/alpha/snips/ft/cucumber.lua b/lua/alpha/snips/ft/cucumber.lua index cb74586..6176a87 100644 --- a/lua/alpha/snips/ft/cucumber.lua +++ b/lua/alpha/snips/ft/cucumber.lua @@ -9,6 +9,13 @@ local M = { all = t [[And all stubs should be matched]], status_code = fmt([[Then the response status code should be {}]], { i(1, "200") }), no_error = t [[And the JSON path expression errors should not have result]], + json_data = fmt([[And the JSON path expression "data" should be equal to: +""" +{{ + {} +}} +""" + ]], {i(1)}), feature = fmt( [[Feature: {} diff --git a/lua/alpha/telescope/init.lua b/lua/alpha/telescope/init.lua index 38cd9be..c278028 100644 --- a/lua/alpha/telescope/init.lua +++ b/lua/alpha/telescope/init.lua @@ -1,16 +1,16 @@ -SHOULD_RELOAD_TELESCOPE = true +local SHOULD_RELOAD_TELESCOPE = true local reloader = function() if SHOULD_RELOAD_TELESCOPE then - RELOAD "plenary" - RELOAD "telescope" - RELOAD "alpha.telescope.setup" + Reload "plenary" + Reload "telescope" + Reload "alpha.telescope.setup" end end local fb_actions = require("telescope").extensions.file_browser.actions local actions = require "telescope.actions" -local my_actions = require "alpha.telescope.actions" +local my_actions = require "alpha.telescope.my_actions" local M = {} @@ -52,8 +52,8 @@ M.find_nvim_plugin = function() prompt_title = "< Plugins >", cwd = "$HOME/.config/nvim/lua/plugins/", attach_mappings = function(_, map) - map("i", "<C-t>", my_actions.create_plugin) - map("i", "<C-d>", my_actions.disable_plugin) + map("i", "<C-y>", my_actions.create_plugin) + map("i", "<C-w>", my_actions.disable_plugin) map("i", "<C-e>", my_actions.enable_plugin) return true diff --git a/lua/alpha/telescope/actions.lua b/lua/alpha/telescope/my_actions.lua index b0e9f10..b0e9f10 100644 --- a/lua/alpha/telescope/actions.lua +++ b/lua/alpha/telescope/my_actions.lua diff --git a/lua/alpha/telescope/setup.lua b/lua/alpha/telescope/setup.lua index cd5ad63..0e368c7 100644 --- a/lua/alpha/telescope/setup.lua +++ b/lua/alpha/telescope/setup.lua @@ -11,8 +11,57 @@ local set_prompt_to_entry_value = function(prompt_bufnr) action_state.get_current_picker(prompt_bufnr):reset_prompt(entry.ordinal) end +local filetype_hook = function(filepath, bufnr, opts) + -- Here for example you can say: if ft == "xyz" then this_regex_highlighing else nothing end + -- + local is_image = function(filepath) + local image_extensions = { "png", "jpg" } -- Supported image formats + local split_path = vim.split(filepath:lower(), ".", { plain = true }) + local extension = split_path[#split_path] + return vim.tbl_contains(image_extensions, extension) + end + if not is_image(filepath) then + return true + end + local ui = require "image.ui" + local options = require "image.options" + local dimensions = require "image.dimensions" + local api = require "image.api" + local config = require "image.config" + local user_opts = { + render = { + foreground_color = true, + background_color = true, + }, + } + local global_opts = vim.tbl_deep_extend("force", config.DEFAULT_OPTS, user_opts) + + local ascii_width, ascii_height, horizontal_padding, vertical_padding, img_width, img_height = + dimensions.calculate_ascii_width_height(opts.winid, filepath, global_opts) + options.set_options_before_render(bufnr) + ui.buf_clear(bufnr) + local label = ui.create_label( + filepath, + ascii_width, + horizontal_padding, + global_opts.render.show_image_dimensions, + img_width, + img_height + ) + + api.get_ascii_data_sync(filepath, ascii_width, ascii_height, global_opts, function(ascii_data) + ui.buf_insert_data_with_padding(bufnr, ascii_data, horizontal_padding, vertical_padding, label, global_opts) + + options.set_options_after_render(bufnr) + end) + return false +end + require("telescope").setup { defaults = { + preview = { + filetype_hook = filetype_hook, + }, prompt_prefix = "❯ ", selection_caret = "❯ ", @@ -30,7 +79,7 @@ require("telescope").setup { if cols > 200 then return math.floor(cols * 0.5) else - return math.floor(cols * 0.6) + return math.floor(cols * 0.7) end end, }, @@ -100,6 +149,7 @@ require("telescope").setup { path = "~/.local/share/nvim/databases/telescope_history.sqlite3", limit = 100, }, + -- buffer_previewer_maker = new_maker, }, pickers = { |