net config

This commit is contained in:
Harivansh Rathi 2026-02-04 15:18:34 -05:00
parent 93b7b93d64
commit dd59a54b92
36 changed files with 960 additions and 631 deletions

41
lua/config/lsp.lua Normal file
View file

@ -0,0 +1,41 @@
-- Shared LSP utilities
local M = {}
-- Set up buffer-local keymaps when LSP attaches
function M.on_attach(client, bufnr)
local opts = { buffer = bufnr, silent = true }
-- Navigation
vim.keymap.set("n", "gd", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" }))
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, vim.tbl_extend("force", opts, { desc = "Go to declaration" }))
vim.keymap.set("n", "<C-]>", vim.lsp.buf.definition, vim.tbl_extend("force", opts, { desc = "Go to definition" }))
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, vim.tbl_extend("force", opts, { desc = "Go to implementation" }))
vim.keymap.set("n", "gr", vim.lsp.buf.references, vim.tbl_extend("force", opts, { desc = "Go to references" }))
-- Documentation
vim.keymap.set("n", "K", vim.lsp.buf.hover, vim.tbl_extend("force", opts, { desc = "Hover documentation" }))
-- Refactoring
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, vim.tbl_extend("force", opts, { desc = "Rename symbol" }))
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, vim.tbl_extend("force", opts, { desc = "Code action" }))
-- Formatting
vim.keymap.set("n", "<leader>f", function()
vim.lsp.buf.format({ async = true })
end, vim.tbl_extend("force", opts, { desc = "Format buffer" }))
end
-- Return default capabilities for LSP servers
function M.capabilities()
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- If nvim-cmp is available, extend capabilities
local ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if ok then
capabilities = vim.tbl_deep_extend("force", capabilities, cmp_nvim_lsp.default_capabilities())
end
return capabilities
end
return M

139
lua/config/statusline.lua Normal file
View file

@ -0,0 +1,139 @@
-- Minimal custom statusline
local M = {}
-- Mode mapping
local mode_map = {
n = "NORMAL",
no = "N-PENDING",
nov = "N-PENDING",
noV = "N-PENDING",
["no\22"] = "N-PENDING",
niI = "NORMAL",
niR = "NORMAL",
niV = "NORMAL",
nt = "NORMAL",
ntT = "NORMAL",
v = "VISUAL",
vs = "VISUAL",
V = "V-LINE",
Vs = "V-LINE",
["\22"] = "V-BLOCK",
["\22s"] = "V-BLOCK",
s = "SELECT",
S = "S-LINE",
["\19"] = "S-BLOCK",
i = "INSERT",
ic = "INSERT",
ix = "INSERT",
R = "REPLACE",
Rc = "REPLACE",
Rx = "REPLACE",
Rv = "V-REPLACE",
Rvc = "V-REPLACE",
Rvx = "V-REPLACE",
c = "COMMAND",
cv = "EX",
ce = "EX",
r = "REPLACE",
rm = "MORE",
["r?"] = "CONFIRM",
["!"] = "SHELL",
t = "TERMINAL",
}
-- Get current mode indicator
local function get_mode()
local mode = vim.api.nvim_get_mode().mode
return mode_map[mode] or mode
end
-- Get git branch from gitsigns
local function get_git_branch()
local branch = vim.b.gitsigns_head
if branch and branch ~= "" then
return " " .. branch
end
return ""
end
-- Get filename with modified indicator
local function get_filename()
local filename = vim.fn.expand("%:t")
if filename == "" then
filename = "[No Name]"
end
local modified = vim.bo.modified and " [+]" or ""
local readonly = vim.bo.readonly and " [RO]" or ""
return filename .. modified .. readonly
end
-- Get file path (relative to cwd)
local function get_filepath()
local filepath = vim.fn.expand("%:~:.")
if filepath == "" then
return ""
end
return filepath
end
-- Get current position
local function get_position()
local line = vim.fn.line(".")
local col = vim.fn.col(".")
local total = vim.fn.line("$")
return string.format("%d:%d/%d", line, col, total)
end
-- Get filetype
local function get_filetype()
local ft = vim.bo.filetype
if ft == "" then
return ""
end
return ft
end
-- Build the statusline
function M.statusline()
local parts = {}
-- Left side
table.insert(parts, " " .. get_mode() .. " ")
table.insert(parts, get_git_branch())
local filepath = get_filepath()
if filepath ~= "" then
table.insert(parts, " " .. filepath)
end
-- Modified indicator
if vim.bo.modified then
table.insert(parts, " [+]")
end
-- Separator
table.insert(parts, "%=")
-- Right side
local ft = get_filetype()
if ft ~= "" then
table.insert(parts, ft .. " ")
end
table.insert(parts, get_position() .. " ")
return table.concat(parts, "")
end
-- Setup function to configure the statusline
function M.setup()
-- Use the %!v:lua.require() pattern
vim.o.statusline = "%!v:lua.require('config.statusline').statusline()"
-- Ensure statusline is always shown
vim.o.laststatus = 2
end
return M