This commit is contained in:
sankalp committed 2024-08-22 07:38:23 +05:45
1 parent a13ea6d3a9
commit 6224efd4a8
30 files changed
+2144 -3784

No files matched your search

-76
View File
@@ -1,76 +0,0 @@
-- Header
local function header()
local banner_small = {
' ',
' ',
' ',
' ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ',
' ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ',
' ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ',
' ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ',
' ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ',
' ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ',
' ',
' With experience comes perspective ',
}
return banner_small
end
-- Footer
local function footer()
local version = vim.version()
local print_version = 'v' .. version.major .. '.' .. version.minor .. '.' .. version.patch
local stats = require('lazy').stats()
local plugins_count = stats.loaded .. '/' .. stats.count
local ms = math.floor(stats.startuptime + 0.5)
local time = vim.fn.strftime('%H:%M:%S')
local date = vim.fn.strftime('%d.%m.%Y')
local line1 = '' .. plugins_count .. ' plugins loaded in ' .. ms .. 'ms'
local line2 = '󰃭 ' .. date .. '' .. time
local line3 = '' .. print_version
-- Calculate padding for centering lines
local line1_width = vim.fn.strdisplaywidth(line1)
local line2_padding = math.max(0, math.floor((line1_width - vim.fn.strdisplaywidth(line2)) / 2))
local line3_padding = math.max(0, math.floor((line1_width - vim.fn.strdisplaywidth(line3)) / 2))
-- Apply padding to lines
line2 = string.rep(' ', line2_padding) .. line2
line3 = string.rep(' ', line3_padding) .. line3
return {
' ',
line1,
line2,
line3,
}
end
local alpha = require('alpha')
local dashboard = require('alpha.themes.dashboard')
dashboard.section.header.val = header()
dashboard.section.footer.val = footer()
-- Menu
-- TODO: Add projects and Frecency?
dashboard.section.buttons.val = {
dashboard.button('e', ' New file', ':ene <BAR> startinsert<CR>'),
dashboard.button('f', ' Find files', '<cmd>Telescope find_files<CR>'),
dashboard.button('t', '󰊄 Find text', '<cmd>Telescope live_grep<CR>'),
dashboard.button('F', ' File browser', '<cmd>Telescope file_browser<CR>'),
dashboard.button('r', '󰔠 Recent files', '<cmd>Telescope oldfiles<CR>'),
dashboard.button('s', ' Open last session', ':lua require("persistence").load({ last = true })<CR>'),
dashboard.button('c', ' Config', '<cmd>e $MYVIMRC<CR>'),
dashboard.button('l', ' Plugins', '<cmd>Lazy<CR>'),
dashboard.button('q', ' Quit', '<cmd>qa<CR>'),
}
alpha.setup(dashboard.config)
-- Update the footer after all plugins are fully loaded
vim.api.nvim_create_autocmd('User', {
pattern = 'LazyVimStarted',
callback = function()
dashboard.section.footer.val = footer()
pcall(vim.cmd, 'AlphaRedraw')
end,
})
+73
View File
@@ -0,0 +1,73 @@
local dashboard = require("dashboard")
local icons = require("lib.icons")
dashboard.setup({
theme = "hyper",
disable_move = false,
shortcut_type = "letter",
change_to_vcs_root = true,
hide = {
statusline = true,
tabline = false,
winbar = false,
},
config = {
week_header = {
enable = true,
append = { "", icons.ui.Circle .. " Learn, Make, Explore! " .. icons.ui.Circle },
},
packages = { enable = true },
project = { enable = true, limit = 8 },
mru = { limit = 8 },
shortcut = {
{
desc = icons.ui.Package .. "Mason",
group = "@property",
action = "Mason",
key = "m",
},
{
desc = icons.ui.Sleep .. "Lazy",
group = "@property",
action = "Lazy",
key = "l",
},
{
desc = icons.documents.OpenFolder .. "Files",
group = "Label",
action = "Telescope find_files",
key = "f",
},
{
desc = icons.ui.Search .. "Search",
group = "Label",
action = "Telescope live_grep",
key = "g",
},
{
desc = icons.ui.Note .. "Todo",
group = "Label",
action = "Tdo",
key = "d",
},
{
desc = icons.ui.Power,
group = "Action",
action = "quit",
key = "q",
},
},
footer = { "", icons.ui.Heart .. " Happiness is a state of mind. " .. icons.ui.Heart },
},
})
-- Show dashboard when lazy closes
if vim.o.filetype == "lazy" then
vim.cmd.close()
vim.api.nvim_create_autocmd("User", {
pattern = "DashboardLoaded",
callback = function()
require("lazy").show()
end,
})
end
+104 -116
View File
@@ -1,172 +1,160 @@
local lspconfig = require('lspconfig')
local lspconfig = require("lspconfig")
-- import cmp-nvim-lsp plugin
local cmp_nvim_lsp = require('cmp_nvim_lsp')
local cmp_nvim_lsp = require("cmp_nvim_lsp")
local keymap = vim.keymap -- for conciseness
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf, silent = true }
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf, silent = true }
-- set keybinds
opts.desc = 'Show LSP references'
keymap.set('n', 'lR', '<cmd>Telescope lsp_references<CR>', opts) -- show definition, references
-- set keybinds
opts.desc = "Show LSP references"
keymap.set("n", "lR", "<cmd>Telescope lsp_references<CR>", opts) -- show definition, references
opts.desc = 'Go to declaration'
keymap.set('n', 'lD', vim.lsp.buf.declaration, opts) -- go to declaration
opts.desc = "Go to declaration"
keymap.set("n", "lD", vim.lsp.buf.declaration, opts) -- go to declaration
opts.desc = 'Show LSP definitions'
keymap.set('n', 'ld', '<cmd>Telescope lsp_definitions<CR>', opts) -- show lsp definitions
opts.desc = "Show LSP definitions"
keymap.set("n", "ld", "<cmd>Telescope lsp_definitions<CR>", opts) -- show lsp definitions
opts.desc = 'Show LSP implementations'
keymap.set('n', 'li', '<cmd>Telescope lsp_implementations<CR>', opts) -- show lsp implementations
opts.desc = "Show LSP implementations"
keymap.set("n", "li", "<cmd>Telescope lsp_implementations<CR>", opts) -- show lsp implementations
opts.desc = 'Show LSP type definitions'
keymap.set('n', 'lt', '<cmd>Telescope lsp_type_definitions<CR>', opts) -- show lsp type definitions
opts.desc = "Show LSP type definitions"
keymap.set("n", "lt", "<cmd>Telescope lsp_type_definitions<CR>", opts) -- show lsp type definitions
opts.desc = 'See available code actions'
keymap.set({ 'n', 'v' }, '<leader>la', vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
opts.desc = "See available code actions"
keymap.set({ "n", "v" }, "<leader>la", vim.lsp.buf.code_action, opts) -- see available code actions, in visual mode will apply to selection
opts.desc = 'Smart rename'
keymap.set('n', '<leader>mr', vim.lsp.buf.rename, opts) -- smart rename
opts.desc = "Smart rename"
keymap.set("n", "<leader>mr", vim.lsp.buf.rename, opts) -- smart rename
opts.desc = 'Show buffer diagnostics'
keymap.set('n', '<leader>lD', '<cmd>Telescope diagnostics bufnr=0<CR>', opts) -- show diagnostics for file
opts.desc = "Show buffer diagnostics"
keymap.set("n", "<leader>lD", "<cmd>Telescope diagnostics bufnr=0<CR>", opts) -- show diagnostics for file
opts.desc = 'Show line diagnostics'
keymap.set('n', '<leader>ld', vim.diagnostic.open_float, opts) -- show diagnostics for line
opts.desc = "Show line diagnostics"
keymap.set("n", "<leader>ld", vim.diagnostic.open_float, opts) -- show diagnostics for line
opts.desc = 'Show documentation for what is under cursor'
keymap.set('n', 'K', vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "K", vim.lsp.buf.hover, opts) -- show documentation for what is under cursor
opts.desc = 'Restart LSP'
keymap.set('n', '<leader>ls', ':LspRestart<CR>', opts) -- mapping to restart lsp if necessary
end,
opts.desc = "Restart LSP"
keymap.set("n", "<leader>ls", ":LspRestart<CR>", opts) -- mapping to restart lsp if necessary
end,
})
-- used to enable autocompletion (assign to every lsp server config)
local capabilities = cmp_nvim_lsp.default_capabilities()
-- configure matlab server
lspconfig['clangd'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["clangd"].setup({
capabilities = capabilities,
})
-- configure bash server
lspconfig['bashls'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["bashls"].setup({
capabilities = capabilities,
})
-- configure html server
lspconfig['html'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["html"].setup({
capabilities = capabilities,
})
-- configure typescript server with plugin
lspconfig['tsserver'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["tsserver"].setup({
capabilities = capabilities,
})
-- configure css server
lspconfig['cssls'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["cssls"].setup({
capabilities = capabilities,
})
-- configure tailwindcss server
lspconfig['tailwindcss'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["tailwindcss"].setup({
capabilities = capabilities,
})
-- configure svelte server
lspconfig['svelte'].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
on_attach(client, bufnr)
vim.api.nvim_create_autocmd('BufWritePost', {
pattern = { '*.js', '*.ts' },
callback = function(ctx)
if client.name == 'svelte' then
client.notify('$/onDidChangeTsOrJsFile', { uri = ctx.file })
end
end,
})
end,
lspconfig["svelte"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = { "*.js", "*.ts" },
callback = function(ctx)
if client.name == "svelte" then
client.notify("$/onDidChangeTsOrJsFile", { uri = ctx.file })
end
end,
})
end,
})
-- configure prisma orm server
lspconfig['prismals'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["prismals"].setup({
capabilities = capabilities,
})
-- configure emmet language server
lspconfig['emmet_ls'].setup({
capabilities = capabilities,
on_attach = on_attach,
filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less', 'svelte' },
lspconfig["emmet_ls"].setup({
capabilities = capabilities,
filetypes = { "html", "typescriptreact", "javascriptreact", "css", "sass", "scss", "less", "svelte" },
})
-- configure python server
lspconfig['pyright'].setup({
capabilities = capabilities,
on_attach = on_attach,
lspconfig["pyright"].setup({
capabilities = capabilities,
})
-- configure lua server (with special settings)
lspconfig['lua_ls'].setup({
capabilities = capabilities,
on_attach = on_attach,
settings = { -- custom settings for lua
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { 'vim' },
},
workspace = {
-- make language server aware of runtime files
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.stdpath('config') .. '/lua'] = true,
},
},
},
},
lspconfig["lua_ls"].setup({
capabilities = capabilities,
settings = { -- custom settings for lua
Lua = {
-- make the language server recognize "vim" global
diagnostics = {
globals = { "vim" },
},
workspace = {
-- make language server aware of runtime files
library = {
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.stdpath("config") .. "/lua"] = true,
},
},
},
},
})
local x = vim.diagnostic.severity
local config = {
-- Enable virtual text
virtual_text = { -- or false for disable
prefix = '', -- ■  󰊠
suffix = '',
format = function(diagnostic)
local prefix = '󰊠 '
local suffix = ' '
-- return full message with custom prefix & suffix
return prefix .. diagnostic.message .. suffix
end,
},
update_in_insert = true,
signs = { text = { [x.ERROR] = '', [x.WARN] = '', [x.HINT] = '󰌵', [x.INFO] = '' } },
underline = false,
severity_sort = true,
float = {
focusable = false,
style = 'minimal',
border = 'rounded',
source = 'always',
header = '',
prefix = '',
},
-- Enable virtual text
virtual_text = { -- or false for disable
prefix = "", -- ■  󰊠
suffix = "",
format = function(diagnostic)
local prefix = "󰊠 "
local suffix = " "
-- return full message with custom prefix & suffix
return prefix .. diagnostic.message .. suffix
end,
},
update_in_insert = true,
signs = { text = { [x.ERROR] = "", [x.WARN] = "", [x.HINT] = "󰌵", [x.INFO] = "" } },
underline = false,
severity_sort = true,
float = {
focusable = false,
style = "minimal",
border = "rounded",
source = "always",
header = "",
prefix = "",
},
}
vim.diagnostic.config(config)
-- add borders to lsp info window
require('lspconfig.ui.windows').default_options.border = 'single'
require("lspconfig.ui.windows").default_options.border = "single"
+161 -163
View File
@@ -1,25 +1,50 @@
local lualine = require('lualine')
local icons = require('lib.icons')
-- Color table for highlights
-- stylua: ignore
local colors = {
bg = 'none',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
local mode_color = {
n = colors.green,
i = colors.blue,
v = colors.magenta,
[''] = colors.magenta,
V = colors.magenta,
c = colors.yellow,
t = colors.red,
R = colors.orange,
Rv = colors.orange,
no = colors.fg,
s = colors.violet,
S = colors.violet,
[''] = colors.violet,
ic = colors.yellow,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
['r?'] = colors.cyan,
['!'] = colors.red,
}
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
buffer_is_file = function()
return vim.bo.buftype == ''
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
@@ -29,170 +54,143 @@ local conditions = {
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local searchcount = { 'searchcount', color = { fg = colors.fg, gui = 'bold' } }
local selectioncount = { 'selectioncount', color = { fg = colors.fg, gui = 'bold' } }
local progress = { 'progress', color = { fg = colors.fg, gui = 'bold' } }
local filetype = { 'filetype', color = { fg = colors.blue, gui = 'bold' } }
local filesize = { 'filesize', color = { fg = colors.fg, gui = 'bold' }, cond = conditions.buffer_not_empty }
local fileformat = { 'fileformat', icons_enabled = true, color = { fg = colors.white, gui = 'bold' } }
-- Config
local config = {
options = {
-- Disable sections and component separators
component_separators = '',
section_separators = '',
disabled_filetypes = {
'NeoTree',
'NvimTree',
'Outline',
'alpha',
},
theme = {
-- We are going to use lualine_c an lualine_x as left and
-- right section. Both are highlighted by c theme . So we
-- are just setting default looks o statusline
normal = { c = { fg = colors.fg, bg = colors.bg } },
inactive = { c = { fg = colors.fg, bg = colors.bg } },
},
},
sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
-- These will be filled later
lualine_c = {},
lualine_x = {},
},
inactive_sections = {
-- these are to remove the defaults
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
lualine_c = {},
lualine_x = {},
},
local filename = {
'filename',
cond = conditions.buffer_not_empty and conditions.buffer_is_file,
color = { fg = colors.magenta, gui = 'bold' },
}
-- Inserts a component in lualine_c at left section
local function ins_left(component)
table.insert(config.sections.lualine_c, component)
end
-- Inserts a component in lualine_x at right section
local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left({
function()
return '▊'
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
})
ins_left({
-- mode component
function()
return ''
end,
color = function()
-- auto change color according to neovims mode
local mode_color = {
n = colors.red,
i = colors.green,
v = colors.blue,
['␖'] = colors.blue,
V = colors.blue,
c = colors.magenta,
no = colors.red,
s = colors.orange,
S = colors.orange,
['␓'] = colors.orange,
ic = colors.yellow,
R = colors.violet,
Rv = colors.violet,
cv = colors.red,
ce = colors.red,
r = colors.cyan,
rm = colors.cyan,
['r?'] = colors.cyan,
['!'] = colors.red,
t = colors.red,
}
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { right = 1 },
})
ins_left({
'filename',
cond = conditions.buffer_not_empty,
color = { fg = colors.magenta, gui = 'bold' },
})
ins_left({
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = { error = '', warn = '', info = '' },
diagnostics_color = {
error = { fg = colors.red },
warn = { fg = colors.yellow },
info = { fg = colors.cyan },
local buffers = {
'buffers',
filetype_names = {
TelescopePrompt = icons.ui.Telescope .. 'Telescope',
dashboard = icons.ui.Dashboard .. 'Dashboard',
lazy = icons.ui.Sleep .. 'Lazy',
mason = icons.ui.Package .. 'Mason',
NvimTree = icons.documents.OpenFolder .. 'Files',
spectre_panel = icons.ui.Search .. 'Spectre',
},
})
use_mode_colors = true,
}
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left({
function()
return '%='
local branch = {
'branch',
icon = icons.git.Branch,
fmt = function(str)
return str:sub(1, 32)
end,
})
color = { fg = colors.green, gui = 'bold' },
}
ins_left({
-- Lsp server name .
function()
local msg = 'No Active Lsp'
local clients = vim.lsp.get_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes) ~= -1 then
return client.name
end
end
return msg
end,
icon = ' LSP:',
color = { fg = '#ffffff', gui = 'bold' },
})
ins_right({
local diff_icons = {
'diff',
-- Is it me or the symbol for modified us really weird
symbols = { added = '', modified = '', removed = '' },
symbols = { added = icons.git.AddAlt, modified = icons.git.DiffAlt, removed = icons.git.RemoveAlt },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.orange },
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
})
}
ins_right({
'branch',
icon = '',
color = { fg = colors.violet, gui = 'bold' },
})
local diagnostics = {
'diagnostics',
sources = { 'nvim_lsp', 'nvim_diagnostic', 'nvim_workspace_diagnostic' },
symbols = {
error = icons.diagnostics.Error,
warn = icons.diagnostics.Warning,
info = icons.diagnostics.Information,
hint = icons.diagnostics.Hint,
},
diagnostics_color = {
color_error = { fg = colors.red },
color_warn = { fg = colors.yellow },
color_info = { fg = colors.blue },
color_hint = { fg = colors.yellow },
},
}
ins_right({
local lsp = {
function()
return '▊'
local msg = 'No LSP'
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
local clients = vim.lsp.get_active_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end,
color = { fg = colors.blue },
padding = { left = 1 },
})
icon = icons.ui.Gear,
color = { fg = colors.fg, gui = 'bold' },
}
-- Now don't forget to initialize lualine
lualine.setup(config)
local encoding = {
'o:encoding',
fmt = string.upper,
cond = conditions.hide_in_width,
color = { fg = colors.green, gui = 'bold' },
}
local separator = {
function()
return icons.ui.Separator
end,
color = function()
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { left = 0, right = 0 },
}
local function mode(icon)
icon = icon or icons.ui.Neovim
return {
function()
return icon
end,
color = function()
return { fg = mode_color[vim.fn.mode()] }
end,
padding = { left = 1, right = 0 },
}
end
lualine.setup({
options = {
component_separators = '',
-- section_separators = '',
theme = 'onedark',
disabled_filetypes = {
'dashboard',
},
},
-- extensions = { 'quickfix', 'man', 'mason', 'lazy', 'toggleterm', 'nvim-tree' },
tabline = {
lualine_a = {},
lualine_b = { mode(), buffers },
lualine_c = {},
lualine_x = { diff_icons, branch },
lualine_y = { searchcount, selectioncount },
lualine_z = {},
},
sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { separator, mode(icons.ui.Heart), 'location', progress, filename },
lualine_x = { diagnostics, lsp, filetype, filesize, fileformat, encoding, separator },
lualine_y = {},
lualine_z = {},
},
})
+38 -37
View File
@@ -1,47 +1,48 @@
local mason = require('mason')
local mason_lspconfig = require('mason-lspconfig')
local mason_tool_installer = require('mason-tool-installer')
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")
local mason_tool_installer = require("mason-tool-installer")
-- enable mason and configure icons
mason.setup({
ui = {
border = 'rounded',
icons = {
package_installed = '✓',
package_pending = '➜',
package_uninstalled = '✗',
},
},
automatic_installation = true,
ui = {
border = "rounded",
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗",
},
},
})
mason_lspconfig.setup({
-- list of servers for mason to install
ensure_installed = {
'tsserver',
'html',
'cssls',
'tailwindcss',
'svelte',
'lua_ls',
'pyright',
'jdtls',
'bashls',
'jsonls',
'clangd',
'emmet_ls',
'prismals',
},
-- list of servers for mason to install
ensure_installed = {
"tsserver",
"html",
"cssls",
"tailwindcss",
"svelte",
"lua_ls",
"pyright",
"jdtls",
"bashls",
"jsonls",
"clangd",
"emmet_ls",
"prismals",
},
})
mason_tool_installer.setup({
ensure_installed = {
'prettier', -- prettier formatter
'biome', -- js formatter
'stylua', -- lua formatter
'black', -- python formatter
'isort', -- python formatter
'clang-format', -- c/c++ formatter
'pylint',
'eslint_d',
},
ensure_installed = {
"prettier", -- prettier formatter
"biome", -- js formatter
"stylua", -- lua formatter
"black", -- python formatter
"isort", -- python formatter
"clang-format", -- c/c++ formatter
"pylint",
"eslint_d",
},
})
+46 -46
View File
@@ -1,19 +1,19 @@
local mason_null_ls = require('mason-null-ls')
local mason_null_ls = require("mason-null-ls")
local null_ls = require('null-ls')
local null_ls = require("null-ls")
local null_ls_utils = require('null-ls.utils')
local null_ls_utils = require("null-ls.utils")
mason_null_ls.setup({
ensure_installed = {
'prettier', -- prettier formatter
'biome', -- js formatter
'clang-format', -- c/c++ formatter
'stylua', -- lua formatter
'black', -- python formatter
'pylint', -- python linter
-- "eslint_d", -- js linter
},
ensure_installed = {
"prettier", -- prettier formatter
"biome", -- js formatter
"clang-format", -- c/c++ formatter
"stylua", -- lua formatter
"black", -- python formatter
"pylint", -- python linter
-- "eslint_d", -- js linter
},
})
-- for conciseness
@@ -21,41 +21,41 @@ local formatting = null_ls.builtins.formatting -- to setup formatters
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
-- to setup format on save
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
-- configure null_ls
null_ls.setup({
root_dir = null_ls_utils.root_pattern('.null-ls-root', 'Makefile', '.git', 'package.json'),
sources = {
formatting.prettier, -- js/ts formatter
formatting.stylua, -- lua formatter
formatting.isort,
formatting.black,
formatting.clang_format,
diagnostics.pylint,
-- diagnostics.eslint_d.with({ -- js/ts linter
-- condition = function(utils)
-- return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs
-- end,
-- }),
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_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()
vim.lsp.buf.format({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == 'null-ls'
end,
bufnr = bufnr,
})
end,
})
end
end,
root_dir = null_ls_utils.root_pattern(".null-ls-root", "Makefile", ".git", "package.json"),
sources = {
formatting.prettier, -- js/ts formatter
formatting.stylua, -- lua formatter
formatting.isort,
formatting.black,
formatting.clang_format,
diagnostics.pylint,
-- diagnostics.eslint_d.with({ -- js/ts linter
-- condition = function(utils)
-- return utils.root_has_file({ ".eslintrc.js", ".eslintrc.cjs" }) -- only enable if root has .eslintrc.js or .eslintrc.cjs
-- end,
-- }),
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_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()
vim.lsp.buf.format({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end,
})
end
end,
})