Skip to content

Commit

Permalink
feat: add Neovim LSP-related plugins and configurations (#37)
Browse files Browse the repository at this point in the history
* feat: initial LSP setup:

- The lsp.lua file configues main LSP-related plugins:
  * nvim-lspconfig - basic, default LSP client configurations
  * mason - LSP, DAP, linter, and formatter package manager
  * mason-lspconfig - automatically install and configure servers
  * mason-tool-installer - install and update Mason packages
  * fidget - LSP status messages
- dressing.nvim provides nice menus for vim.ui.select and vim.ui.input
  which are used to filter Mason packages (it's unusable without this)
- lazydev.nvim provides automatic LuaLS configurations for Neovim
  configuration files
- manjaro_packages is updated to add unzip and npm, which are required
  by Mason

* feat: add autoformat Neovim configuration

- autoformat.lua configures the Neovim plugin and formatting tools for a
  few languages
- stylua.toml configures the Lua autoformatting project-wide

* feat: add autocompletion Neovim configuration

* feat: add linting Neovim configuration
  • Loading branch information
vicnett authored Nov 17, 2024
1 parent de3c144 commit 299c44f
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manjaro_packages
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ ctags
fd
fzf
neovim
npm
ripgrep
unzip
zsh
4 changes: 4 additions & 0 deletions stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
column_width = 80
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
15 changes: 15 additions & 0 deletions vim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
{
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"bullets.vim": { "branch": "master", "commit": "83fa7298085be647e6b378ef2c8ca491ca032154" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
"conform.nvim": { "branch": "master", "commit": "6239d9986f51ca93ded99ecdb1af0e287eabb651" },
"csv.vim": { "branch": "master", "commit": "bddfcbadd788ab11eb3dbba4550a38a412fe3705" },
"dressing.nvim": { "branch": "master", "commit": "43b8f74e0b1e3f41e51f640f8efa3bcd401cea0d" },
"fidget.nvim": { "branch": "main", "commit": "ef99df04a1c53a453602421bc0f756997edc8289" },
"gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" },
"indent-blankline.nvim": { "branch": "master", "commit": "7871a88056f7144defca9c931e311a3134c5d509" },
"lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" },
"lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" },
"lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" },
"mason.nvim": { "branch": "main", "commit": "c43eeb5614a09dc17c03a7fb49de2e05de203924" },
"mini.icons": { "branch": "main", "commit": "a2742459f0ee32806c2438ca06b4d8b331f3f4d4" },
"nvim-cmp": { "branch": "main", "commit": "983453e32cb35533a119725883c04436d16c0120" },
"nvim-highlight-colors": { "branch": "main", "commit": "e967e2ba13fd4ca731b41d0e5cc1ac2edcd6e25e" },
"nvim-lint": { "branch": "master", "commit": "36da8dd0ddc4f88e0beae234c20e75397326f143" },
"nvim-lspconfig": { "branch": "master", "commit": "056f569f71e4b726323b799b9cfacc53653bceb3" },
"nvim-solarized-lua": { "branch": "master", "commit": "d69a263c97cbc765ca442d682b3283aefd61d4ac" },
"nvim-treesitter": { "branch": "master", "commit": "cfc6f2c117aaaa82f19bcce44deec2c194d900ab" },
"nvim-treesitter-context": { "branch": "master", "commit": "158377d700596367a91ea41818f76abdbf75a232" },
Expand Down
43 changes: 43 additions & 0 deletions vim/lua/plugins/autoformat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
return {
"stevearc/conform.nvim",
-- Load plugin before writing file, since it will automatically format when
-- writing
event = { "BufWritePre" },
-- Also load
cmd = { "ConformInfo" },
init = function()
-- Set formatexpr so builtin vim formatting commands will use conform.
-- This sets the following options automatically:
-- opts = vim.tbl_deep_extend("keep", opts or {}, {
-- timeout_ms = 500,
-- lsp_format = "fallback",
-- bufnr = vim.api.nvim_get_current_buf(),
-- })
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't have a
-- well standardized coding style. You can add additional languages here
-- or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
local lsp_format_opt
if disable_filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = "never"
else
lsp_format_opt = "fallback"
end
return {
timeout_ms = 500,
lsp_format = lsp_format_opt,
}
end,
-- Configure formatters per file type.
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
markdown = { "markdownlint" },
},
},
}
76 changes: 76 additions & 0 deletions vim/lua/plugins/completion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
return {
"hrsh7th/nvim-cmp",
event = "VimEnter",
dependencies = {
{
"L3MON4D3/LuaSnip",
build = (function()
return "make install_jsregexp"
end)(),
},
"saadparwaiz1/cmp_luasnip",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
},
config = function()
local cmp = require("cmp")
local luasnip = require("luasnip")
luasnip.config.setup({})

cmp.setup({
snippet = {
expand = function(args)
vim.snippet.expand(args.body)
end,
},
completion = {
-- Only manual completions, please
autocomplete = false,
completeopt = "menu,menuone,noinsert",
},

mapping = cmp.mapping.preset.insert({
-- Scroll the documentation window [b]ack / [f]orward
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),

-- Trigger a completion from nvim-cmp.
["<C-Space>"] = cmp.mapping.complete({}),

-- Think of <c-l> as moving to the right of your snippet expansion.
-- So if you have a snippet that's like:
-- function $name($args)
-- $body
-- end
--
-- <c-l> will move you to the right of each of the expansion locations.
-- <c-h> is similar, except moving you backwards.
["<C-l>"] = cmp.mapping(function()
if luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
end
end, { "i", "s" }),
["<C-h>"] = cmp.mapping(function()
if luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
end
end, { "i", "s" }),

-- For more advanced Luasnip keymaps (e.g. selecting choice nodes,
-- expansion) see:
-- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps
}),
sources = {
{
name = "lazydev",
-- set group index to 0 to skip loading LuaLS completions as lazydev recommends it
group_index = 0,
},
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "path" },
},
})
end,
}
3 changes: 3 additions & 0 deletions vim/lua/plugins/dressing.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
return {
"stevearc/dressing.nvim",
}
10 changes: 10 additions & 0 deletions vim/lua/plugins/lazydev.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
return {
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = 'luvit-meta/library', words = { 'vim%.uv' } },
},
},
}
33 changes: 33 additions & 0 deletions vim/lua/plugins/lint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
return {
{
"mfussenegger/nvim-lint",
event = { "BufReadPre", "BufNewFile" },
config = function()
local lint = require("lint")
lint.linters_by_ft = {
dockerfile = { "hadolint" },
json = { "jsonlint" },
markdown = { "markdownlint" },
terraform = { "tflint" },
}

-- Create autocommand which carries out the actual linting
-- on the specified events.
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd(
{ "BufEnter", "BufWritePost", "InsertLeave" },
{
group = lint_augroup,
callback = function()
-- Only run the linter in buffers that you can modify in order to
-- avoid superfluous noise, notably within the handy LSP pop-ups that
-- describe the hovered symbol using Markdown.
if vim.opt_local.modifiable:get() then
lint.try_lint()
end
end,
}
)
end,
},
}
Loading

0 comments on commit 299c44f

Please sign in to comment.