aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/home/.config/nvim/lua/cfg
diff options
context:
space:
mode:
Diffstat (limited to 'home/.config/nvim/lua/cfg')
-rw-r--r--home/.config/nvim/lua/cfg/lsp.lua64
-rw-r--r--home/.config/nvim/lua/cfg/options.lua124
-rw-r--r--home/.config/nvim/lua/cfg/utils.lua24
3 files changed, 212 insertions, 0 deletions
diff --git a/home/.config/nvim/lua/cfg/lsp.lua b/home/.config/nvim/lua/cfg/lsp.lua
new file mode 100644
index 0000000..5767ff6
--- /dev/null
+++ b/home/.config/nvim/lua/cfg/lsp.lua
@@ -0,0 +1,64 @@
+return {
+ on_attach_wrapper = function(client, bufnr, opts)
+ local map = require("mapper")
+ local autocmd = vim.api.nvim_create_autocmd
+
+ opts = vim.tbl_extend("force", { auto_format = false }, opts or {})
+
+ if client.supports_method("textDocument/codeLens") then
+ require("virtualtypes").on_attach(client, bufnr)
+ autocmd(
+ { "CursorHold", "CursorHoldI", "InsertLeave" },
+ { buffer = bufnr, callback = vim.lsp.codelens.refresh }
+ )
+ map.n("gl", vim.lsp.codelens.run, { buffer = bufnr })
+ end
+
+ if client.supports_method("textDocument/definition") then
+ map.n("<c-]>", vim.lsp.buf.definition, { buffer = bufnr })
+ end
+ if client.supports_method("textDocument/declaration") then
+ map.n("gD", vim.lsp.buf.declaration, { buffer = bufnr })
+ end
+ if client.supports_method("textDocument/signatureHelp") then
+ require("lsp_signature").on_attach(client, bufnr)
+ map.n("gs", vim.lsp.buf.signature_help, { buffer = bufnr })
+ end
+ if client.supports_method("textDocument/rename") then
+ map.n("gR", vim.lsp.buf.rename, { buffer = bufnr })
+ end
+ if client.supports_method("textDocument/codeAction") then
+ map.n("ga", vim.lsp.buf.code_action, { buffer = bufnr })
+ map.v("ga", vim.lsp.buf.code_action, { buffer = bufnr })
+ end
+
+ local buf_async_format = function()
+ vim.lsp.buf.format(
+ { bufnr = bufnr, async = true, id = client.id })
+ end
+ local buf_sync_format = function()
+ vim.lsp.buf.format(
+ { bufnr = bufnr, async = false, id = client.id })
+ end
+ local buf_async_format_hunks = function()
+ require("cfg.utils").format_hunks(
+ { bufnr = bufnr, async = true, id = client.id })
+ end
+
+ if client.supports_method("textDocument/formatting") then
+ map.n("<leader>f", buf_async_format, { buffer = bufnr })
+ if opts.auto_format then
+ autocmd(
+ "BufWritePre",
+ { buffer = bufnr, callback = buf_sync_format }
+ )
+ end
+ end
+ if client.supports_method("textDocument/rangeFormatting") then
+ map.v("<leader>f", buf_async_format, { buffer = bufnr })
+ map.n("<leader>hf", buf_async_format_hunks, { buffer = bufnr })
+ end
+
+ require("lsp-inlayhints").on_attach(client, bufnr, false)
+ end
+}
diff --git a/home/.config/nvim/lua/cfg/options.lua b/home/.config/nvim/lua/cfg/options.lua
new file mode 100644
index 0000000..1529121
--- /dev/null
+++ b/home/.config/nvim/lua/cfg/options.lua
@@ -0,0 +1,124 @@
+local opt = vim.opt
+
+opt.undofile = true
+opt.swapfile = false
+vim.opt.shadafile = "NONE"
+vim.g.ts_highlight_lua = true
+vim.g.ts_highlight_c = true
+vim.g.ts_highlight_vim = true
+
+opt.showmode = true
+opt.number = true
+opt.cursorline = true
+opt.signcolumn = "auto:2"
+opt.showtabline = 2
+opt.showmatch = true
+
+opt.expandtab = true
+opt.shiftround = true
+opt.shiftwidth = 0
+opt.softtabstop = -1
+opt.tabstop = 4
+
+opt.foldenable = false
+
+opt.splitbelow = true
+opt.splitright = true
+
+opt.linebreak = true
+opt.breakindent = true
+opt.textwidth = 80
+opt.colorcolumn = "+1"
+opt.formatoptions:remove("t")
+
+opt.spelllang:append({ "pt_pt", "es_es" })
+opt.spellfile = vim.fn.stdpath("config") .. "/spell/en.utf-8.add"
+
+opt.cmdheight = 2
+opt.updatetime = 300
+
+opt.shortmess:append({ a = true })
+
+opt.gdefault = true
+opt.synmaxcol = 500
+
+opt.completeopt = { "menu", "menuone", "noselect" }
+opt.scrolloff = 999
+opt.sidescrolloff = 5
+
+opt.clipboard = "unnamedplus"
+
+opt.wildmode = { "longest", "full" }
+
+opt.cpoptions:remove({ "_" })
+
+opt.listchars = {
+ tab = "> ",
+ trail = "ยท",
+ extends = ">",
+ precedes = "<",
+ nbsp = "+",
+}
+opt.list = true
+
+opt.virtualedit = "block"
+opt.spelloptions = "camel"
+
+vim.g.is_posix = 1
+vim.g.python_host_prog = 0
+vim.g.python3_host_prog = 0
+vim.g.netrw_home = vim.fn.stdpath("data")
+
+vim.g.loaded_netrw = 1
+vim.g.loaded_netrwPlugin = 1
+vim.g.loaded_netrwSettings = 1
+vim.g.loaded_netrwFileHandlers = 1
+vim.g.loaded_gzip = 1
+vim.g.loaded_zip = 1
+vim.g.loaded_zipPlugin = 1
+vim.g.loaded_tar = 1
+vim.g.loaded_tarPlugin = 1
+vim.g.loaded_zipPlugin = 1
+vim.g.loaded_getscript = 1
+vim.g.loaded_getscriptPlugin = 1
+vim.g.loaded_vimball = 1
+vim.g.loaded_vimballPlugin = 1
+vim.g.loaded_2html_plugin = 1
+vim.g.loaded_logipat = 1
+vim.g.loaded_rrhelper = 1
+vim.g.loaded_matchparen = 1
+vim.g.loaded_spec = 1
+
+opt.diffopt:append({
+ ["indent-heuristic"] = true,
+ hiddenoff = true,
+ iblank = true,
+ iwhiteall = true,
+ algorithm = "histogram",
+})
+
+if vim.fn.executable("rg") then
+ opt.grepprg = "rg\\ --vimgrep"
+ opt.grepformat:append("f:%l:%c:%m")
+end
+
+opt.termguicolors = true
+opt.pumblend = 20
+
+opt.foldmethod = "expr"
+opt.foldexpr = "nvim_treesitter#foldexpr()"
+opt.foldenable = false
+
+opt.laststatus = 2
+vim.g.mapleader = " "
+vim.g.maplocalleader = ","
+
+vim.diagnostic.config({
+ virtual_text = {
+ source = "if_many",
+ severity = vim.diagnostic.severity.ERROR,
+ },
+ signs = true,
+ underline = true,
+ update_in_insert = false,
+})
diff --git a/home/.config/nvim/lua/cfg/utils.lua b/home/.config/nvim/lua/cfg/utils.lua
new file mode 100644
index 0000000..abda35d
--- /dev/null
+++ b/home/.config/nvim/lua/cfg/utils.lua
@@ -0,0 +1,24 @@
+local M = {}
+local gitsigns = require("gitsigns")
+
+function M.format_hunks(options)
+ local hunks = require("gitsigns").get_hunks()
+ if not hunks or vim.tbl_isempty(hunks) then
+ return
+ end
+ for _, hunk in ipairs(hunks) do
+ local added = hunk.added
+ if added then
+ local start_line = added.start
+ local count = added.count
+ if start_line and count and start_line > 0 and count > 0 then
+ local end_line = start_line + added.count - 1
+ local range = { start = { start_line, 0 }, ["end"] = { end_line, 0 } }
+ options = vim.tbl_extend("force", { range = range }, options or {})
+ vim.lsp.buf.format(options)
+ end
+ end
+ end
+end
+
+return M