mostly added friendly-snippets and a dashboard

pull/1709/head
Nikhil 2 weeks ago
parent c5d1b0ac8f
commit f01bb407cc

@ -0,0 +1,159 @@
-- lua/dashboard.lua
-- FIX: Require snacks at the top to make it available in this file's scope
local snacks = require("snacks")
local M = {}
M.config = {
enabled = true,
width = 60,
row = nil, -- dashboard position. nil for center
col = nil, -- dashboard position. nil for center
pane_gap = 4, -- empty columns between vertical panes
autokeys = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
preset = {
pick = nil,
keys = {
-- FIX: Changed actions from strings to functions and used the correct 'snacks' variable
{ icon = " ", key = "f", desc = "Find File", action = function() snacks.dashboard.pick("files") end },
{ icon = " ", key = "n", desc = "New File", action = ":ene | startinsert" },
{ icon = " ", key = "g", desc = "Find Text", action = function() snacks.dashboard.pick("live_grep") end },
{ icon = " ", key = "r", desc = "Recent Files", action = function() snacks.dashboard.pick("oldfiles") end },
{
icon = " ",
key = "c",
desc = "Config",
action = function() snacks.dashboard.pick("files", { cwd = vim.fn.stdpath("config") }) end,
},
{ icon = " ", key = "s", desc = "Restore Session", section = "session" },
{ icon = "󰒲 ", key = "L", desc = "Lazy", action = ":Lazy", enabled = package.loaded.lazy ~= nil },
{ icon = " ", key = "q", desc = "Quit", action = ":qa" },
},
header = [[
]],
},
formats = {
-- FIX: The M.icon function was not defined.
-- This now returns the default icon to prevent errors.
-- For custom icons, you would need to implement this, for example using nvim-web-devicons:
-- return require("nvim-web-devicons").get_icon(item.file, item.icon)
icon = function(item)
if item.file and (item.icon == "file" or item.icon == "directory") then
-- Placeholder to avoid error. Implement your icon logic here.
local ok, devicons = pcall(require, "nvim-web-devicons")
if ok then
local icon, hl = devicons.get_icon(item.file, nil, { default = true })
return { icon, width = 2, hl = hl }
end
end
return { item.icon, width = 2, hl = "icon" }
end,
footer = { "%s", align = "center" },
header = { "%s", align = "center" },
file = function(item, ctx)
local fname = vim.fn.fnamemodify(item.file, ":~")
fname = ctx.width and #fname > ctx.width and vim.fn.pathshorten(fname) or fname
if #fname > ctx.width then
local dir = vim.fn.fnamemodify(fname, ":h")
local file = vim.fn.fnamemodify(fname, ":t")
if dir and file then
file = file:sub(-(ctx.width - #dir - 2))
fname = dir .. "/…" .. file
end
end
local dir, file = fname:match("^(.*)/(.+)$")
return dir and { { dir .. "/", hl = "dir" }, { file, hl = "file" } } or { { fname, hl = "file" } }
end,
},
-- Replace your old 'sections' table with this one
sections = {
-- Header (spans all columns)
{ section = "header" },
{ section = "startup", padding = { 0, 0, 1, 0 } }, -- Adds a small gap below the header
-----------------------------------
-- PANE 1: Left Column
-----------------------------------
-- Pokemon sprite at the top-left
{
pane = 1, -- MOVED from pane 3
section = "terminal",
cmd = "pokemon-colorscripts -r --no-title; sleep .1",
random = 10,
height = 15, -- Adjust height as needed
padding = 2,
indent = 4,
},
-- File commands below the sprite
{
pane = 1, -- MOVED to pane 1
section = "keys",
gap = 1,
padding = { 2, 3 }, -- top/bottom, left/right
},
-----------------------------------
-- PANE 2: Right Column
-----------------------------------
-- "Browse Repo" button at the top-right
{
pane = 2, -- Stays in pane 2
icon = " ",
desc = "Browse Repo",
padding = { 1, 0 },
key = "b",
action = function() require("snacks").gitbrowse() end,
},
-- All GitHub sections (Notifications, Issues, PRs)
function()
local in_git = require("snacks").git.get_root() ~= nil
local cmds = {
{
title = "Notifications",
cmd = "gh notify -s -a -n5",
action = function() vim.ui.open("https://github.com/notifications") end,
key = "n",
height = 5,
},
{
title = "Open Issues",
cmd = "gh issue list -L 5",
key = "i",
action = function() vim.fn.jobstart("gh issue list --web", { detach = true }) end,
height = 7,
},
{
title = "Open PRs",
cmd = "gh pr list -L 5",
key = "p",
action = function() vim.fn.jobstart("gh pr list --web", { detach = true }) end,
height = 7,
},
}
return vim.tbl_map(function(cmd)
return vim.tbl_extend("force", {
pane = 2, -- IMPORTANT: Ensures all these are in the right column
section = "terminal",
enabled = in_git,
padding = 1,
ttl = 5 * 60, -- Refresh every 5 minutes
indent = 3,
}, cmd)
end, cmds)
end,
},
}
return M

@ -52,7 +52,7 @@ return {
},
},
-- -- Autocompletion: `nvim-cmp` and its dependencies
-- Autocompletion: `nvim-cmp` and its dependencies
-- This is the core of the autocompletion system.
{
'hrsh7th/nvim-cmp',
@ -69,6 +69,11 @@ return {
end
return 'make install_jsregexp'
end)(),
-- ++ ADDED DEPENDENCY ++
dependencies = {
-- This plugin provides a collection of useful snippets.
'rafamadriz/friendly-snippets',
},
},
-- `cmp_luasnip` connects the snippet engine to the autocompletion.
'saadparwaiz1/cmp_luasnip',
@ -85,6 +90,10 @@ return {
local luasnip = require 'luasnip'
luasnip.config.setup {}
-- ++ ADDED SNIPPET LOADING ++
-- This line tells luasnip to load snippets from plugins like friendly-snippets.
require("luasnip.loaders.from_vscode").lazy_load()
-- Set up the `nvim-cmp` plugin.
cmp.setup {
-- Define how snippets are expanded.
@ -161,11 +170,11 @@ return {
end,
},
{ -- Adds indentation guides to all lines
'lukas-reineke/indent-blankline.nvim',
main = 'ibl',
opts = {},
},
-- { -- Adds indentation guides to all lines
-- 'lukas-reineke/indent-blankline.nvim',
-- main = 'ibl',
-- opts = {},
-- },
-- Detect tabstop and shiftwidth automatically
'tpope/vim-sleuth',

@ -55,12 +55,12 @@ return {
cmd = { "Git", "G" }, -- lazy load only on :Git commands
},
{ -- Lazygit UI (optional)
"kdheepak/lazygit.nvim",
cmd = "LazyGit",
dependencies = { "nvim-lua/plenary.nvim" },
keys = {
{ "<leader>lg", "<cmd>LazyGit<CR>", desc = "Open LazyGit" },
},
},
-- { -- Lazygit UI (optional)
-- "kdheepak/lazygit.nvim",
-- cmd = "LazyGit",
-- dependencies = { "nvim-lua/plenary.nvim" },
-- keys = {
-- { "<leader>lg", "<cmd>LazyGit<CR>", desc = "Open LazyGit" },
-- },
-- },
}

@ -147,24 +147,74 @@ return {
end,
},
{ -- Snacks.nvim: utilities (scratch, terminal, etc.)
{
"folke/snacks.nvim",
event = "VeryLazy",
priority = 1000,
lazy = false,
opts = {
terminal = { win = { style = "float" } },
scratch = { enabled = true }, -- ✅ must be a table
-- Core utilities
bigfile = { enabled = true }, -- handle large files gracefully
quickfile = { enabled = true }, -- speed up startup with file args
scope = { enabled = true }, -- treesitter/indent-based scope detection
util = { enabled = true }, -- core utility functions
-- UI / Experience
dashboard = { enabled = true }, -- Will be configured in config function
explorer = { enabled = true }, -- Snacks explorer (you still keep neo-tree)
indent = { enabled = true }, -- replaces indent-blankline.nvim
input = { enabled = true }, -- nicer vim.ui.input
picker = { enabled = true }, -- universal picker (you still keep telescope)
notifier = { enabled = true }, -- pretty notifications
scroll = { enabled = true }, -- smooth scrolling
statuscolumn = { enabled = true }, -- sign/number column
words = { enabled = true }, -- highlight LSP references / word navigation
-- Productivity
terminal = { win = { style = "float" } }, -- floating terminal
scratch = { enabled = true }, -- persistent scratch buffers
zen = { enabled = true }, -- zen mode (distraction free)
git = { enabled = true }, -- git helpers
gitbrowse = { enabled = true }, -- open in GitHub/GitLab/Bitbucket
lazygit = { enabled = true }, -- replaces kdheepak/lazygit.nvim
rename = { enabled = true }, -- LSP-aware file rename
},
config = function(_, opts)
-- Load dashboard config and merge it
local dashboard_config = require("dashboard")
-- FIX: Access the .config table from the required module
opts.dashboard = dashboard_config.config
local snacks = require("snacks")
snacks.setup(opts)
-- Keymaps
vim.keymap.set("n", "<leader>tt", function() snacks.terminal.toggle() end, { desc = "Toggle terminal" })
vim.keymap.set("n", "<leader>sc", function() snacks.scratch.open() end, { desc = "Open [s]cratch buffer" })
-- === Keymaps ===
-- Dashboard
vim.keymap.set("n", "<leader>db", function() snacks.dashboard.open() end, { desc = "Open [D]ash[B]oard" })
-- Explorer (in addition to neo-tree)
vim.keymap.set("n", "<leader>xx", function() snacks.explorer.open() end, { desc = "Open Snacks E[x]plorer" })
-- Terminal
vim.keymap.set("n", "<leader>tt", function() snacks.terminal.toggle() end, { desc = "Toggle [T]erminal" })
-- Scratch Buffer
vim.keymap.set("n", "<leader>sc", function() snacks.scratch.open() end, { desc = "Open [S]cratch buffer" })
-- Zen Mode
vim.keymap.set("n", "<leader>zn", function() snacks.zen.toggle() end, { desc = "Toggle [Z]en mode" })
-- LazyGit
vim.keymap.set("n", "<leader>gg", function() snacks.lazygit.open() end, { desc = "Open [G]it: LazyGit" })
-- Git Browse (open repo/commit/branch in browser)
vim.keymap.set("n", "<leader>gb", function() snacks.gitbrowse.open() end, { desc = "[G]it [B]rowse in browser" })
-- Word navigation (LSP references / matches)
vim.keymap.set("n", "<leader>ww", function() snacks.words.jump_next() end, { desc = "Jump to next [W]ord reference" })
vim.keymap.set("n", "<leader>wW", function() snacks.words.jump_prev() end, { desc = "Jump to prev [W]ord reference" })
end,
},
{ -- Debugging (DAP)
'mfussenegger/nvim-dap',
dependencies = {

Loading…
Cancel
Save