commit 97347067f65c59c6975f47587748119f5b2f9aba from: Andre M. Bertachini date: Sun May 11 02:24:03 2025 UTC LSP Config and Formatting commit - 3be0639a9062658804becb993d8b2687c123c9c2 commit + 97347067f65c59c6975f47587748119f5b2f9aba blob - 90b9c4a7b0a0a6a9f017bdc48ffac8843a9392d2 blob + 6628c28a24012404d3cb4d16909295ea5101c780 --- init.lua +++ init.lua @@ -1,11 +1,14 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -require 'plugins.lazy' +require('plugins.lazy') require('lazy').setup({ - require 'plugins/telescope' + require('plugins/telescope'), + require('plugins/mason'), + require('plugins/lspconfig'), + require('plugins/conform'), }) -require 'config.options' -require 'config.keymaps' +require('config.options') +require('config.keymaps') blob - 995738b008bada3c6825615a94fbd1640f7a7c32 blob + 5f1f13082416d29610789fc428681e9fb8568bbd --- lazy-lock.json +++ lazy-lock.json @@ -1,6 +1,12 @@ { + "conform.nvim": { "branch": "master", "commit": "374aaf384e2e841607b8e2fe63fa3ad01d111c91" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "d39a75bbce4b8aad5d627191ea915179c77c100f" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "aafae207d5a2a28c59c9d478d8581c2739135d09" }, + "mason.nvim": { "branch": "main", "commit": "7c7318e8bae7e3536ef6b9e86b9e38e74f2e125e" }, + "nvim-lspconfig": { "branch": "master", "commit": "61e5109c8cf24807e4ae29813a3a82b31821dd45" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" } } blob - 0974f2dad9ec8b6ca79d7e71136f442486e8c4bc blob + b2b1a0c36baa9b9cd650b87130f0229893bba2b6 --- lua/config/keymaps.lua +++ lua/config/keymaps.lua @@ -36,16 +36,15 @@ vim.keymap.set('n', '', '', { desc = 'M vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) - -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = function() - vim.highlight.on_yank() - end, + desc = 'Highlight when yanking (copying) text', + group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), + callback = function() + vim.highlight.on_yank() + end, }) vim.keymap.set('t', '', '', { desc = 'Exit terminal mode' }) @@ -71,4 +70,37 @@ vim.keymap.set('n', 'sb', 'Telescope buff vim.keymap.set('n', 'gf', 'Telescope git_files', { desc = 'Find Git-tracked files' }) vim.keymap.set('n', 'sh', 'Telescope help_tags', { desc = 'Search help tags' }) vim.keymap.set('n', 'sr', 'Telescope oldfiles', { desc = 'List recent files' }) -vim.keymap.set('n', 'sz', 'Telescope current_buffer_fuzzy_find', { desc = 'Fuzzy find in current buffer' }) +vim.keymap.set( + 'n', + 'sz', + 'Telescope current_buffer_fuzzy_find', + { desc = 'Fuzzy find in current buffer' } +) + +-- Conform +vim.keymap.set({ 'n', 'x' }, 'f', function() + require('conform').format({ async = true, lsp_fallback = true }) +end, { desc = '[C]ode [F]ormat' }) + +-- LSP keymaps (set on LspAttach) +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', { clear = true }), + callback = function(event) + local lsp_map = function(keys, func, desc, mode) + mode = mode or 'n' + vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) + end + + -- Core navigation (single-key, no prefix) + lsp_map('gd', require('telescope.builtin').lsp_definitions, 'Go to Definition') + lsp_map('gD', vim.lsp.buf.declaration, 'Go to Declaration') + lsp_map('gi', require('telescope.builtin').lsp_implementations, 'Go to Implementation') + lsp_map('gr', require('telescope.builtin').lsp_references, 'Get References') + lsp_map('K', vim.lsp.buf.hover, 'Show hover documentation') + + -- Leader-based LSP actions (under l for less frequent actions) + lsp_map('lr', vim.lsp.buf.rename, 'Rename across multiple files', 'n') + lsp_map('la', vim.lsp.buf.code_action, 'Code actions', { 'n', 'x' }) + lsp_map('lt', require('telescope.builtin').lsp_type_definitions, 'Type Definition') + end, +}) blob - cfba14dc15db438fe815d17a0d21d3f65ecaea4f blob + 60376135828e270a184d042effe1e8f8aeb9d4e3 --- lua/config/options.lua +++ lua/config/options.lua @@ -9,7 +9,7 @@ vim.o.showmode = false -- Sync clipboard between OS and Neovim. vim.schedule(function() - vim.o.clipboard = 'unnamedplus' + vim.o.clipboard = 'unnamedplus' end) -- Enable break indent @@ -52,5 +52,3 @@ vim.o.scrolloff = 10 -- instead raise a dialog asking if you wish to save the current file(s) -- See `:help 'confirm'` vim.o.confirm = true - --- vim: ts=2 sts=2 sw=2 et blob - 242ede334e2859fea69f50f538bf9c6b6aad4d82 blob + 25523869af3986209d2421e9c188b113222da7ef --- lua/plugins/lazy.lua +++ lua/plugins/lazy.lua @@ -1,15 +1,15 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim' if not (vim.uv or vim.loop).fs_stat(lazypath) then - local lazyrepo = "https://github.com/folke/lazy.nvim.git" - local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) - if vim.v.shell_error ~= 0 then - vim.api.nvim_echo({ - { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, - { out, "WarningMsg" }, - { "\nPress any key to exit..." }, - }, true, {}) - vim.fn.getchar() - os.exit(1) - end + local lazyrepo = 'https://github.com/folke/lazy.nvim.git' + local out = vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }) + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { 'Failed to clone lazy.nvim:\n', 'ErrorMsg' }, + { out, 'WarningMsg' }, + { '\nPress any key to exit...' }, + }, true, {}) + vim.fn.getchar() + os.exit(1) + end end vim.opt.runtimepath:prepend(lazypath) blob - /dev/null blob + 609b6c2631e6da6463e0e6037354551ade1d59a8 (mode 644) --- /dev/null +++ lua/plugins/conform.lua @@ -0,0 +1,12 @@ +return { + { + 'stevearc/conform.nvim', + cmd = { 'ConformInfo' }, + opts = { + notify_on_error = true, + formatters_by_ft = { + lua = { 'stylua' }, + }, + }, + }, +} blob - 4338fe2b02e3d3bdb5f6336488b458890784eaaa blob + a95912f76c3be67ed25ef341e032eb2506d1235f --- lua/plugins/telescope.lua +++ lua/plugins/telescope.lua @@ -3,23 +3,24 @@ return { branch = '0.1.x', dependencies = { 'nvim-lua/plenary.nvim', + { 'nvim-telescope/telescope-ui-select.nvim' }, { - 'nvim-telescope/telescope-fzf-native.nvim', + 'nvim-telescope/telescope-fzf-native.nvim', + -- `build` is used to run some command when the plugin is installed/updated. + -- This is only run then, not every time Neovim starts up. + build = 'make', - -- `build` is used to run some command when the plugin is installed/updated. - -- This is only run then, not every time Neovim starts up. - build = 'make', - - -- `cond` is a condition used to determine whether this plugin should be - -- installed and loaded. - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, + -- `cond` is a condition used to determine whether this plugin should be + -- installed and loaded. + cond = function() + return vim.fn.executable('make') == 1 + end, + }, }, cmd = 'Telescope', -- Lazy-load on :Telescope command config = function() pcall(require('telescope').load_extension, 'fzf') + pcall(require('telescope').load_extension, 'ui-select') require('telescope').setup({ defaults = { -- Minimal layout for speed @@ -43,6 +44,11 @@ return { }, }, }, + extensions = { + ['ui-select'] = { + require('telescope.themes').get_dropdown(), + }, + }, }) end, } blob - /dev/null blob + d5c6154c7eb54ceb8d2132da4c0dd07ab195af74 (mode 644) --- /dev/null +++ lua/plugins/lspconfig.lua @@ -0,0 +1,58 @@ +return { + { + 'neovim/nvim-lspconfig', + dependencies = { + { 'williamboman/mason-lspconfig.nvim' }, + }, + config = function() + local lspconfig = require('lspconfig') + local capabilities = vim.lsp.protocol.make_client_capabilities() + + vim.diagnostic.config({ + severity_sort = true, + float = { border = 'rounded', source = 'if_many' }, + underline = { severity = vim.diagnostic.severity.ERROR }, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = '󰅚 ', + [vim.diagnostic.severity.WARN] = '󰀪 ', + [vim.diagnostic.severity.INFO] = '󰋽 ', + [vim.diagnostic.severity.HINT] = '󰌶 ', + }, + } or {}, + virtual_text = { + source = 'if_many', + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, + }) + + -- Define LSP servers and their configurations + local servers = { + lua_ls = { + settings = { + Lua = { + diagnostics = { globals = { 'vim' } }, + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, + }, + } + + for server_name, server_config in pairs(servers) do + lspconfig[server_name].setup(vim.tbl_deep_extend('force', { + capabilities = capabilities, + }, server_config)) + end + end, + }, +} blob - /dev/null blob + cdf95b5419e6f77c2092a1a841cfdc91af244d47 (mode 644) --- /dev/null +++ lua/plugins/mason.lua @@ -0,0 +1,19 @@ +return { + { + "williamboman/mason.nvim", + opts = {}, + }, + { + "williamboman/mason-lspconfig.nvim", + opts = { + ensure_installed = { "lua_ls" }, + automatic_installation = true, + }, + }, + { + "WhoIsSethDaniel/mason-tool-installer.nvim", + opts = { + ensure_installed = { "stylua" }, + }, + }, +} blob - /dev/null blob + b352dd7109ae42c6169064ca7bbec6b5e605cb6c (mode 644) --- /dev/null +++ stylua.toml @@ -0,0 +1,4 @@ +indent_type = "Spaces" +indent_width = 4 +column_width = 120 +quote_style = "AutoPreferSingle"