Added stylua and reformated lua files

This commit is contained in:
Salar Rahmanian 2021-07-15 08:19:22 -07:00
parent c1cd430cae
commit c11d9351a6
4 changed files with 224 additions and 197 deletions

7
.stylua.toml Normal file
View file

@ -0,0 +1,7 @@
column_width = 160
line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
no_call_parentheses = true

View file

@ -221,6 +221,7 @@
pkgs.ripgrep pkgs.ripgrep
pkgs.rnix-lsp pkgs.rnix-lsp
pkgs.shellcheck pkgs.shellcheck
pkgs.stylua
pkgs.sumneko-lua-language-server pkgs.sumneko-lua-language-server
pkgs.tealdeer pkgs.tealdeer
pkgs.tig pkgs.tig

View file

@ -1,11 +1,9 @@
local execute = vim.api.nvim_command local execute = vim.api.nvim_command
local fn = vim.fn local fn = vim.fn
local install_path = fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
local function load_plugins() local function load_plugins()
local use = require('packer').use local use = require('packer').use
require('packer').startup(function() require('packer').startup(function()
use 'wbthomason/packer.nvim' -- Package manager use 'wbthomason/packer.nvim' -- Package manager
@ -16,7 +14,13 @@ local function load_plugins()
use 'folke/tokyonight.nvim' -- Theme use 'folke/tokyonight.nvim' -- Theme
use 'windwp/nvim-autopairs' -- Autopairs use 'windwp/nvim-autopairs' -- Autopairs
use 'kyazdani42/nvim-tree.lua' -- File explorer use 'kyazdani42/nvim-tree.lua' -- File explorer
use { 'glepnir/galaxyline.nvim', config = function() require'salargalaxyline' end, requires = 'kyazdani42/nvim-web-devicons' } use {
'glepnir/galaxyline.nvim',
config = function()
require 'salargalaxyline'
end,
requires = 'kyazdani42/nvim-web-devicons',
}
use 'lukas-reineke/indent-blankline.nvim' use 'lukas-reineke/indent-blankline.nvim'
use { 'lewis6991/gitsigns.nvim', requires = 'nvim-lua/plenary.nvim' } use { 'lewis6991/gitsigns.nvim', requires = 'nvim-lua/plenary.nvim' }
use { 'TimUntersberger/neogit', requires = { { 'nvim-lua/plenary.nvim' }, { 'sindrets/diffview.nvim' } } } use { 'TimUntersberger/neogit', requires = { { 'nvim-lua/plenary.nvim' }, { 'sindrets/diffview.nvim' } } }
@ -30,27 +34,26 @@ local function load_plugins()
use { 'folke/trouble.nvim', requires = 'kyazdani42/nvim-web-devicons' } use { 'folke/trouble.nvim', requires = 'kyazdani42/nvim-web-devicons' }
use 'nvim-treesitter/playground' use 'nvim-treesitter/playground'
use 'b3nj5m1n/kommentary' use 'b3nj5m1n/kommentary'
use 'ckipp01/stylua-nvim'
end) end)
end end
_G.load_config = function() _G.load_config = function()
require('nvim-autopairs').setup() require('nvim-autopairs').setup()
require('which-key').setup() require('which-key').setup()
require('trouble').setup() require('trouble').setup()
require('gitsigns').setup() require('gitsigns').setup()
require("salargalaxyline") require 'salargalaxyline'
require('kommentary.config').use_extended_mappings() require('kommentary.config').use_extended_mappings()
-- Treesitter -- Treesitter
require('nvim-treesitter.configs').setup { require('nvim-treesitter.configs').setup {
query_linter = { query_linter = {
enable = true, enable = true,
use_virtual_text = true, use_virtual_text = true,
lint_events = { "BufWrite", "CursorHold" }, lint_events = { 'BufWrite', 'CursorHold' },
}, },
ensure_installed = "maintained", ensure_installed = 'maintained',
highlight = { enable = true }, highlight = { enable = true },
incremental_selection = { incremental_selection = {
enable = true, enable = true,
@ -114,18 +117,18 @@ _G.load_config = function()
goto_node = '<cr>', goto_node = '<cr>',
show_help = '?', show_help = '?',
}, },
} },
} }
-- neogit -- neogit
require('neogit').setup({ require('neogit').setup {
integrations = { integrations = {
diffview = true diffview = true,
},
} }
})
--Incremental live completion --Incremental live completion
vim.o.inccommand = "nosplit" vim.o.inccommand = 'nosplit'
--Set highlight on search --Set highlight on search
vim.o.hlsearch = false vim.o.hlsearch = false
@ -138,7 +141,7 @@ _G.load_config = function()
vim.o.hidden = true vim.o.hidden = true
--Enable mouse mode --Enable mouse mode
vim.o.mouse = "a" vim.o.mouse = 'a'
-- clipboard -- clipboard
vim.o.clipboard = 'unnamedplus' vim.o.clipboard = 'unnamedplus'
@ -155,19 +158,18 @@ _G.load_config = function()
--Decrease update time --Decrease update time
vim.o.updatetime = 250 vim.o.updatetime = 250
vim.wo.signcolumn="yes" vim.wo.signcolumn = 'yes'
--Set colorscheme (order is important here) --Set colorscheme (order is important here)
vim.g.tokyonight_style = "night" vim.g.tokyonight_style = 'night'
vim.g.tokyonight_italic_functions = true vim.g.tokyonight_italic_functions = true
vim.o.termguicolors = true vim.o.termguicolors = true
vim.cmd [[colorscheme tokyonight]] vim.cmd [[colorscheme tokyonight]]
--Remap space as leader key --Remap space as leader key
vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent = true }) vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent = true })
vim.g.mapleader = " " vim.g.mapleader = ' '
vim.g.maplocalleader = " " vim.g.maplocalleader = ' '
--Remap for dealing with word wrap --Remap for dealing with word wrap
vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap = true, expr = true, silent = true }) vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap = true, expr = true, silent = true })
@ -177,10 +179,10 @@ _G.load_config = function()
vim.api.nvim_set_keymap('t', '<Esc>', [[<c-\><c-n>]], { noremap = true }) vim.api.nvim_set_keymap('t', '<Esc>', [[<c-\><c-n>]], { noremap = true })
--Add map to enter paste mode --Add map to enter paste mode
vim.o.pastetoggle="<F3>" vim.o.pastetoggle = '<F3>'
--Map blankline --Map blankline
vim.g.indent_blankline_char = "" vim.g.indent_blankline_char = ''
vim.g.indent_blankline_filetype_exclude = { 'help', 'packer' } vim.g.indent_blankline_filetype_exclude = { 'help', 'packer' }
vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile' } vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile' }
vim.g.indent_blankline_char_highlight = 'LineNr' vim.g.indent_blankline_char_highlight = 'LineNr'
@ -192,13 +194,13 @@ _G.load_config = function()
vim.wo.signcolumn = 'no' vim.wo.signcolumn = 'no'
vim.o.mouse = 'v' vim.o.mouse = 'v'
vim.wo.number = false vim.wo.number = false
print("Mouse disabled") print 'Mouse disabled'
else else
vim.cmd [[IndentBlanklineEnable]] vim.cmd [[IndentBlanklineEnable]]
vim.wo.signcolumn = 'yes' vim.wo.signcolumn = 'yes'
vim.o.mouse = 'a' vim.o.mouse = 'a'
vim.wo.number = true vim.wo.number = true
print("Mouse enabled") print 'Mouse enabled'
end end
end end
@ -209,13 +211,13 @@ _G.load_config = function()
defaults = { defaults = {
mappings = { mappings = {
i = { i = {
["<C-u>"] = false, ['<C-u>'] = false,
["<C-d>"] = false, ['<C-d>'] = false,
}, },
}, },
generic_sorter = require'telescope.sorters'.get_fzy_sorter, generic_sorter = require('telescope.sorters').get_fzy_sorter,
file_sorter = require'telescope.sorters'.get_fzy_sorter, file_sorter = require('telescope.sorters').get_fzy_sorter,
} },
} }
--Add leader shortcuts --Add leader shortcuts
vim.api.nvim_set_keymap('n', '<leader>f', [[<cmd>lua require('telescope.builtin').find_files()<cr>]], { noremap = true, silent = true }) vim.api.nvim_set_keymap('n', '<leader>f', [[<cmd>lua require('telescope.builtin').find_files()<cr>]], { noremap = true, silent = true })
@ -238,18 +240,21 @@ _G.load_config = function()
vim.g.splitbelow = true vim.g.splitbelow = true
-- Highlight on yank -- Highlight on yank
vim.api.nvim_exec([[ vim.api.nvim_exec(
[[
augroup YankHighlight augroup YankHighlight
autocmd! autocmd!
autocmd TextYankPost * silent! lua vim.highlight.on_yank() autocmd TextYankPost * silent! lua vim.highlight.on_yank()
augroup end augroup end
]], false) ]],
false
)
-- Y yank until the end of line -- Y yank until the end of line
vim.api.nvim_set_keymap('n', 'Y', 'y$', { noremap = true }) vim.api.nvim_set_keymap('n', 'Y', 'y$', { noremap = true })
-- --
-- LSP settings -- LSP settings
local nvim_lsp = require('lspconfig') local nvim_lsp = require 'lspconfig'
local on_attach = function(_client, bufnr) local on_attach = function(_client, bufnr)
require('lsp_signature').on_attach() require('lsp_signature').on_attach()
@ -281,13 +286,20 @@ _G.load_config = function()
end end
-- lua language server -- lua language server
local sumneko_binary = vim.fn.getenv("HOME").."/.nix-profile/bin/lua-language-server" local sumneko_binary = vim.fn.getenv 'HOME' .. '/.nix-profile/bin/lua-language-server'
local runtime_path = vim.split(package.path, ';') local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, 'lua/?.lua') table.insert(runtime_path, 'lua/?.lua')
table.insert(runtime_path, 'lua/?/init.lua') table.insert(runtime_path, 'lua/?/init.lua')
require('lspconfig').sumneko_lua.setup { require('lspconfig').sumneko_lua.setup {
cmd = { sumneko_binary }, cmd = { sumneko_binary },
commands = {
Format = {
function()
require('stylua-nvim').format_file()
end,
},
},
on_attach = on_attach, on_attach = on_attach,
settings = { settings = {
Lua = { Lua = {
@ -313,47 +325,46 @@ require('lspconfig').sumneko_lua.setup {
}, },
} }
-- metals -- metals
vim.opt_global.shortmess:remove("F"):append("c") vim.opt_global.shortmess:remove('F'):append 'c'
metals_config = require("metals").bare_config metals_config = require('metals').bare_config
metals_config.init_options.statusBarProvider = "on" metals_config.init_options.statusBarProvider = 'on'
vim.cmd [[augroup lsp]] vim.cmd [[augroup lsp]]
vim.cmd [[au!]] vim.cmd [[au!]]
vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]] vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]]
vim.cmd [[augroup end]] vim.cmd [[augroup end]]
-- Map :Format to vim.lsp.buf.formatting() -- Map :Format to vim.lsp.buf.formatting()
vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]) vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
-- Set completeopt to have a better completion experience -- Set completeopt to have a better completion experience
vim.o.completeopt="menuone,noinsert" vim.o.completeopt = 'menuone,noinsert'
-- Compe setup -- Compe setup
require'compe'.setup { require('compe').setup {
enabled = true; enabled = true,
autocomplete = true; autocomplete = true,
debug = false; debug = false,
min_length = 1; min_length = 1,
preselect = 'enable'; preselect = 'enable',
throttle_time = 80; throttle_time = 80,
source_timeout = 200; source_timeout = 200,
incomplete_delay = 400; incomplete_delay = 400,
max_abbr_width = 100; max_abbr_width = 100,
max_kind_width = 100; max_kind_width = 100,
max_menu_width = 100; max_menu_width = 100,
documentation = true; documentation = true,
source = { source = {
path = true; path = true,
nvim_lsp = { nvim_lsp = {
priority = 1000, priority = 1000,
filetypes = { "scala", "sbt", "java" }, filetypes = { 'scala', 'sbt', 'java' },
}, },
nvim_lua = true, nvim_lua = true,
buffer = true, buffer = true,
luasnip = true, luasnip = true,
}; },
} }
local t = function(str) local t = function(str)
@ -361,8 +372,8 @@ require('lspconfig').sumneko_lua.setup {
end end
local check_back_space = function() local check_back_space = function()
local col = vim.fn.col('.') - 1 local col = vim.fn.col '.' - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then if col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' then
return true return true
else else
return false return false
@ -374,30 +385,29 @@ require('lspconfig').sumneko_lua.setup {
--- jump to prev/next snippet's placeholder --- jump to prev/next snippet's placeholder
_G.tab_complete = function() _G.tab_complete = function()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 then
return t "<C-n>" return t '<C-n>'
elseif check_back_space() then elseif check_back_space() then
return t "<Tab>" return t '<Tab>'
else else
return vim.fn['compe#complete']() return vim.fn['compe#complete']()
end end
end end
_G.s_tab_complete = function() _G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 then
return t "<C-p>" return t '<C-p>'
else else
return t "<S-Tab>" return t '<S-Tab>'
end end
end end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true}) vim.api.nvim_set_keymap('i', '<Tab>', 'v:lua.tab_complete()', { expr = true })
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true}) vim.api.nvim_set_keymap('s', '<Tab>', 'v:lua.tab_complete()', { expr = true })
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) vim.api.nvim_set_keymap('i', '<S-Tab>', 'v:lua.s_tab_complete()', { expr = true })
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true}) vim.api.nvim_set_keymap('s', '<S-Tab>', 'v:lua.s_tab_complete()', { expr = true })
end end
if fn.isdirectory(install_path) == 0 then if fn.isdirectory(install_path) == 0 then
fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path}) fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path }
load_plugins() load_plugins()
require('packer').sync() require('packer').sync()
vim.cmd 'autocmd User PackerComplete ++once lua load_config()' vim.cmd 'autocmd User PackerComplete ++once lua load_config()'

View file

@ -1,4 +1,4 @@
local gl = require('galaxyline') local gl = require 'galaxyline'
local gls = gl.section local gls = gl.section
gl.short_line_list = { 'LuaTree', 'vista', 'dbui' } gl.short_line_list = { 'LuaTree', 'vista', 'dbui' }
@ -13,11 +13,11 @@ local colors = {
magenta = '#d16d9e', magenta = '#d16d9e',
grey = '#c0c0c0', grey = '#c0c0c0',
blue = '#0087d7', blue = '#0087d7',
red = '#ec5f67' red = '#ec5f67',
} }
local buffer_not_empty = function() local buffer_not_empty = function()
if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then if vim.fn.empty(vim.fn.expand '%:t') ~= 1 then
return true return true
end end
return false return false
@ -25,8 +25,10 @@ end
gls.left[1] = { gls.left[1] = {
FirstElement = { FirstElement = {
provider = function() return '' end, provider = function()
highlight = {colors.blue,colors.yellow} return ''
end,
highlight = { colors.blue, colors.yellow },
}, },
} }
gls.left[2] = { gls.left[2] = {
@ -36,12 +38,15 @@ gls.left[2] = {
return alias[vim.fn.mode()] return alias[vim.fn.mode()]
end, end,
separator = '', separator = '',
separator_highlight = {colors.purple,function() separator_highlight = {
colors.purple,
function()
if not buffer_not_empty() then if not buffer_not_empty() then
return colors.purple return colors.purple
end end
return colors.darkblue return colors.darkblue
end}, end,
},
highlight = { colors.darkblue, colors.purple, 'bold' }, highlight = { colors.darkblue, colors.purple, 'bold' },
}, },
} }
@ -58,23 +63,25 @@ gls.left[4] = {
condition = buffer_not_empty, condition = buffer_not_empty,
separator = '', separator = '',
separator_highlight = { colors.purple, colors.darkblue }, separator_highlight = { colors.purple, colors.darkblue },
highlight = {colors.magenta,colors.darkblue} highlight = { colors.magenta, colors.darkblue },
} },
} }
gls.left[5] = { gls.left[5] = {
GitIcon = { GitIcon = {
provider = function() return '' end, provider = function()
return ''
end,
condition = buffer_not_empty, condition = buffer_not_empty,
highlight = { colors.orange, colors.purple }, highlight = { colors.orange, colors.purple },
} },
} }
gls.left[6] = { gls.left[6] = {
GitBranch = { GitBranch = {
provider = 'GitBranch', provider = 'GitBranch',
condition = buffer_not_empty, condition = buffer_not_empty,
highlight = { colors.grey, colors.purple }, highlight = { colors.grey, colors.purple },
} },
} }
local checkwidth = function() local checkwidth = function()
@ -91,7 +98,7 @@ gls.left[7] = {
condition = checkwidth, condition = checkwidth,
icon = '', icon = '',
highlight = { colors.green, colors.purple }, highlight = { colors.green, colors.purple },
} },
} }
gls.left[8] = { gls.left[8] = {
DiffModified = { DiffModified = {
@ -99,7 +106,7 @@ gls.left[8] = {
condition = checkwidth, condition = checkwidth,
icon = '', icon = '',
highlight = { colors.orange, colors.purple }, highlight = { colors.orange, colors.purple },
} },
} }
gls.left[9] = { gls.left[9] = {
DiffRemove = { DiffRemove = {
@ -107,34 +114,38 @@ gls.left[9] = {
condition = checkwidth, condition = checkwidth,
icon = '', icon = '',
highlight = { colors.red, colors.purple }, highlight = { colors.red, colors.purple },
} },
} }
gls.left[10] = { gls.left[10] = {
LeftEnd = { LeftEnd = {
provider = function() return '' end, provider = function()
return ''
end,
separator = '', separator = '',
separator_highlight = { colors.purple, colors.bg }, separator_highlight = { colors.purple, colors.bg },
highlight = {colors.purple,colors.purple} highlight = { colors.purple, colors.purple },
} },
} }
gls.left[11] = { gls.left[11] = {
DiagnosticError = { DiagnosticError = {
provider = 'DiagnosticError', provider = 'DiagnosticError',
icon = '', icon = '',
highlight = {colors.red,colors.bg} highlight = { colors.red, colors.bg },
} },
} }
gls.left[12] = { gls.left[12] = {
Space = { Space = {
provider = function () return ' ' end provider = function()
} return ' '
end,
},
} }
gls.left[13] = { gls.left[13] = {
DiagnosticWarn = { DiagnosticWarn = {
provider = 'DiagnosticWarn', provider = 'DiagnosticWarn',
icon = '', icon = '',
highlight = { colors.blue, colors.bg }, highlight = { colors.blue, colors.bg },
} },
} }
gls.right[1] = { gls.right[1] = {
FileFormat = { FileFormat = {
@ -142,7 +153,7 @@ gls.right[1]= {
separator = '', separator = '',
separator_highlight = { colors.bg, colors.purple }, separator_highlight = { colors.bg, colors.purple },
highlight = { colors.grey, colors.purple }, highlight = { colors.grey, colors.purple },
} },
} }
gls.right[2] = { gls.right[2] = {
LineInfo = { LineInfo = {
@ -158,13 +169,13 @@ gls.right[3] = {
separator = '', separator = '',
separator_highlight = { colors.darkblue, colors.purple }, separator_highlight = { colors.darkblue, colors.purple },
highlight = { colors.grey, colors.darkblue }, highlight = { colors.grey, colors.darkblue },
} },
} }
gls.right[4] = { gls.right[4] = {
ScrollBar = { ScrollBar = {
provider = 'ScrollBar', provider = 'ScrollBar',
highlight = { colors.yellow, colors.purple }, highlight = { colors.yellow, colors.purple },
} },
} }
gls.short_line_left[1] = { gls.short_line_left[1] = {
@ -172,17 +183,15 @@ gls.short_line_left[1] = {
provider = 'FileTypeName', provider = 'FileTypeName',
separator = '', separator = '',
separator_highlight = { colors.purple, colors.bg }, separator_highlight = { colors.purple, colors.bg },
highlight = {colors.grey,colors.purple} highlight = { colors.grey, colors.purple },
},
} }
}
gls.short_line_right[1] = { gls.short_line_right[1] = {
BufferIcon = { BufferIcon = {
provider = 'BufferIcon', provider = 'BufferIcon',
separator = '', separator = '',
separator_highlight = { colors.purple, colors.bg }, separator_highlight = { colors.purple, colors.bg },
highlight = {colors.grey,colors.purple} highlight = { colors.grey, colors.purple },
},
} }
}