Format neovim config with stylua using new stylua.toml config

This commit is contained in:
2022-01-22 12:10:28 +03:00
parent 1a29e2858a
commit 8b75b3b1ea
10 changed files with 324 additions and 317 deletions

View File

@@ -4,94 +4,94 @@ local fn = vim.fn
-- Install packer automagically
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
PACKER_BOOTSTRAP = fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
PACKER_BOOTSTRAP = fn.system({
"git",
"clone",
"--depth",
"1",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
end
require("packer").startup(function(use)
use({ "wbthomason/packer.nvim" })
use({ "wbthomason/packer.nvim" })
use({ "nvim-lua/popup.nvim" })
use({ "nvim-lua/plenary.nvim" })
use({ "nvim-lua/popup.nvim" })
use({ "nvim-lua/plenary.nvim" })
-- Colorschemes go here
use({ "folke/tokyonight.nvim" })
-- Colorschemes go here
use({ "folke/tokyonight.nvim" })
-- Make commenting code great
use({ "tpope/vim-commentary" })
-- Make commenting code great
use({ "tpope/vim-commentary" })
-- Icons used by many plugins
use({ "kyazdani42/nvim-web-devicons" })
-- Icons used by many plugins
use({ "kyazdani42/nvim-web-devicons" })
-- Auto pairs plugin that automatically closes brackets and quotes
use({ "windwp/nvim-autopairs" })
-- Auto pairs plugin that automatically closes brackets and quotes
use({ "windwp/nvim-autopairs" })
-- File tree
use({ "kyazdani42/nvim-tree.lua" })
-- File tree
use({ "kyazdani42/nvim-tree.lua" })
-- Treesitter for better syntax highlighting
use({
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
{
{ "JoosepAlviste/nvim-ts-context-commentstring" },
{ "nvim-treesitter/playground" },
{ "windwp/nvim-ts-autotag" },
},
})
-- Treesitter for better syntax highlighting
use({
"nvim-treesitter/nvim-treesitter",
run = ":TSUpdate",
{
{ "JoosepAlviste/nvim-ts-context-commentstring" },
{ "nvim-treesitter/playground" },
{ "windwp/nvim-ts-autotag" },
},
})
-- Git things
use({ "lewis6991/gitsigns.nvim" })
use({ "tpope/vim-fugitive" })
-- Git things
use({ "lewis6991/gitsigns.nvim" })
use({ "tpope/vim-fugitive" })
-- LSP stuff
use({ "neovim/nvim-lspconfig" })
use({ "williamboman/nvim-lsp-installer" })
use({ "jose-elias-alvarez/null-ls.nvim" })
-- LSP stuff
use({ "neovim/nvim-lspconfig" })
use({ "williamboman/nvim-lsp-installer" })
use({ "jose-elias-alvarez/null-ls.nvim" })
-- Completion, snippets, etc
use({
"hrsh7th/nvim-cmp",
{
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-buffer" },
{ "hrsh7th/cmp-path" },
{ "hrsh7th/cmp-cmdline" },
},
})
use({ "L3MON4D3/LuaSnip", {
"saadparwaiz1/cmp_luasnip",
} })
-- Completion, snippets, etc
use({
"hrsh7th/nvim-cmp",
{
{ "hrsh7th/cmp-nvim-lsp" },
{ "hrsh7th/cmp-buffer" },
{ "hrsh7th/cmp-path" },
{ "hrsh7th/cmp-cmdline" },
},
})
use({ "L3MON4D3/LuaSnip", {
"saadparwaiz1/cmp_luasnip",
} })
use({ "nvim-telescope/telescope.nvim" })
use({ "nvim-telescope/telescope.nvim" })
-- Statusline
use({ "nvim-lualine/lualine.nvim" })
-- Statusline
use({ "nvim-lualine/lualine.nvim" })
-- Highlight todo comments
use({
"folke/todo-comments.nvim",
config = function()
require("todo-comments").setup({})
end,
})
-- Highlight todo comments
use({
"folke/todo-comments.nvim",
config = function()
require("todo-comments").setup({})
end,
})
use({
"folke/trouble.nvim",
config = function()
require("trouble").setup({})
end,
})
use({
"folke/trouble.nvim",
config = function()
require("trouble").setup({})
end,
})
if PACKER_BOOTSTRAP then
require("packer").sync()
end
if PACKER_BOOTSTRAP then
require("packer").sync()
end
end)
vim.g.mapleader = " "

View File

@@ -1,9 +1,9 @@
function open_terminal(vertically)
vertically = vertically or false
vertically = vertically or false
if vertically then
vim.cmd(":vs term://bash")
else
vim.cmd(":split term://bash")
end
if vertically then
vim.cmd(":vs term://bash")
else
vim.cmd(":split term://bash")
end
end

View File

@@ -1,40 +1,57 @@
local tree_cb = require("nvim-tree.config").nvim_tree_callback
local nmap = require("user.utils").nmap
require("nvim-tree").setup({
disable_netrw = true,
hijack_netrw = true,
open_on_setup = true,
hijack_cursor = true,
open_on_tab = true,
update_cwd = true,
auto_close = true,
update_focused_file = {
enable = true,
},
view = {
width = 30,
side = "left",
auto_resize = true,
mappings = {
list = {
{
key = "<C-t>",
cb = tree_cb("tabnew"),
},
},
},
},
filters = {
custom = { ".git" },
},
git = {
ignore = false,
},
})
vim.g.nvim_tree_show_icons = {
git = 1,
files = 1,
folders = 1,
}
vim.g.nvim_tree_icons = {
default = "",
symlink = "",
git = {
unstaged = "U",
staged = "S",
unmerged = "M",
renamed = "R",
untracked = "N",
deleted = "D",
},
}
vim.g.nvim_tree_git_hl = 1
vim.g.nvim_tree_add_trailing = 1
vim.g.nvim_tree_indent_markers = 1
-- TODO: Change git icons to something similar to vscode
require("nvim-tree").setup({
disable_netrw = true,
hijack_netrw = true,
open_on_setup = true,
hijack_cursor = true,
open_on_tab = true,
update_cwd = true,
auto_close = true,
update_focused_file = {
enable = true,
},
view = {
width = 30,
side = "left",
auto_resize = true,
mappings = {
list = {
{
key = "<C-t>",
cb = tree_cb("tabnew"),
},
},
},
},
filters = {
custom = { ".git" },
},
git = {
ignore = false,
},
})
nmap("<leader>b", ":NvimTreeToggle<CR>")

View File

@@ -1,17 +1,17 @@
require("gitsigns").setup({
signcolumn = true,
keymaps = {
noremap = true,
signcolumn = true,
keymaps = {
noremap = true,
["n <leader>gs"] = ":Gitsigns stage_hunk<CR>",
["n <leader>gu"] = ":Gitsigns undo_stage_hunk<CR>",
["n <leader>gr"] = ":Gitsigns reset_hunk<CR>",
},
current_line_blame = true,
current_line_blame_opts = {
delay = 1000,
},
current_line_blame_formatter_opts = {
relative_time = true,
},
["n <leader>gs"] = ":Gitsigns stage_hunk<CR>",
["n <leader>gu"] = ":Gitsigns undo_stage_hunk<CR>",
["n <leader>gr"] = ":Gitsigns reset_hunk<CR>",
},
current_line_blame = true,
current_line_blame_opts = {
delay = 1000,
},
current_line_blame_formatter_opts = {
relative_time = true,
},
})

View File

@@ -4,129 +4,129 @@ local null_ls = require("null-ls")
local list_includes_item = require("user.utils").list_includes_item
local kind_icons = {
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
TypeParameter = "",
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
TypeParameter = "",
}
local formatting = null_ls.builtins.formatting
local diagnostics = null_ls.builtins.diagnostics
null_ls.setup({
sources = {
formatting.prettierd,
formatting.stylua,
formatting.black,
formatting.gofmt,
formatting.goimports,
formatting.shfmt,
},
on_attach = function()
vim.cmd([[
sources = {
formatting.prettierd,
formatting.stylua,
formatting.black,
formatting.gofmt,
formatting.goimports,
formatting.shfmt,
},
on_attach = function()
vim.cmd([[
augroup LspFormatting
autocmd! * <buffer>
autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
augroup END
]])
end,
end,
})
-- Other formats that work weird with null_ls
vim.cmd([[autocmd BufWritePre *.svelte lua vim.lsp.buf.formatting_sync(nil, 1000)]])
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = {
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
["<C-space>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.close()
else
cmp.complete()
end
end),
["<TAB>"] = cmp.mapping.confirm({
select = true,
behavior = cmp.SelectBehavior.Insert,
}),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "path" },
{ name = "buffer" },
}),
completion = {
completeopt = "menu,menuone,noselect,noinsert,preview",
},
experimental = {
ghost_text = true,
},
sorting = {
comparators = {
cmp.config.compare.score,
cmp.config.compare.sort_text,
cmp.config.compare.kind,
},
},
documentation = {
border = { "", "", "", "", "", "", "", "" },
zindex = 999,
format = { "markdown" },
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind)
vim_item.menu = ({
buffer = "[Buffer]",
luasnip = "[Snippet]",
nvim_lua = "[Lua]",
path = "[File]",
})[entry.source.name]
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = {
["<C-j>"] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
["<C-k>"] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
["<C-space>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.close()
else
cmp.complete()
end
end),
["<TAB>"] = cmp.mapping.confirm({
select = true,
behavior = cmp.SelectBehavior.Insert,
}),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "luasnip" },
}, {
{ name = "path" },
{ name = "buffer" },
}),
completion = {
completeopt = "menu,menuone,noselect,noinsert,preview",
},
experimental = {
ghost_text = true,
},
sorting = {
comparators = {
cmp.config.compare.score,
cmp.config.compare.sort_text,
cmp.config.compare.kind,
},
},
documentation = {
border = { "", "", "", "", "", "", "", "" },
zindex = 999,
format = { "markdown" },
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = string.format("%s %s", kind_icons[vim_item.kind], vim_item.kind)
vim_item.menu = ({
buffer = "[Buffer]",
luasnip = "[Snippet]",
nvim_lua = "[Lua]",
path = "[File]",
})[entry.source.name]
return vim_item
end,
},
return vim_item
end,
},
})
cmp.setup.cmdline("/", {
sources = {
{ name = "cmdline" },
},
sources = {
{ name = "cmdline" },
},
})
cmp.setup.cmdline(":", {
sources = {
{ name = "cmdline" },
},
sources = {
{ name = "cmdline" },
},
})
local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
@@ -134,47 +134,47 @@ local capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protoco
local lsps_with_disabled_formatting = { "tsserver", "gopls" }
local on_attach = function(client)
if list_includes_item(lsps_with_disabled_formatting, client.name) then
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
end
if list_includes_item(lsps_with_disabled_formatting, client.name) then
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
end
end
lsp_installer.on_server_ready(function(server)
local opts = {
capabilities = capabilities,
on_attach = on_attach,
}
local opts = {
capabilities = capabilities,
on_attach = on_attach,
}
if server.name == "sumneko_lua" then
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init/lua")
if server.name == "sumneko_lua" then
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init/lua")
opts.settings = {
Lua = {
runtime = {
version = "LuaJIT",
path = runtime_path,
},
diagnostics = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
}
end
opts.settings = {
Lua = {
runtime = {
version = "LuaJIT",
path = runtime_path,
},
diagnostics = {
library = vim.api.nvim_get_runtime_file("", true),
},
telemetry = {
enable = false,
},
},
}
end
server:setup(opts)
server:setup(opts)
end)
-- Don't show diagnostics as virtual text
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
update_in_insert = true,
virtual_text = false,
signs = false,
update_in_insert = true,
virtual_text = false,
signs = false,
})
require("luasnip.loaders.from_vscode").load()

View File

@@ -1,46 +1,46 @@
local lualine = require("lualine")
local branch = {
"branch",
icons_enabled = true,
icon = "",
"branch",
icons_enabled = true,
icon = "",
}
local diagnostics = {
"diagnostics",
sections = { "error", "warn" },
symbols = { error = "", warn = "" },
colored = false,
update_in_insert = false,
always_visible = true,
"diagnostics",
sections = { "error", "warn" },
symbols = { error = "", warn = "" },
colored = false,
update_in_insert = false,
always_visible = true,
}
local mode = {
"mode",
"mode",
}
local filetype = {
"filetype",
"filetype",
}
local location = function()
local line, column = unpack(vim.api.nvim_win_get_cursor(0))
local line, column = unpack(vim.api.nvim_win_get_cursor(0))
return "Ln " .. line .. ", Col " .. column
return "Ln " .. line .. ", Col " .. column
end
lualine.setup({
options = {
disabled_filetypes = { "NvimTree" },
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
},
sections = {
lualine_a = { branch, diagnostics },
lualine_b = { mode },
lualine_c = {},
lualine_x = { location },
lualine_y = { "encoding", filetype },
lualine_z = {},
},
options = {
disabled_filetypes = { "NvimTree" },
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
},
sections = {
lualine_a = { branch, diagnostics },
lualine_b = { mode },
lualine_c = {},
lualine_x = { location },
lualine_y = { "encoding", filetype },
lualine_z = {},
},
})

View File

@@ -1,6 +1,6 @@
require("telescope").setup({
defaults = {
sorting_strategy = "ascending",
file_ignore_patterns = { ".git/", "node_modules/" },
},
defaults = {
sorting_strategy = "ascending",
file_ignore_patterns = { ".git/", "node_modules/" },
},
})

View File

@@ -2,13 +2,3 @@ local cmd = vim.cmd
vim.g.tokyonight_style = "night"
cmd([[colorscheme tokyonight]])
cmd([[
hi NvimTreeGitNew guifg=green
hi NvimTreeGitStaged guifg=lightgreen
hi NvimTreeGitDeleted guifg=red
hi NvimTreeGitDirty guifg=lightblue
hi NvimTreeGitMerge guifg=yellow
hi NvimTreeGitIgnored guifg=gray
hi NvimTreeOpenedFolderName gui=italic,bold
]])

View File

@@ -1,9 +1,9 @@
require("nvim-treesitter.configs").setup({
ensure_installed = "maintained",
highlight = {
enable = true,
},
context_commentstring = {
enable = true,
},
ensure_installed = "maintained",
highlight = {
enable = true,
},
context_commentstring = {
enable = true,
},
})

View File

@@ -1,41 +1,41 @@
local M = {}
local function map(mode, shortcut, command, additional_opts)
local opts = { noremap = true, silent = true }
local opts = { noremap = true, silent = true }
if opts then
opts = vim.tbl_extend("force", opts, additional_opts)
end
if opts then
opts = vim.tbl_extend("force", opts, additional_opts)
end
vim.api.nvim_set_keymap(mode, shortcut, command, opts)
vim.api.nvim_set_keymap(mode, shortcut, command, opts)
end
M.nmap = function(shortcut, command, opts)
opts = opts or {}
opts = opts or {}
map("n", shortcut, command, opts)
map("n", shortcut, command, opts)
end
M.vmap = function(shortcut, command, opts)
opts = opts or {}
opts = opts or {}
map("v", shortcut, command, opts)
map("v", shortcut, command, opts)
end
M.tmap = function(shortcut, command, opts)
opts = opts or {}
opts = opts or {}
map("t", shortcut, command, opts)
map("t", shortcut, command, opts)
end
M.list_includes_item = function(list, item)
for _, value in pairs(list) do
if value == item then
return true
end
end
for _, value in pairs(list) do
if value == item then
return true
end
end
return false
return false
end
return M