Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asoderlind committed Aug 9, 2023
1 parent 33ced16 commit 282c398
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 13 deletions.
23 changes: 16 additions & 7 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
local init_modules = {
"core",
"plugins"
"core",
"plugins",
}

for _, module in ipairs(init_modules) do
local ok, err = pcall(require, module)
if not ok then
error("Error loading " .. module .. "\n\n" .. err)
end
if vim.g.vscode then
for _, module in ipairs({ "vscode" }) do
local ok, err = pcall(require, module)
if not ok then
error("Error loading " .. module .. "\n\n" .. err)
end
end
else
for _, module in ipairs(init_modules) do
local ok, err = pcall(require, module)
if not ok then
error("Error loading " .. module .. "\n\n" .. err)
end
end
end
1 change: 0 additions & 1 deletion lua/core/autocmds.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
vim.cmd([[colorscheme gruvbox]])
vim.cmd([[hi Normal guibg=NONE ctermbg=NONE]])
vim.cmd([[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()]])
2 changes: 2 additions & 0 deletions lua/plugins/configs/lspinstaller.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local _, lsp_installer = pcall(require, "nvim-lsp-installer")


local function on_attach(client, bufnr)
-- Avoid conflicts with null_ls
client.server_capabilities.document_formatting = false
Expand Down Expand Up @@ -38,6 +39,7 @@ local function on_attach(client, bufnr)
buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.format()<CR>", opts)
buf_set_keymap("v", "<space>ca", "<cmd>lua vim.lsp.buf.range_code_action()<CR>", opts)

end

-- Register a handler that will be called for all installed servers.
Expand Down
42 changes: 37 additions & 5 deletions lua/plugins/configs/null.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
local _, null_ls = pcall(require, "null-ls")

local augroup = vim.api.nvim_create_augroup("LspFormatting", {})

-- Set LSP auto format on buffer save
local on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
vim.lsp.buf.formatting_sync()
end,
})
end
end

local sources = {
--null_ls.builtins.formatting.prettierd,
null_ls.builtins.formatting.stylua,
null_ls.builtins.formatting.eslint_d,
null_ls.builtins.formatting.autopep8,
null_ls.builtins.formatting.tidy,
null_ls.builtins.formatting.stylua.with({
filetypes = { "lua" },
}),

null_ls.builtins.formatting.autopep8.with({
filetypes = { "python" },
}),

null_ls.builtins.formatting.prettierd.with({
filetypes = { "javascript", "typescript", "json", "markdown", "graphql" },
}),

null_ls.builtins.formatting.tidy.with({
filetypes = { "html" },
}),

null_ls.builtins.formatting.djlint.with({
filetypes = { "django", "htmldjango", "jinja.html" },
}),
}

null_ls.setup({ sources = sources })
null_ls.setup({ sources = sources, on_attach = on_attach })
10 changes: 10 additions & 0 deletions lua/vscode/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local core_modules = {
"vscode.mappings",
}

for _, module in ipairs(core_modules) do
local ok, err = pcall(require, module)
if not ok then
error("Error loading " .. module .. "\n\n" .. err)
end
end
6 changes: 6 additions & 0 deletions lua/vscode/mappings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
vim.g.mapleader = ","
local map = vim.api.nvim_set_keymap

-- custom escape
map("i", "jk", "<ESC>", { noremap = true, silent = true })
map("i", "kj", "<ESC>", { noremap = true, silent = true })

0 comments on commit 282c398

Please sign in to comment.