Skip to content

Commit

Permalink
nvim: setup formatter for lua using conform
Browse files Browse the repository at this point in the history
  • Loading branch information
rapelista committed Oct 19, 2024
1 parent a27c4da commit 0c0f1de
Show file tree
Hide file tree
Showing 18 changed files with 350 additions and 182 deletions.
7 changes: 0 additions & 7 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
{
"runtime.version": "LuaJIT",
"runtime.path": ["lua/?.lua", "lua/?/init.lua"],
"diagnostics.globals": ["vim"],
"workspace.checkThirdParty": false,
"workspace.library": ["$VIMRUNTIME"]
}
1 change: 0 additions & 1 deletion .stylua.toml

This file was deleted.

6 changes: 3 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require("core.options")
require("core.keymaps")
require("core.lazy")
require('core.options')
require('core.keymaps')
require('core.lazy')
10 changes: 10 additions & 0 deletions lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"LuaSnip": { "branch": "master", "commit": "e808bee352d1a6fcf902ca1a71cee76e60e24071" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
"conform.nvim": { "branch": "master", "commit": "f5bd8419f8a29451e20bdb1061a54fe13d5c8de3" },
"copilot.vim": { "branch": "release", "commit": "87038123804796ca7af20d1b71c3428d858a9124" },
"cyberdream.nvim": { "branch": "main", "commit": "358f6bfdd06115c139fb5518d3b95688083b7f70" },
"friendly-snippets": { "branch": "main", "commit": "de8fce94985873666bd9712ea3e49ee17aadb1ed" },
"lazy.nvim": { "branch": "main", "commit": "1159bdccd8910a0fd0914b24d6c3d186689023d9" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" },
"nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" },
"nvim-autopairs": { "branch": "master", "commit": "ee297f215e95a60b01fde33275cc3c820eddeebe" },
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
"nvim-lsp-file-operations": { "branch": "master", "commit": "92a673de7ecaa157dd230d0128def10beb56d103" },
"nvim-lspconfig": { "branch": "master", "commit": "fd49d5863e873891be37afac79b1f56fb34bb5d3" },
"nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" },
"nvim-treesitter": { "branch": "master", "commit": "a3ca2e60563064cea008555d0b7d031430305b09" },
"nvim-ts-autotag": { "branch": "main", "commit": "e239a560f338be31337e7abc3ee42515daf23f5e" },
Expand Down
56 changes: 28 additions & 28 deletions lua/core/keymaps.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")

vim.keymap.set("n", "J", "mzJ`z")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set('n', 'J', 'mzJ`z')
vim.keymap.set('n', '<C-d>', '<C-d>zz')
vim.keymap.set('n', '<C-u>', '<C-u>zz')
vim.keymap.set('n', 'n', 'nzzzv')

vim.keymap.set("n", "N", "nzzzv")
vim.keymap.set('n', 'N', 'nzzzv')

vim.keymap.set("x", "<leader>p", '"_dP')
vim.keymap.set('x', '<leader>p', '"_dP')

vim.keymap.set("v", "<", "<gv")
vim.keymap.set("v", ">", ">gv")
vim.keymap.set('v', '<', '<gv')
vim.keymap.set('v', '>', '>gv')

vim.keymap.set("v", "~", "~gv")
vim.keymap.set("v", "U", "Ugv")
vim.keymap.set("v", "u", "ugv")
vim.keymap.set('v', '~', '~gv')
vim.keymap.set('v', 'U', 'Ugv')
vim.keymap.set('v', 'u', 'ugv')

vim.keymap.set("n", "<Up>", ":resize -2<CR>")
vim.keymap.set("n", "<Down>", ":resize +2<CR>")
vim.keymap.set("n", "<Left>", ":vertical resize -2<CR>")
vim.keymap.set("n", "<Right>", ":vertical resize +2<CR>")
vim.keymap.set('n', '<Up>', ':resize -2<CR>')
vim.keymap.set('n', '<Down>', ':resize +2<CR>')
vim.keymap.set('n', '<Left>', ':vertical resize -2<CR>')
vim.keymap.set('n', '<Right>', ':vertical resize +2<CR>')

vim.keymap.set("n", "<leader>|", "<C-w>v")
vim.keymap.set("n", "<leader>-", "<C-w>s")
vim.keymap.set("n", "<leader>se", "<C-w>=")
vim.keymap.set("n", "<leader>xs", ":close<CR>")
vim.keymap.set('n', '<leader>|', '<C-w>v')
vim.keymap.set('n', '<leader>-', '<C-w>s')
vim.keymap.set('n', '<leader>se', '<C-w>=')
vim.keymap.set('n', '<leader>xs', ':close<CR>')

vim.keymap.set("n", "<leader>k", ":wincmd k<CR>")
vim.keymap.set("n", "<leader>j", ":wincmd j<CR>")
vim.keymap.set("n", "<leader>h", ":wincmd h<CR>")
vim.keymap.set("n", "<leader>l", ":wincmd l<CR>")
vim.keymap.set('n', '<leader>k', ':wincmd k<CR>')
vim.keymap.set('n', '<leader>j', ':wincmd j<CR>')
vim.keymap.set('n', '<leader>h', ':wincmd h<CR>')
vim.keymap.set('n', '<leader>l', ':wincmd l<CR>')

vim.keymap.set("n", "<leader>c", ":bd!<CR>")
vim.keymap.set("n", "<leader>kw", ":%bd!<CR><CR>")
vim.keymap.set('n', '<leader>c', ':bd!<CR>')
vim.keymap.set('n', '<leader>kw', ':%bd!<CR><CR>')

vim.keymap.set("n", "Q", "<nop>")
vim.keymap.set('n', 'Q', '<nop>')
17 changes: 9 additions & 8 deletions lua/core/lazy.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
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 })
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..." },
{ '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.rtp:prepend(lazypath)

require("lazy").setup({
require('lazy').setup({
spec = {
{ import = "plugins" },
{ import = 'plugins' },
{ import = 'plugins.lsp' },
},
defaults = {
lazy = false,
Expand Down
34 changes: 34 additions & 0 deletions lua/plugins/cmp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
return {
'hrsh7th/nvim-cmp',
event = 'InsertEnter',
dependencies = {
'hrsh7th/cmp-buffer',
'hrsh7th/cmp-path',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
'rafamadriz/friendly-snippets',
},
config = function()
local cmp = require('cmp')
local luasnip = require('luasnip')

require('luasnip.loaders.from_vscode').lazy_load()

cmp.setup({
completion = {
completeopt = 'menu,menuone,preview,noselect',
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
},
})
end,
}
32 changes: 16 additions & 16 deletions lua/plugins/colorscheme.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
return {
"scottmckendry/cyberdream.nvim",
lazy = false,
priority = 1000,
config = function()
require("cyberdream").setup({
transparent = true,
terminal_colors = true,
theme = {
saturation = 1,
},
extensions = {
telescope = false,
},
})
'scottmckendry/cyberdream.nvim',
lazy = false,
priority = 1000,
config = function()
require('cyberdream').setup({
transparent = true,
terminal_colors = true,
theme = {
saturation = 1,
},
extensions = {
telescope = false,
},
})

vim.cmd("colorscheme cyberdream")
end,
vim.cmd('colorscheme cyberdream')
end,
}
31 changes: 31 additions & 0 deletions lua/plugins/conform.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
return {
'stevearc/conform.nvim',
lazy = false,
event = { 'BufWritePre' },
cmd = { 'ConformInfo' },
keys = {
{
'<leader>f',
function()
require('conform').format({ async = true })
end,
mode = { 'n', 'v' },
desc = 'Format buffer',
},
},
---@module "conform"
---@type conform.setupOpts
opts = {
formatters_by_ft = {
lua = { 'stylua' },
},
default_format_opts = {
lsp_format = 'fallback',
},
format_on_save = { timeout_ms = 500 },
formatters = {},
},
init = function()
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}
16 changes: 8 additions & 8 deletions lua/plugins/copilot.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
return {
"github/copilot.vim",
config = function()
vim.keymap.set("i", "<C-O>", 'copilot#Accept("\\<CR>")', {
expr = true,
replace_keycodes = false,
})
vim.g.copilot_no_tab_map = true
end,
'github/copilot.vim',
config = function()
vim.keymap.set('i', '<C-O>', 'copilot#Accept("\\<CR>")', {
expr = true,
replace_keycodes = false,
})
vim.g.copilot_no_tab_map = true
end,
}
80 changes: 80 additions & 0 deletions lua/plugins/lsp/lspconfig.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
return {
'neovim/nvim-lspconfig',
event = { 'BufReadPre', 'BufNewFile' },
dependencies = {
'hrsh7th/cmp-nvim-lsp',
{ 'antosha417/nvim-lsp-file-operations', config = true },
},
config = function()
local mason_lspconfig = require('mason-lspconfig')
local cmp_nvim_lsp = require('cmp_nvim_lsp')

local lspconfig = require('lspconfig')
local lsp_defaults = require('lspconfig').util.default_config

lsp_defaults.capabilities =
vim.tbl_deep_extend('force', lsp_defaults.capabilities, cmp_nvim_lsp.default_capabilities())

vim.api.nvim_create_autocmd('LspAttach', {
desc = 'LSP actions',
callback = function(event)
local opts = { buffer = event.buf }
vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
vim.keymap.set('n', 'gc', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
vim.keymap.set('n', 'ga', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
end,
})

mason_lspconfig.setup({
ensure_installed = {
'lua_ls',
},
handlers = {
function(server_name)
require('lspconfig')[server_name].setup({})
end,
},
})

lspconfig.lua_ls.setup({
settings = {
Lua = {
diagnostics = {
globals = { 'vim' },
},
workspace = {
-- library = {
-- [vim.fn.expand("$VIMRUNTIME/lua")] = true,
-- [vim.fn.stdpath("config") .. "/lua"] = true
-- },
library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false,
},
codeLens = {
enable = true,
},
completion = {
callSnippet = 'Replace',
},
doc = {
privateName = { '^_' },
},
hint = {
enable = true,
setType = false,
paramType = true,
paramName = 'Disable',
semicolon = 'Disable',
arrayIndex = 'Disable',
},
},
},
})
end,
}
19 changes: 19 additions & 0 deletions lua/plugins/lsp/mason.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
return {
'williamboman/mason.nvim',
dependencies = {
'williamboman/mason-lspconfig.nvim',
},
config = function()
local mason = require('mason')

mason.setup({
ui = {
icons = {
package_installed = '',
package_pending = '',
package_uninstalled = '',
},
},
})
end,
}
34 changes: 17 additions & 17 deletions lua/plugins/luasnip.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
return {
{
"L3MON4D3/LuaSnip",
lazy = true,
build = "make install_jsregexp",
dependencies = {
{
"rafamadriz/friendly-snippets",
config = function()
require("luasnip.loaders.from_vscode").lazy_load()
end,
},
},
opts = {
history = true,
delete_check_events = "TextChanged",
},
},
{
'L3MON4D3/LuaSnip',
lazy = true,
build = 'make install_jsregexp',
dependencies = {
{
'rafamadriz/friendly-snippets',
config = function()
require('luasnip.loaders.from_vscode').lazy_load()
end,
},
},
opts = {
history = true,
delete_check_events = 'TextChanged',
},
},
}
Loading

0 comments on commit 0c0f1de

Please sign in to comment.