feat: make more robust
This commit is contained in:
parent
c40c6dbeef
commit
0ea2c241dc
@ -1,5 +1,3 @@
|
||||
local u = require("utils")
|
||||
|
||||
local o = vim.o
|
||||
local opt = vim.opt
|
||||
local wo = vim.wo
|
||||
@ -7,6 +5,33 @@ local bo = vim.bo
|
||||
local g = vim.g
|
||||
local fn = vim.fn
|
||||
|
||||
require("install-paq")
|
||||
require("paq"):setup({verbose=true}) {
|
||||
"savq/paq-nvim", -- Let Paq manage itself
|
||||
-- Theming Plugins
|
||||
{url="git@github.com:kaicataldo/material.vim", branch = "main"},
|
||||
{url="git@github.com:ryanoasis/vim-devicons"},
|
||||
-- Layout Plugins
|
||||
{url="git@github.com:preservim/nerdtree"},
|
||||
{url="git@github.com:hoob3rt/lualine.nvim"},
|
||||
-- Code Navigation
|
||||
{url="git@github.com:nvim-lua/popup.nvim"},
|
||||
{url="git@github.com:nvim-lua/plenary.nvim"},
|
||||
{url="git@github.com:nvim-telescope/telescope.nvim"},
|
||||
-- Syntax / Autocomplete
|
||||
{url="git@github.com:neovim/nvim-lspconfig"},
|
||||
{url="git@github.com:nvim-lua/lsp-status.nvim"},
|
||||
{url="git@github.com:hrsh7th/nvim-compe"},
|
||||
{url="git@github.com:nvim-treesitter/nvim-treesitter", run = ":TSUpdate"},
|
||||
-- Formatting
|
||||
{url="git@github.com:mhartington/formatter.nvim"},
|
||||
-- Git Interface
|
||||
{url="git@github.com:akinsho/nvim-toggleterm.lua"}
|
||||
}
|
||||
|
||||
local u = require("utils")
|
||||
|
||||
|
||||
-- Global options
|
||||
o.number = true
|
||||
o.tabstop = 2
|
||||
@ -25,55 +50,40 @@ g.NERDTreeMinimalUI = true
|
||||
g.NERDTreeDirArrows = true
|
||||
g.hidden = true
|
||||
g.material_theme_style = "ocean_community"
|
||||
vim.cmd [[colorscheme material]]
|
||||
if u.has_plugin("material")
|
||||
vim.cmd [[colorscheme material]]
|
||||
end
|
||||
-- Remove background color
|
||||
vim.cmd [[highlight Normal guibg=none]]
|
||||
vim.cmd [[highlight NonText guibg=none]]
|
||||
|
||||
-- KeyBindings
|
||||
g.mapleader = " "
|
||||
require "keymappings"
|
||||
|
||||
-- Remove background color
|
||||
vim.cmd [[highlight Normal guibg=none]]
|
||||
vim.cmd [[highlight NonText guibg=none]]
|
||||
|
||||
require "paq" {
|
||||
"savq/paq-nvim", -- Let Paq manage itself
|
||||
-- Theming Plugins
|
||||
{"kaicataldo/material.vim", branch = "main"},
|
||||
"ryanoasis/vim-devicons",
|
||||
-- Layout Plugins
|
||||
"preservim/nerdtree",
|
||||
"hoob3rt/lualine.nvim",
|
||||
-- Code Navigation
|
||||
"nvim-lua/popup.nvim",
|
||||
"nvim-lua/plenary.nvim",
|
||||
"nvim-telescope/telescope.nvim",
|
||||
-- Syntax / Autocomplete
|
||||
"neovim/nvim-lspconfig",
|
||||
"nvim-lua/lsp-status.nvim",
|
||||
"hrsh7th/nvim-compe",
|
||||
{"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"},
|
||||
-- Formatting
|
||||
"mhartington/formatter.nvim",
|
||||
-- Git Interface
|
||||
"akinsho/nvim-toggleterm.lua"
|
||||
}
|
||||
|
||||
require "nvim-treesitter.configs".setup {ensure_installed = "maintained", highlight = {enable = true}}
|
||||
|
||||
-- Treesitter config
|
||||
if u.has_plugin("nvim-treesitter")
|
||||
require "nvim-treesitter.configs".setup {ensure_installed = "maintained", highlight = {enable = true}}
|
||||
end
|
||||
-- Toggleterm / Lazygit setup
|
||||
require "lazy-git"
|
||||
|
||||
if u.has_plugin("toggleterm")
|
||||
require "lazy-git"
|
||||
end
|
||||
-- Autocommands
|
||||
u.create_augroup(
|
||||
if u.has_plugin("NERDTree")
|
||||
u.create_augroup(
|
||||
{
|
||||
{"VimEnter", "*", "if (@% == '') | NERDTree | endif"},
|
||||
{"BufEnter", "*", 'if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif'}
|
||||
},
|
||||
"Nerdtree"
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
-- Autocompletion Setup
|
||||
require "autocomplete"
|
||||
if u.has_plugin("compe")
|
||||
require "autocomplete"
|
||||
end
|
||||
|
||||
-- LSP Config
|
||||
local lsp_utils = require "lsp-utils"
|
||||
|
7
configs/lua/install-paq.lua
Normal file
7
configs/lua/install-paq.lua
Normal file
@ -0,0 +1,7 @@
|
||||
local fn = vim.fn
|
||||
|
||||
local install_path = fn.stdpath('data') .. '/site/pack/paqs/start/paq-nvim'
|
||||
|
||||
if fn.empty(fn.glob(install_path)) > 0 then
|
||||
fn.system({'git', 'clone', '--depth=1', 'https://github.com/savq/paq-nvim.git', install_path})
|
||||
end
|
@ -150,155 +150,3 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
||||
update_in_insert = true
|
||||
}
|
||||
)
|
||||
local lsp_status = require("lsp-status")
|
||||
|
||||
-- function to attach completion when setting up lsp
|
||||
local function on_attach(client)
|
||||
local function buf_set_keymap(...)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
||||
end
|
||||
local function buf_set_option(...)
|
||||
vim.api.nvim_buf_set_option(bufnr, ...)
|
||||
end
|
||||
|
||||
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
|
||||
|
||||
-- Mappings.
|
||||
local opts = {noremap = true, silent = true}
|
||||
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
||||
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
|
||||
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||
buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
|
||||
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
|
||||
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
|
||||
|
||||
-- Set some keybinds conditional on server capabilities
|
||||
if client.resolved_capabilities.document_formatting then
|
||||
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
||||
elseif client.resolved_capabilities.document_range_formatting then
|
||||
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
||||
end
|
||||
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
" autocmd CursorHold *.* :lua vim.lsp.diagnostic.show_line_diagnostics()
|
||||
autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 300)
|
||||
augroup END
|
||||
]],
|
||||
false
|
||||
)
|
||||
end
|
||||
end
|
||||
-- Use a loop to conveniently both setup defined servers
|
||||
-- and map buffer local keybindings when the language server attaches
|
||||
local servers = {
|
||||
"tsserver",
|
||||
"svelte"
|
||||
}
|
||||
for _, lsp in ipairs(servers) do
|
||||
nvim_lsp[lsp].setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = lsp_status.capabilities
|
||||
}
|
||||
end
|
||||
|
||||
-- Setup diagnostics formaters and linters for non LSP provided files
|
||||
nvim_lsp.diagnosticls.setup {
|
||||
on_attach = on_attach,
|
||||
capabilities = lsp_status.capabilities,
|
||||
cmd = {"diagnostic-languageserver", "--stdio"},
|
||||
filetypes = {
|
||||
"lua",
|
||||
"sh",
|
||||
"markdown",
|
||||
"json",
|
||||
"yaml",
|
||||
"toml"
|
||||
},
|
||||
init_options = {
|
||||
linters = {
|
||||
shellcheck = {
|
||||
command = "shellcheck",
|
||||
debounce = 100,
|
||||
args = {"--format", "json", "-"},
|
||||
sourceName = "shellcheck",
|
||||
parseJson = {
|
||||
line = "line",
|
||||
column = "column",
|
||||
endLine = "endLine",
|
||||
endColumn = "endColumn",
|
||||
message = "${message} [${code}]",
|
||||
security = "level"
|
||||
},
|
||||
securities = {
|
||||
error = "error",
|
||||
warning = "warning",
|
||||
info = "info",
|
||||
style = "hint"
|
||||
}
|
||||
},
|
||||
markdownlint = {
|
||||
command = "markdownlint",
|
||||
isStderr = true,
|
||||
debounce = 100,
|
||||
args = {"--stdin"},
|
||||
offsetLine = 0,
|
||||
offsetColumn = 0,
|
||||
sourceName = "markdownlint",
|
||||
formatLines = 1,
|
||||
formatPattern = {
|
||||
"^.*?:\\s?(\\d+)(:(\\d+)?)?\\s(MD\\d{3}\\/[A-Za-z0-9-/]+)\\s(.*)$",
|
||||
{
|
||||
line = 1,
|
||||
column = 3,
|
||||
message = {4}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
filetypes = {
|
||||
sh = "shellcheck",
|
||||
markdown = "markdownlint"
|
||||
},
|
||||
formatters = {
|
||||
shfmt = {
|
||||
command = "shfmt",
|
||||
args = {"-i", "2", "-bn", "-ci", "-sr"}
|
||||
},
|
||||
prettier = {
|
||||
command = "prettier",
|
||||
args = {"--stdin-filepath", "%filepath"}
|
||||
}
|
||||
},
|
||||
formatFiletypes = {
|
||||
sh = "shfmt",
|
||||
json = "prettier",
|
||||
yaml = "prettier",
|
||||
toml = "prettier",
|
||||
markdown = "prettier",
|
||||
lua = "prettier"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-- Enable diagnostics
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
||||
vim.lsp.with(
|
||||
vim.lsp.diagnostic.on_publish_diagnostics,
|
||||
{
|
||||
underline = true,
|
||||
virtual_text = false,
|
||||
signs = true,
|
||||
update_in_insert = true
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -10,4 +10,22 @@ function M.create_augroup(autocmds, name)
|
||||
cmd('augroup END')
|
||||
end
|
||||
|
||||
local function dump(o)
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
else
|
||||
return tostring(o)
|
||||
end
|
||||
end
|
||||
|
||||
function M.has_plugin(pluginName)
|
||||
local rtp = vim.api.nvim_eval('&rtp')
|
||||
return rtp:match(pluginName)
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
Reference in New Issue
Block a user