diff options
Diffstat (limited to '.config')
-rw-r--r-- | .config/nvim/init.lua | 139 | ||||
-rw-r--r-- | .config/nvim/lua/set.lua | 79 |
2 files changed, 193 insertions, 25 deletions
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 9012b4a..8a2de27 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -45,6 +45,9 @@ vim.keymap.set('n', '<Esc>', vim.cmd.nohlsearch) vim.keymap.set('n', '<S-Right>', vim.cmd.bnext) vim.keymap.set('n', '<S-Left>', vim.cmd.bprev) + +---@param buffer integer +---@return string local function get_formated_bufname(buffer) buffer = buffer or 0 @@ -64,7 +67,9 @@ local function get_formated_bufname(buffer) return name end +---@class Line Line = { + ---@return string status = function() local buffer = vim.api.nvim_win_get_buf(vim.g.statusline_winid) local buftype = vim.bo[buffer].buftype @@ -97,6 +102,7 @@ Line = { }, " ") end, + ---@return string tab = function() local tabs = vim.api.nvim_list_tabpages() local format = vim.tbl_map(function(tab) @@ -120,6 +126,7 @@ Line = { return tabline .. '%#TabLineFill#%T' end, + ---@return string column = function() local col = {} if vim.opt.foldenable:get() then @@ -162,15 +169,9 @@ require 'nvim-treesitter.configs'.setup { auto_install = true, } -function Set(list) - local set = {} - for _, l in ipairs(list) - do - set[l] = true - end - return set -end +local set = require 'set' +---@param dir string function Filepicker(dir) vim.fs.normalize(dir) local function action(result) @@ -208,10 +209,11 @@ function Filepicker(dir) return tbl end, files) files = vim.tbl_filter(function(tbl) + local valid = set:new { "file", "directory" } if tbl[2] == "link" then - return Set { "file", "directory" }[tbl[4]] + return valid:has(tbl[4]) else - return Set { "file", "directory" }[tbl[2]] + return valid:has(tbl[2]) end end, files) vim.ui.select(files, { @@ -292,6 +294,7 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set('n', 'grn', vim.lsp.buf.rename, opts) vim.keymap.set({ 'n', 'v' }, 'gra', vim.lsp.buf.code_action, opts) + vim.keymap.set({ 'n', 'v' }, 'grl', vim.lsp.codelens.run, opts) vim.keymap.set('n', 'grr', vim.lsp.buf.references, opts) vim.keymap.set('n', 'gri', vim.lsp.buf.implementation, opts) vim.keymap.set('n', 'gO', vim.lsp.buf.document_symbol, opts) @@ -312,55 +315,141 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.lsp.inlay_hint.enable() + vim.lsp.codelens.refresh({ bufnr = ev.buf }) + + vim.api.nvim_create_autocmd({ 'CursorHold', 'InsertLeave' }, { + buffer = ev.buf, + callback = function() + vim.lsp.codelens.refresh({ bufnr = ev.buf }) + end, + }) + vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = ev.buf, - callback = function () + callback = function() vim.lsp.buf.document_highlight() end, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = ev.buf, - callback = function () + callback = function() vim.lsp.buf.clear_references() end, }) vim.api.nvim_create_autocmd('LspDetach', { - callback = function(event) + callback = function() vim.lsp.buf.clear_references() end, }) end, }) -local capabilities = vim.tbl_deep_extend( - "force", - {}, - vim.lsp.protocol.make_client_capabilities(), - require('cmp_nvim_lsp').default_capabilities() -) +--- Setup LSP Server with lspconfig and nvim-cmp +---@param server_name string +---@param settings ?lspconfig.Config +local function setupLSP(server_name, settings) + settings = settings or {} + settings.capabilities = vim.tbl_deep_extend( + "force", + {}, + vim.lsp.protocol.make_client_capabilities(), + require('cmp_nvim_lsp').default_capabilities() + ) + local config = require("lspconfig") + require("lspconfig")[server_name].setup(settings) +end + require('mason').setup {} require('mason-lspconfig').setup { ensure_installed = { 'lua_ls' }, handlers = { function(server_name) - require("lspconfig")[server_name].setup { - capabilities = capabilities - } + setupLSP(server_name) end, lua_ls = function() - require("lspconfig").lua_ls.setup { + setupLSP("lua_ls", { settings = { Lua = { completion = { callSnippet = 'Replace', }, - diagnostics = { disable = { 'missing-fields' } }, + diagnostics = { + disable = { 'missing-fields' } + }, + hint = { + enable = true + } + }, + } + }) + end, + gopls = function() + setupLSP("gopls", { + settings = { + gopls = { + hints = { + rangeVariableTypes = true, + parameterNames = true, + constantValues = true, + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + functionTypeParameters = true, + }, + codelenses ={ + gc_details = true, + } + }, + } + }) + end, + clangd = function() + setupLSP("clangd", { + settings = { + clangd = { + InlayHints = { + Designators = true, + Enabled = true, + ParameterNames = true, + DeducedTypes = true, + }, + fallbackFlags = { "-std=c++20" }, + }, + } + }) + end, + ts_ls = function() + setupLSP("ts_ls", { + settings = { + typescript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = false, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, + }, + javascript = { + inlayHints = { + includeInlayParameterNameHints = "all", + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = false, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + }, }, } - } + }) end, rust_analyzer = function() end, } diff --git a/.config/nvim/lua/set.lua b/.config/nvim/lua/set.lua new file mode 100644 index 0000000..1e829d5 --- /dev/null +++ b/.config/nvim/lua/set.lua @@ -0,0 +1,79 @@ +---@class Set +---@field elements table<any, boolean> +Set = {} +Set.__index = Set + +--- Constructor for creating a new set +---@param initialList table|nil -- Accepts a table (list) or nil for empty set +---@return Set +function Set:new(initialList) + local instance = setmetatable({}, self) + instance.elements = {} + + -- Populate the set with elements from initialList if provided + if initialList then + for _, element in ipairs(initialList) do + instance:add(element) + end + end + + return instance +end + +--- Add an element to the set +---@param element any +function Set:add(element) + self.elements[element] = true -- Setting key to true enforces uniqueness +end + +--- Remove an element from the set +---@param element any +function Set:remove(element) + self.elements[element] = nil +end + +---Check if the set contains an element +---@param element any +function Set:has(element) + return self.elements[element] ~= nil +end + +---Union operation: combines two sets +---@param otherSet Set +---@return Set +function Set:union(otherSet) + local resultSet = Set:new() + for key in pairs(self.elements) do + resultSet:add(key) + end + for key in pairs(otherSet.elements) do + resultSet:add(key) + end + return resultSet +end + +-- Intersection operation: elements common to both sets +function Set:intersection(otherSet) + local resultSet = Set:new() + for key in pairs(self.elements) do + if otherSet:contains(key) then + resultSet:add(key) + end + end + return resultSet +end + +-- Difference operation: elements in this set but not in otherSet +---@param otherSet Set +---@return Set +function Set:difference(otherSet) + local resultSet = Set:new() + for key in pairs(self.elements) do + if not otherSet:has(key) then + resultSet:add(key) + end + end + return resultSet +end + +return Set |