summaryrefslogtreecommitdiff
path: root/private_dot_config/nvim/lua
diff options
context:
space:
mode:
Diffstat (limited to 'private_dot_config/nvim/lua')
-rw-r--r--private_dot_config/nvim/lua/dap_conf.lua52
-rw-r--r--private_dot_config/nvim/lua/evil_lualine.lua152
-rw-r--r--private_dot_config/nvim/lua/git.lua65
-rw-r--r--private_dot_config/nvim/lua/lsp_conf.lua130
4 files changed, 399 insertions, 0 deletions
diff --git a/private_dot_config/nvim/lua/dap_conf.lua b/private_dot_config/nvim/lua/dap_conf.lua
new file mode 100644
index 0000000..2346e6a
--- /dev/null
+++ b/private_dot_config/nvim/lua/dap_conf.lua
@@ -0,0 +1,52 @@
+local dap, dapui = require('dap'), require('dapui')
+local dapgo = require('dap-go')
+dapui.setup()
+dapgo.setup()
+dap.listeners.before.attach.dapui_config = function()
+ dapui.open()
+end
+dap.listeners.before.launch.dapui_config = function()
+ dapui.open()
+end
+
+dap.adapters.gdb = {
+ type = "executable",
+ command = "gdb",
+ args = { "--interpreter=dap", "--eval-command", "set print pretty on" }
+}
+
+local configurations = {'c', 'cpp', 'rust'}
+
+for _, conf in ipairs(configurations) do
+ dap.configurations[conf] = {
+ {
+ name = "Launch",
+ type = "gdb",
+ request = "launch",
+ program = function()
+ return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
+ end,
+ cwd = "${workspaceFolder}",
+ stopAtBeginningOfMainSubprogram = false,
+ },
+ }
+end
+
+-- Include the next few lines until the comment only if you feel you need it
+dap.listeners.before.event_terminated.dapui_config = function()
+ dapui.close()
+end
+dap.listeners.before.event_exited.dapui_config = function()
+ dapui.close()
+end
+-- Include everything after this
+
+
+vim.keymap.set('n', '<F12>', function() require('dap').continue() end)
+vim.keymap.set('n', '<F5>', function() require('dap').step_over() end)
+vim.keymap.set('n', '<F6>', function() require('dap').step_into() end)
+vim.keymap.set('n', '<F7>', function() require('dap').step_out() end)
+vim.keymap.set('n', '<C-K>', function() require('dap').toggle_breakpoint() end)
+vim.api.nvim_create_user_command('DapRepeat',function() require('dap').run_last() end, {})
+vim.api.nvim_create_user_command('DapOpen',function() dapui.open() end, {})
+vim.api.nvim_create_user_command('DapClose',function() dapui.close() end, {})
diff --git a/private_dot_config/nvim/lua/evil_lualine.lua b/private_dot_config/nvim/lua/evil_lualine.lua
new file mode 100644
index 0000000..b38e283
--- /dev/null
+++ b/private_dot_config/nvim/lua/evil_lualine.lua
@@ -0,0 +1,152 @@
+-- Eviline config for lualine
+-- Author: shadmansaleh
+-- Credit: glepnir
+local lualine = require('lualine')
+
+-- Color table for highlights
+-- stylua: ignore
+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 conditions = {
+ buffer_not_empty = function()
+ return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
+ end,
+ hide_in_width = function()
+ return vim.fn.winwidth(0) > 80
+ end,
+ check_git_workspace = function()
+ local filepath = vim.fn.expand('%:p:h')
+ local gitdir = vim.fn.finddir('.git', filepath .. ';')
+ return gitdir and #gitdir > 0 and #gitdir < #filepath
+ end,
+}
+
+-- Config
+local config = {
+ options = {
+ -- Disable sections and component separators
+ component_separators = '',
+ section_separators = '',
+ 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 = {},
+ },
+}
+
+-- 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 {
+ 'filename',
+ cond = conditions.buffer_not_empty,
+ path = 3,
+ color = { fg = colors.magenta, gui = 'bold' },
+}
+
+ins_left {
+ -- filesize component
+ 'filesize',
+ cond = conditions.buffer_not_empty,
+}
+
+ins_left { 'location' }
+
+ins_left { 'progress', color = { fg = colors.fg, 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 },
+ },
+}
+
+-- 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 '%='
+ end,
+}
+
+-- Add components to right sections
+ins_right { 'lsp_status' }
+
+ins_right {
+ 'o:encoding', -- option component same as &encoding in viml
+ fmt = string.upper, -- I'm not sure why it's upper case either ;)
+ cond = conditions.hide_in_width,
+ color = { fg = colors.green, gui = 'bold' },
+}
+
+ins_right {
+ 'fileformat',
+ fmt = string.upper,
+ icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
+ color = { fg = colors.green, gui = 'bold' },
+}
+
+ins_right {
+ 'branch',
+ icon = '',
+ color = { fg = colors.violet, gui = 'bold' },
+}
+
+ins_right {
+ 'diff',
+ -- Is it me or the symbol for modified us really weird
+ symbols = { added = ' ', modified = '󰝤 ', removed = ' ' },
+ diff_color = {
+ added = { fg = colors.green },
+ modified = { fg = colors.orange },
+ removed = { fg = colors.red },
+ },
+ cond = conditions.hide_in_width,
+}
+
+-- Now don't forget to initialize lualine
+lualine.setup(config)
diff --git a/private_dot_config/nvim/lua/git.lua b/private_dot_config/nvim/lua/git.lua
new file mode 100644
index 0000000..da6bbdd
--- /dev/null
+++ b/private_dot_config/nvim/lua/git.lua
@@ -0,0 +1,65 @@
+require('gitsigns').setup {
+ signs = {
+ add = { text = '+' },
+ change = { text = '~' },
+ delete = { text = '-' },
+ topdelete = { text = '-' },
+ changedelete = { text = '~' },
+ untracked = { text = '┆' },
+ },
+ signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
+ numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
+ linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
+ word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
+ watch_gitdir = {
+ follow_files = true
+ },
+ attach_to_untracked = true,
+ current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
+ current_line_blame_opts = {
+ virt_text = true,
+ virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
+ delay = 1000,
+ ignore_whitespace = false,
+ },
+ current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
+ sign_priority = 6,
+ update_debounce = 100,
+ status_formatter = nil, -- Use default
+ max_file_length = 40000, -- Disable if file is longer than this (in lines)
+ preview_config = {
+ -- Options passed to nvim_open_win
+ border = 'single',
+ style = 'minimal',
+ relative = 'cursor',
+ row = 0,
+ col = 1
+ },
+ on_attach = function(bufnr)
+ local gs = package.loaded.gitsigns
+ local function map(mode, l, r, opts)
+ opts = opts or {}
+ opts.buffer = bufnr
+ vim.keymap.set(mode, l, r, opts)
+ end
+
+ map('n', ']c', function()
+ if vim.wo.diff then return ']c' end
+ vim.schedule(function() gs.next_hunk() end)
+ return '<Ignore>'
+ end, {expr=true})
+
+ map('n', '[c', function()
+ if vim.wo.diff then return '[c' end
+ vim.schedule(function() gs.prev_hunk() end)
+ return '<Ignore>'
+ end, {expr=true})
+
+ map('n', 'hs', gs.stage_hunk)
+ map('v', 'hs', function() gs.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
+ map('n', 'hS', gs.stage_buffer)
+ map('n', 'hu', gs.undo_stage_hunk)
+ map('n', 'hp', gs.preview_hunk)
+ map('n', 'hB', gs.blame_line)
+ end
+}
diff --git a/private_dot_config/nvim/lua/lsp_conf.lua b/private_dot_config/nvim/lua/lsp_conf.lua
new file mode 100644
index 0000000..15fa695
--- /dev/null
+++ b/private_dot_config/nvim/lua/lsp_conf.lua
@@ -0,0 +1,130 @@
+local nvim_lsp = require('lspconfig')
+local trouble = require("trouble")
+
+local capabilities = require("cmp_nvim_lsp").default_capabilities()
+
+-- Redefine LSP diagnostic signs
+-- local signs = { Error = 'E', Warning = 'W', Hint = 'H', Information = 'I' }
+--
+-- for type, icon in pairs(signs) do
+-- local hl = 'DiagnosticSign' .. type
+-- vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
+-- end
+
+local opts = { noremap=true, silent=true }
+
+-- Setup lsp_signature for function signature help
+require "lsp_signature".setup()
+
+-- Common on_attach function to handle keymaps and settings for all LSPs
+local common_on_attach = function(client, bufnr)
+ -- Key mappings
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "ga", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
+ -- Use vim.diagnostic.open_float for showing line diagnostics (replacing deprecated call)
+ vim.api.nvim_buf_set_keymap(bufnr, "n", "<space>e", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
+ vim.keymap.set('n', '<A-f>', '<cmd>lua vim.lsp.buf.format {async = true}<cr>', opts)
+
+ -- Autoformat on save
+ vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.format {async = true}")
+end
+
+-- LSP servers setup
+local servers = {
+ 'clangd',
+ 'gopls',
+ 'jdtls',
+ 'metals',
+ 'ocamllsp',
+ 'ruff',
+ 'rust_analyzer',
+ -- 'hls',
+}
+
+capabilities.offsetEncoding = { "utf-16" }
+
+for _, lsp in ipairs(servers) do
+ nvim_lsp[lsp].setup {
+ capabilities = capabilities,
+ on_attach = common_on_attach,
+ flags = {
+ debounce_text_changes = 150,
+ }
+ }
+end
+
+nvim_lsp.ts_ls.setup {
+ capabilities = capabilities,
+ on_attach = common_on_attach,
+ filetypes = { "typescript", "typescriptreact", "typescript.tsx" },
+ cmd = { "typescript-language-server", "--stdio" }
+}
+
+-- nvim_lsp.pyright.setup {
+-- settings = {
+-- pyright = {
+-- -- Using Ruff's import organizer
+-- disableOrganizeImports = true,
+-- },
+-- python = {
+-- analysis = {
+-- -- Ignore all files for analysis to exclusively use Ruff for linting
+-- ignore = { '*' },
+-- },
+-- },
+-- },
+-- }
+
+vim.lsp.inlay_hint.enable(true, { 0 })
+
+-- Trouble setup
+trouble.setup({
+ use_diagnostic_signs = true,
+ auto_close = true,
+ auto_open = false
+})
+
+-- nvim-cmp setup for autocompletion
+local luasnip = require 'luasnip'
+local cmp = require 'cmp'
+cmp.setup {
+ snippet = {
+ expand = function(args)
+ luasnip.lsp_expand(args.body)
+ end,
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-d>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-Space>'] = cmp.mapping.complete(),
+ ['<CR>'] = cmp.mapping.confirm {
+ behavior = cmp.ConfirmBehavior.Replace,
+ select = true,
+ },
+ ['<Tab>'] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_next_item()
+ elseif luasnip.expand_or_jumpable() then
+ luasnip.expand_or_jump()
+ else
+ fallback()
+ end
+ end, { 'i', 's' }),
+ ['<S-Tab>'] = cmp.mapping(function(fallback)
+ if cmp.visible() then
+ cmp.select_prev_item()
+ elseif luasnip.jumpable(-1) then
+ luasnip.jump(-1)
+ else
+ fallback()
+ end
+ end, { 'i', 's' }),
+ }),
+ sources = {
+ { name = 'nvim_lsp' },
+ { name = 'luasnip' },
+ },
+}