diff --git a/init.lua b/init.lua index 21c83f8..3823631 100644 --- a/init.lua +++ b/init.lua @@ -38,8 +38,6 @@ require "nvchad.autocmds" require("configs.set") -vim.opt.relativenumber = true - vim.schedule(function() require "mappings" end) diff --git a/lazy-lock.json b/lazy-lock.json index e483742..3581cc4 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -33,6 +33,7 @@ "nvim-cmp": { "branch": "main", "commit": "12509903a5723a876abd65953109f926f4634c30" }, "nvim-dap": { "branch": "master", "commit": "52302f02fea3a490e55475de52fa4deb8af2eb11" }, "nvim-lspconfig": { "branch": "master", "commit": "00dae9f5f4ad215d4561f2fd2f26478c48b0ca7f" }, + "nvim-notify": { "branch": "master", "commit": "22f29093eae7785773ee9d543f8750348b1a195c" }, "nvim-tree.lua": { "branch": "master", "commit": "70825f23db61ecd900c4cfea169bffe931926a9d" }, "nvim-treesitter": { "branch": "master", "commit": "824bf8455fd670186986fb3eb46fcaa4c5460949" }, "nvim-web-devicons": { "branch": "master", "commit": "402377242b04be3f4f0f3720bd952df86e946c30" }, diff --git a/lua/configs/auto-session.lua b/lua/configs/auto-session.lua new file mode 100644 index 0000000..6a23612 --- /dev/null +++ b/lua/configs/auto-session.lua @@ -0,0 +1,45 @@ +require("auto-session").setup { + enabled = true, + root_dir = vim.fn.stdpath "data" .. "/sessions/", + auto_save = true, + auto_restore = true, + auto_create = true, + suppressed_dirs = nil, + allowed_dirs = nil, + auto_restore_last_session = false, + use_git_branch = false, + lazy_support = true, + bypass_save_filetypes = nil, + close_unsupported_windows = true, + args_allow_single_directory = true, + args_allow_files_auto_save = false, + continue_restore_on_error = true, + show_auto_restore_notif = false, + cwd_change_handling = false, + lsp_stop_on_restore = false, + log_level = "error", + + session_lens = { + load_on_setup = true, + theme_conf = { + -- test + }, + previewer = false, + + mappings = { + delete_session = { "i", "" }, + alternate_session = { "i", "" }, + copy_session = { "i", "" }, + }, + + session_control = { + control_dir = vim.fn.stdpath "data" .. "/auto_session/", + control_filename = "session_control.json", + }, + }, + vim.api.nvim_create_autocmd({ "VimLeavePre" }, { + callback = function() + vim.cmd( "SessionSave" ) + end, + }), +} diff --git a/lua/configs/copilot.lua b/lua/configs/copilot.lua index ee713a5..fad611d 100644 --- a/lua/configs/copilot.lua +++ b/lua/configs/copilot.lua @@ -1,64 +1,64 @@ - require("copilot").setup({ +require("copilot").setup({ panel = { - enabled = true, - auto_refresh = true, - keymap = { - jump_prev = "[[", - jump_next = "]]", - accept = "", - refresh = "gr", - open = "" - }, - layout = { - position = "bottom", -- | top | left | right | horizontal | vertical - ratio = 0.4 - }, + enabled = true, + auto_refresh = true, + keymap = { + jump_prev = "[[", + jump_next = "]]", + accept = "", + refresh = "gr", + open = "" + }, + layout = { + position = "bottom", -- | top | left | right | horizontal | vertical + ratio = 0.4 + }, }, suggestion = { - enabled = true, - auto_trigger = true, - hide_during_completion = true, - debounce = 75, - keymap = { - accept = "", - accept_word = false, - accept_line = false, - next = "", - prev = "", - dismiss = "", - }, + enabled = true, + auto_trigger = true, + hide_during_completion = true, + debounce = 75, + keymap = { + accept = "", + accept_word = false, + accept_line = false, + next = "", + prev = "", + dismiss = "", + }, }, filetypes = { - -- yaml = false, - -- markdown = false, - -- help = false, - -- gitcommit = false, - -- gitrebase = false, - -- hgcommit = false, - -- svn = false, - -- cvs = false, - -- python = false, - -- html = false, - -- css = false, - -- sh = false, - -- tex = false, - -- typescript = false, - -- java = false, - -- swift = false, - -- cpp = false, - -- hypr = false, - -- ["."] = false, + -- yaml = false, + -- markdown = false, + -- help = false, + -- gitcommit = false, + -- gitrebase = false, + -- hgcommit = false, + -- svn = false, + -- cvs = false, + -- python = false, + -- html = false, + -- css = false, + -- sh = false, + -- tex = false, + -- typescript = false, + -- java = false, + -- swift = false, + -- cpp = false, + -- hypr = false, + -- ["."] = false, }, copilot_node_command = 'node', -- Node.js version must be > 18.x server_opts_overrides = {}, vim.api.nvim_create_autocmd({ "VimLeavePre" }, { - callback = function() - vim.cmd( "CopilotChatSave AutoSave" ) - end, + callback = function() + vim.cmd( "CopilotChatSave AutoSave" ) + end, }), vim.api.nvim_create_autocmd( "VimEnter", { - callback = function() - vim.cmd( "CopilotChatLoad AutoSave" ) - end, + callback = function() + vim.cmd( "CopilotChatLoad AutoSave" ) + end, }), - }) +}) diff --git a/lua/configs/focus.lua b/lua/configs/focus.lua index 220ee79..5f384c3 100644 --- a/lua/configs/focus.lua +++ b/lua/configs/focus.lua @@ -25,7 +25,7 @@ require("focus").setup({ enable = false, list = '+1', }, - signcolumn = true, + signcolumn = false, winhighlight = false, } }) diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua index 0dba563..595ba67 100644 --- a/lua/configs/lspconfig.lua +++ b/lua/configs/lspconfig.lua @@ -103,24 +103,9 @@ local servers = { } lspconfig.hyprls.setup { - on_attach = nvlsp.on_attach, - root_dir = function( fname ) - local root_files = { - 'hyprland.conf', - 'hypridle.conf', - 'hyprlock.conf', - 'hyprpaper.conf', - 'hyprshade.conf', - } - local util = require 'lspconfig/util' - local root = util.root_pattern(unpack(root_files))(fname) or util.path.dirname(fname) - if root and string.match( root, '~/.config/hypr/' ) then - return root - else - return nil - end - end, - filetypes = { 'conf' }, + root_dir = vim.fs.root( 0, 'hyprland.conf' ), + single_file_support = false, + filetypes = { "conf" }, } -- lsps with default config diff --git a/lua/configs/notify.lua b/lua/configs/notify.lua new file mode 100644 index 0000000..3a4b6cf --- /dev/null +++ b/lua/configs/notify.lua @@ -0,0 +1,142 @@ +vim.notify = require('notify') +local dap = require('dap') + +require('notify').setup({ + max_width = 40, +}) + +-- Utility functions shared between progress reports for LSP and DAP + +local client_notifs = {} + +local function get_notif_data(client_id, token) + if not client_notifs[client_id] then + client_notifs[client_id] = {} + end + + if not client_notifs[client_id][token] then + client_notifs[client_id][token] = {} + end + + return client_notifs[client_id][token] +end + + +local spinner_frames = { "⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷" } + +local function update_spinner(client_id, token) + local notif_data = get_notif_data(client_id, token) + + if notif_data.spinner then + local new_spinner = (notif_data.spinner + 1) % #spinner_frames + notif_data.spinner = new_spinner + + notif_data.notification = vim.notify(nil, nil, { + hide_from_history = true, + icon = spinner_frames[new_spinner], + replace = notif_data.notification, + }) + + vim.defer_fn(function() + update_spinner(client_id, token) + end, 100) + end +end + +local function format_title(title, client_name) + return client_name .. (#title > 0 and ": " .. title or "") +end + +local function format_message(message, percentage) + return (percentage and percentage .. "%\t" or "") .. (message or "") +end + +-- LSP integration +-- Make sure to also have the snippet with the common helper functions in your config! + +vim.lsp.handlers["$/progress"] = function(_, result, ctx) + local client_id = ctx.client_id + + local val = result.value + + if not val.kind then + return + end + + local notif_data = get_notif_data(client_id, result.token) + + if val.kind == "begin" then + local message = format_message(val.message, val.percentage) + + notif_data.notification = vim.notify(message, "info", { + title = format_title(val.title, vim.lsp.get_client_by_id(client_id).name), + icon = spinner_frames[1], + timeout = false, + hide_from_history = false, + }) + + notif_data.spinner = 1 + update_spinner(client_id, result.token) + elseif val.kind == "report" and notif_data then + notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", { + replace = notif_data.notification, + hide_from_history = false, + }) + elseif val.kind == "end" and notif_data then + notif_data.notification = + vim.notify(val.message and format_message(val.message) or "Complete", "info", { + icon = "", + replace = notif_data.notification, + timeout = 3000, + }) + + notif_data.spinner = nil + end +end + +-- table from lsp severity to vim severity. +local severity = { + "error", + "warn", + "info", + "info", -- map both hint and info to info? +} +vim.lsp.handlers["window/showMessage"] = function(err, method, params, client_id) + vim.notify(method.message, severity[params.type]) +end + +-- DAP integration +-- Make sure to also have the snippet with the common helper functions in your config! + +dap.listeners.before['event_progressStart']['progress-notifications'] = function(session, body) + local notif_data = get_notif_data("dap", body.progressId) + + local message = format_message(body.message, body.percentage) + notif_data.notification = vim.notify(message, "info", { + title = format_title(body.title, session.config.type), + icon = spinner_frames[1], + timeout = false, + hide_from_history = false, + }) + + notif_data.notification.spinner = 1, + update_spinner("dap", body.progressId) +end + +dap.listeners.before['event_progressUpdate']['progress-notifications'] = function(session, body) + local notif_data = get_notif_data("dap", body.progressId) + notif_data.notification = vim.notify(format_message(body.message, body.percentage), "info", { + replace = notif_data.notification, + hide_from_history = false, + }) +end + +dap.listeners.before['event_progressEnd']['progress-notifications'] = function(session, body) + local notif_data = client_notifs["dap"][body.progressId] + notif_data.notification = vim.notify(body.message and format_message(body.message) or "Complete", "info", { + icon = "", + replace = notif_data.notification, + timeout = 3000 + }) + notif_data.spinner = nil +end diff --git a/lua/configs/set.lua b/lua/configs/set.lua index 8f7229f..9cf8241 100644 --- a/lua/configs/set.lua +++ b/lua/configs/set.lua @@ -20,10 +20,48 @@ vim.opt.incsearch = true vim.opt.termguicolors = true vim.opt.scrolloff = 8 -vim.opt.signcolumn = "yes" +vim.opt.signcolumn = "yes:1" vim.opt.isfname:append("@-@") vim.opt.updatetime = 50 vim.opt.colorcolumn = "80" +vim.opt.textwidth = 80 +vim.opt.formatoptions = "tcrqnja" + +vim.o.sessionoptions = "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions" + +vim.o.laststatus = 3 + +vim.o.clipboard = "unnamedplus" +vim.o.cursorline = true +vim.o.cursorlineopt = "number" + +vim.opt.fillchars = { eob = " " } +vim.o.ignorecase = true +vim.o.smartcase = true +vim.o.mouse = "a" + +vim.o.number = true +vim.o.numberwidth = 3 +vim.o.ruler = false + +vim.opt.shortmess:append "sI" + +vim.o.splitbelow = true +vim.o.splitright = true +vim.o.timeoutlen = 400 + +vim.opt.whichwrap:append "<>[]hl" + +vim.g.loaded_node_provider = 0 +vim.g.loaded_python3_provider = 0 +vim.g.loaded_perl_provider = 0 +vim.g.loaded_ruby_provider = 0 + +-- add binaries installed by mason.nvim to path +local is_windows = vim.fn.has "win32" ~= 0 +local sep = is_windows and "\\" or "/" +local delim = is_windows and ";" or ":" +vim.env.PATH = table.concat({ vim.fn.stdpath "data", "mason", "bin" }, sep) .. delim .. vim.env.PATH diff --git a/lua/options.lua b/lua/options.lua index 738f20b..9fdb808 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -2,5 +2,4 @@ require "nvchad.options" -- add yours here! --- local o = vim.o --- o.cursorlineopt ='both' -- to enable cursorline! +-- local o = vim.o o.cursorlineopt ='both' -- to enable cursorline! diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 48c5e76..e63eabd 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -89,6 +89,13 @@ return { { "lambdalisue/vim-suda" }, + { + "rcarriga/nvim-notify", + config = function() + require "configs.notify" + end, + }, + { "ojroques/nvim-bufdel", opts = { @@ -121,46 +128,9 @@ return { { "rmagatti/auto-session", - opts = { - enabled = true, - root_dir = vim.fn.stdpath "data" .. "/sessions/", - auto_save = true, - auto_restore = true, - auto_create = true, - suppressed_dirs = nil, - allowed_dirs = nil, - auto_restore_last_session = false, - use_git_branch = false, - lazy_support = true, - bypass_save_filetypes = nil, - close_unsupported_windows = true, - args_allow_single_directory = true, - args_allow_files_auto_save = false, - continue_restore_on_error = true, - show_auto_restore_notif = false, - cwd_change_handling = false, - lsp_stop_on_restore = false, - log_level = "error", - - session_lens = { - load_on_setup = true, - theme_conf = { - -- test - }, - previewer = false, - - mappings = { - delete_session = { "i", "" }, - alternate_session = { "i", "" }, - copy_session = { "i", "" }, - }, - - session_control = { - control_dir = vim.fn.stdpath "data" .. "/auto_session/", - control_filename = "session_control.json", - }, - }, - }, + config = function() + require "configs.auto-session" + end, }, {