From adcd62176366eb410d30b7cddb8e5e2e42595ade Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Thu, 10 Oct 2024 00:21:39 -0700 Subject: [PATCH] feat: add a bunch of stuff --- flake.lock | 36 ++++- flake.nix | 84 ++++++++--- init.lua | 37 ++++- lua/keymaps.lua | 39 +++++ lua/lsp/init.lua | 36 +++-- lua/plugins/harpoon.lua | 45 ++++++ lua/plugins/init.lua | 7 - lua/plugins/lualine.lua | 58 +++++++ lua/plugins/lz-spec.lua | 310 +++++++++++++++++++++++++++++++++++++- lua/plugins/oil.lua | 39 +++++ lua/plugins/telescope.lua | 36 +++++ lua/scripts/autoroot.lua | 27 ++++ 12 files changed, 700 insertions(+), 54 deletions(-) create mode 100644 lua/plugins/harpoon.lua create mode 100644 lua/plugins/lualine.lua create mode 100644 lua/plugins/oil.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/scripts/autoroot.lua diff --git a/flake.lock b/flake.lock index f46ce3b..826d182 100644 --- a/flake.lock +++ b/flake.lock @@ -649,6 +649,38 @@ "type": "github" } }, + "plugins-lsp-progress": { + "flake": false, + "locked": { + "lastModified": 1721008335, + "narHash": "sha256-OafRT5AnxRTOh7MYofRFjti0+pobKQihymZs/kr5w0A=", + "owner": "linrongbin16", + "repo": "lsp-progress.nvim", + "rev": "d5f4d28efe75ce636bfbe271eb45f39689765aab", + "type": "github" + }, + "original": { + "owner": "linrongbin16", + "repo": "lsp-progress.nvim", + "type": "github" + } + }, + "plugins-typst-preview": { + "flake": false, + "locked": { + "lastModified": 1727642175, + "narHash": "sha256-n0TfcXJLlRXdS6S9dwYHN688IipVSDLVXEqyYs+ROG8=", + "owner": "chomosuke", + "repo": "typst-preview.nvim", + "rev": "0354cc1a7a5174a2e69cdc21c4db9a3ee18bb20a", + "type": "github" + }, + "original": { + "owner": "chomosuke", + "repo": "typst-preview.nvim", + "type": "github" + } + }, "poetry2nix": { "inputs": { "flake-utils": "flake-utils", @@ -750,7 +782,9 @@ "inputs": { "blink-cmp": "blink-cmp", "nixCats": "nixCats", - "nixpkgs": "nixpkgs_4" + "nixpkgs": "nixpkgs_4", + "plugins-lsp-progress": "plugins-lsp-progress", + "plugins-typst-preview": "plugins-typst-preview" } }, "rust-analyzer-src": { diff --git a/flake.nix b/flake.nix index 5d28f3e..e774812 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,16 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + plugins-typst-preview = { + url = "github:chomosuke/typst-preview.nvim"; + flake = false; + }; + + plugins-lsp-progress = { + url = "github:linrongbin16/lsp-progress.nvim"; + flake = false; + }; + # see :help nixCats.flake.inputs # If you want your plugin to be loaded by the standard overlay, # i.e. if it wasnt on nixpkgs, but doesnt have an extra build step. @@ -132,23 +142,23 @@ # this includes LSPs lspsAndRuntimeDeps = { general = with pkgs; [ - lua-language-server + # essential ripgrep python312Packages.pylatexenc + fd + + # lsps / formatters + lua-language-server + nixd + nixfmt-rfc-style ]; }; - # plugins that will load at startup + # install lz.n and treesitter grammars startupPlugins = { gitPlugins = with pkgs.neovimPlugins; [ ]; general = with pkgs.vimPlugins; [ lz-n - telescope-nvim - markdown-preview-nvim - render-markdown-nvim - which-key-nvim - rose-pine - nvim-web-devicons (nvim-treesitter.withPlugins ( p: (with p; [ @@ -165,6 +175,7 @@ toml yaml markdown + markdown_inline svelte css html @@ -176,16 +187,45 @@ ]; }; - # plugins which are installed and will be lazy-loaded by lz.n + # plugins which are installed, but not loaded, and will be handled by + # lz.n (not necessarily lazy loaded) optionalPlugins = { gitPlugins = with pkgs.neovimPlugins; [ inputs.blink-cmp.packages.${pkgs.system}.default + typst-preview + lsp-progress ]; general = with pkgs.vimPlugins; [ nvim-autopairs nvim-lspconfig intellitab-nvim sleuth + which-key-nvim + telescope-nvim + markdown-preview-nvim + render-markdown-nvim + rose-pine + nvim-web-devicons + oil-nvim + telescope-ui-select-nvim + harpoon2 + toggleterm-nvim + trouble-nvim + lualine-nvim + mini-ai + mini-hipatterns + mini-surround + mini-notify + mini-starter + mini-trailspace + cellular-automaton-nvim + indent-blankline-nvim + mini-bufremove + neogit + gitsigns-nvim + diffview-nvim + barbecue-nvim + undotree ]; }; @@ -222,13 +262,13 @@ # in your lua config via # vim.g.python3_host_prog # or run from nvim terminal via :!-python3 - extraPython3Packages = { - test = (_: [ ]); - }; - # populates $LUA_PATH and $LUA_CPATH - extraLuaPackages = { - test = [ (_: [ ]) ]; - }; + # extraPython3Packages = { + # test = (_: [ ]); + # }; + # # populates $LUA_PATH and $LUA_CPATH + # extraLuaPackages = { + # test = [ (_: [ ]) ]; + # }; }; # And then build a package with specific categories from above here: @@ -261,15 +301,9 @@ general = true; gitPlugins = true; customPlugins = true; - test = true; - example = { - youCan = "add more than just booleans"; - toThisSet = [ - "and the contents of this categories set" - "will be accessible to your lua with" - "nixCats('path.to.value')" - "see :help nixCats" - ]; + bin = { + websocat = "${pkgs.websocat}/bin/websocat"; + tinymist = "${pkgs.tinymist}/bin/tinymist"; }; }; }; diff --git a/init.lua b/init.lua index 547252f..e9ef5af 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,8 @@ +require("keymaps") require("plugins") +require("scripts.autoroot") + vim.opt.relativenumber = true vim.opt.number = true @@ -16,4 +19,36 @@ vim.opt.foldexpr = "nvim_treesitter#foldexpr()" vim.opt.foldmethod = "expr" vim.opt.foldenable = false -vim.cmd("colorscheme rose-pine") +vim.cmd.colorscheme("rose-pine") + +require('nvim-treesitter.configs').setup({ + ensure_installed = {}, + sync_install = false, + auto_install = false, + modules = {"highlight", "incremental_selection", "indent"}, + ignore_install = {}, + highlight = { enable = true }, + disable = function(_, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + additional_vim_regex_highlighting = false +}) + +vim.api.nvim_create_autocmd({ + "TermOpen", +}, { + group = vim.api.nvim_create_augroup("terminal", {}), + callback = function() + vim.cmd("setlocal nonumber norelativenumber") + end, +}) + +vim.api.nvim_create_autocmd("TextYankPost", { + callback = function() + vim.highlight.on_yank {higroup='Visual', timeout=300} + end, +}) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index b3189c6..5f3ded1 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -1,2 +1,41 @@ -- Non-exhaustive collection of keymaps. I've decided it's more sane to place -- plugin specific maps in their respective setup scripts + +vim.g.mapleader = " " +vim.keymap.set("n", "", "") + +vim.keymap.set("t", "", "") + +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") + +vim.keymap.set("n", "mr", function () + vim.cmd.CellularAutomaton("make_it_rain") +end) +vim.keymap.set("n", "bruh", function () + vim.cmd.CellularAutomaton("game_of_life") +end) + +-- when searching, also center screen and reopen folds +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +-- The greatest remap of all time -- the primeagen +vim.keymap.set({"n", "v"}, "d",'"_d', { desc = "same as `d` but send to black hole register"}) +vim.keymap.set({"n", "v"}, "D",'"_D', { desc = "same as `D` but send to black hole register"}) +-- The real greatest remap(s) of all time -- me +vim.keymap.set({"n", "v"}, "y",'"+y', { desc = "yank to clipboard"}) +vim.keymap.set({"n", "v"}, "Y",'"+Y', { desc = "yank rest of line to clipboard"}) +vim.keymap.set({"n", "v"}, "p",'"+p', { desc = "put after cursor from clipboard"}) +vim.keymap.set({"n", "v"}, "P",'"+P', { desc = "put before cursor from clipboard"}) + +vim.keymap.set("n", "gg", function () + vim.cmd.Neogit() +end, { desc = "Open neogit" }) +vim.keymap.set("n", "gc", function () + vim.cmd.Neogit("kind=floating commit") +end, { desc = "Open neogit commit menu" }) + +vim.keymap.set("n", "u", function () + vim.cmd.UndotreeToggle() +end, {desc = "Toggle undotree"}) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index a6f22b2..ba14a63 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,22 +1,26 @@ local lspconfig = require("lspconfig") lspconfig.lua_ls.setup({ - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim", "nixCats", "MiniBufremove" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, }, }, }) + +lspconfig.nixd.setup({}) diff --git a/lua/plugins/harpoon.lua b/lua/plugins/harpoon.lua new file mode 100644 index 0000000..1d06535 --- /dev/null +++ b/lua/plugins/harpoon.lua @@ -0,0 +1,45 @@ +return { + "harpoon2", + after = function() + local harpoon = require("harpoon") + + vim.keymap.set("n", "a", function() + harpoon:list():add() + end) + vim.keymap.set("n", "", function() + harpoon:list():select(1) + end) + vim.keymap.set("n", "", function() + harpoon:list():select(2) + end) + vim.keymap.set("n", "", function() + harpoon:list():select(3) + end) + vim.keymap.set("n", "", function() + harpoon:list():select(4) + end) + + local conf = require("telescope.config").values + local function toggle_telescope(harpoon_files) + local file_paths = {} + for _, item in ipairs(harpoon_files.items) do + table.insert(file_paths, item.value) + end + + require("telescope.pickers") + .new({}, { + prompt_title = "Harpoon", + finder = require("telescope.finders").new_table({ + results = file_paths, + }), + previewer = conf.file_previewer({}), + sorter = conf.generic_sorter({}), + }) + :find() + end + + vim.keymap.set("n", "", function() + toggle_telescope(harpoon:list()) + end, { desc = "Open harpoon window" }) + end, + } diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index a6a4476..c78e7cb 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -3,10 +3,3 @@ vim.loader.enable() local pluginSpec = require("plugins.lz-spec") require("lz.n").load(pluginSpec) - --- require("markview").setup({ --- codeblocks = { --- icons = "devicons", --- }, --- filetypes = {"markdown", "quarto", "rmd", "nofile"} --- }) diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..ffee655 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,58 @@ +return { + "lualine.nvim", + event = "BufEnter", + after = function() + require("lualine").setup({ + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { + statusline = { "ministarter" }, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = true, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + }, + }, + sections = { + lualine_a = { "branch" }, + lualine_b = { + function() + return require("lsp-progress").progress() + end, + }, + lualine_c = { "progress", "filetype" }, + lualine_x = { "encoding", "fileformat" }, + lualine_y = { "diff", "diagnostics" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {}, + }) +-- listen lsp-progress event and refresh lualine +vim.api.nvim_create_augroup("lualine_augroup", { clear = true }) +vim.api.nvim_create_autocmd("User", { + group = "lualine_augroup", + pattern = "LspProgressStatusUpdated", + callback = require("lualine").refresh, +}) + end, + +} diff --git a/lua/plugins/lz-spec.lua b/lua/plugins/lz-spec.lua index 0fef26b..b6a3860 100644 --- a/lua/plugins/lz-spec.lua +++ b/lua/plugins/lz-spec.lua @@ -1,5 +1,64 @@ return { require("plugins.blink-cmp"), + require("plugins.telescope"), + require("plugins.oil"), + require("plugins.harpoon"), + require("plugins.lualine"), + { "lsp-progress", + after = function() + require("lsp-progress").setup({ + client_format = function(client_name, spinner, series_messages) + if #series_messages == 0 then + return nil + end + return { + name = client_name, + body = spinner .. " " .. table.concat(series_messages, ", "), + } + end, + format = function(client_messages) + --- @param name string + --- @param msg string? + --- @return string + local function stringify(name, msg) + return msg and string.format("%s %s", name, msg) or name + end + + local sign = "󰆧" -- nf-fa-gear \uf013 + local lsp_clients = vim.lsp.get_clients() + local messages_map = {} + for _, climsg in ipairs(client_messages) do + messages_map[climsg.name] = climsg.body + end + + if #lsp_clients > 0 then + table.sort(lsp_clients, function(a, b) + return a.name < b.name + end) + local builder = {} + for _, cli in ipairs(lsp_clients) do + if + type(cli) == "table" + and type(cli.name) == "string" + and string.len(cli.name) > 0 + then + if messages_map[cli.name] then + table.insert(builder, stringify(cli.name, messages_map[cli.name])) + else + table.insert(builder, stringify(cli.name)) + end + end + end + if #builder > 0 then + return sign .. " " .. table.concat(builder, ", ") + end + end + return "" + end, + }) + end + }, + { "telescope-ui-select.nvim", priority = 70 }, { "nvim-autopairs", event = "BufEnter", @@ -14,12 +73,255 @@ return { require("lsp") end, }, - { - "intellitab-nvim", - keys = "tab", - }, { "sleuth", event = "BufEnter", }, + { + "which-key.nvim", + after = function() + require("which-key").setup({ + delay = 1000, + }) + end, + }, + { "nvim-web-devicons" }, + { "rose-pine" }, + { "render-markdown.nvim" }, + { "markdown-preview.nvim" }, + { + "trouble.nvim", + event = "LspAttach", + after = function() + require("trouble").setup() + vim.keymap.set("n", "xx", function() + vim.cmd("Trouble diagnostics toggle") + end, { desc = "Diagnostics" }) + vim.keymap.set("n", "xX", function() + vim.cmd("Trouble diagnostics toggle filter.buf=0") + end, { desc = "Buffer diagnostics" }) + vim.keymap.set("n", "cs", function() + vim.cmd("Trouble symbols toggle") + end, { desc = "Symbols" }) + vim.keymap.set("n", "cl", function() + vim.cmd("Trouble lsp toggle win.position=right") + end, { desc = "LSP definitions / references /..." }) + vim.keymap.set("n", "ql", function() + vim.cmd("Trouble qflist toggle") + end, { desc = "Quickfix list (trouble)" }) + end, + }, + { + "typst-preview", + after = function() + require("typst-preview").setup({ + dependencies_bin = { + ["typst-preview"] = nixCats("bin.tinymist"), + ["websocat"] = nixCats("bin.websocat"), + }, + }) + end, + }, + { + "toggleterm.nvim", + after = function() + require("toggleterm").setup({ + shade_terminals = false, + }) + + vim.keymap.set({ "n", "t", "v" }, "", function() + vim.cmd("ToggleTerm direction=float") + end) + vim.keymap.set("n", "tv", function() + vim.cmd("ToggleTerm direction=vertical") + end) + vim.keymap.set("n", "tt", function() + vim.cmd("ToggleTerm direction=horizontal") + end) + vim.keymap.set("n", "ts", function() + vim.cmd("TermSelect") + end) + end, + }, + { + "mini.ai", + event = "BufEnter", + after = function() + require("mini.ai").setup() + end + }, + { + "mini.surround", + event = "BufEnter", + after = function() + require("mini.surround").setup() + end + }, + { + "mini.starter", + after = function () + require("mini.starter").setup() + end + }, + { + "mini.notify", + event = "BufEnter", + after = function () + require("mini.notify").setup({ + lsp_progress = { enable = false } + }) + end + }, + { + "mini.trailspace", + event = "BufEnter", + after = function () + require("mini.trailspace").setup() + end + }, + { + "cellular-automaton.nvim", + cmd = "CellularAutomaton", + }, + { + "indent-blankline.nvim", + after = function () + require("ibl").setup({ + indent = { + char = "│", + tab_char = "│", + }, + scope = { show_start = false, show_end = false }, + exclude = { + filetypes = { + "help", + "ministarter", + "Trouble", + "trouble", + "toggleterm", + }, + }, + } + ) + end + }, + { + "mini.bufremove", + event = "BufEnter", + after = function () + require("mini.bufremove").setup() + + vim.keymap.set({"n", "v"}, "bd", function () + MiniBufremove.delete() + end) + end + }, + { + "mini.hipatterns", + event = "BufEnter", + after = function () + require("mini.hipatterns").setup() + end + }, + { + "gitsigns.nvim", + event = "BufEnter", + after = function () + require('gitsigns').setup{ + on_attach = function(bufnr) + local gitsigns = require('gitsigns') + + local function map(mode, l, r, opts) + opts = opts or {} + opts.buffer = bufnr + vim.keymap.set(mode, l, r, opts) + end + + -- Navigation + map('n', ']c', function() + if vim.wo.diff then + vim.cmd.normal({']c', bang = true}) + else + gitsigns.nav_hunk('next') + end + end) + + map('n', '[c', function() + if vim.wo.diff then + vim.cmd.normal({'[c', bang = true}) + else + gitsigns.nav_hunk('prev') + end + end) + + -- Actions + map('n', 'gs', gitsigns.stage_hunk) + map('n', 'gr', gitsigns.reset_hunk) + map('v', 'gs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('v', 'gr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end) + map('n', 'gS', gitsigns.stage_buffer) + map('n', 'gu', gitsigns.undo_stage_hunk) + map('n', 'gR', gitsigns.reset_buffer) + map('n', 'gp', gitsigns.preview_hunk) + map('n', 'gb', function() gitsigns.blame_line{full=true} end) + map('n', 'gb', gitsigns.toggle_current_line_blame) + map('n', 'gd', gitsigns.diffthis) + map('n', 'gD', function() gitsigns.diffthis('~') end) + map('n', 'gtd', gitsigns.toggle_deleted) + + -- Text object + map({'o', 'x'}, 'ih', ':Gitsigns select_hunk') + end } + end + }, + { + "neogit", + cmd = "Neogit", + after = function () + require("neogit").setup({ + graph_style = "unicode", + integrations = { + telescope = true, + diffview = true + } + }) + end + }, + { + "diffiew.nvim", + cmd = {"DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles", "DiffviewRefresh"}, + }, + { + "barbecue.nvim", + event = "BufEnter", + after = function() + require("barbecue").setup() + -- triggers CursorHold event faster + vim.opt.updatetime = 200 + + require("barbecue").setup({ + create_autocmd = false, -- prevent barbecue from updating itself automatically + }) + + vim.api.nvim_create_autocmd({ + "WinResized", + "BufWinEnter", + "CursorHold", + "InsertLeave", + + -- include this if you have set `show_modified` to `true` + "BufModifiedSet", + }, { + group = vim.api.nvim_create_augroup("barbecue.updater", {}), + callback = function() + require("barbecue.ui").update() + end, + }) + end + }, + { + "undotree", + cmd = "UndotreeToggle" + } + } diff --git a/lua/plugins/oil.lua b/lua/plugins/oil.lua new file mode 100644 index 0000000..8e3fde4 --- /dev/null +++ b/lua/plugins/oil.lua @@ -0,0 +1,39 @@ +return { + "oil.nvim", + after = function() + require("oil").setup({ + columns = { + "size", + "icon", + }, + use_default_keymaps = false, + keymaps = { + ["J"] = "actions.parent", + ["Q"] = "actions.close", + [""] = "actions.select_split", + [""] = "actions.refresh", + [""] = "actions.preview", + [""] = "actions.select_vsplit", + [""] = "actions.select_tab", + [""] = "actions.select", + ["K"] = "actions.select", + ["_"] = "actions.open_cwd", + ["`"] = "actions.cd", + ["g."] = "actions.toggle_hidden", + ["g?"] = "actions.show_help", + ["g\\"] = "actions.toggle_trash", + ["gs"] = "actions.change_sort", + ["gx"] = "actions.open_external", + ["~"] = "actions.tcd", + }, + }) + + vim.keymap.set("n", "e", function() + vim.cmd("Oil") + end, { desc = "Open file explorer in current file directory" }) + + vim.keymap.set("n", "fe", function() + vim.cmd("Oil " .. vim.fn.getcwd()) + end, { desc = "Open file explorer in current working directory" }) + end, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..ce69eb4 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,36 @@ +return { + "telescope.nvim", + after = function() + require("telescope").setup({ + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown({}), + }, + }, + }) + + require("telescope").load_extension("ui-select") + + local builtin = require("telescope.builtin") + + vim.keymap.set("n", " ", function() + local is_git = vim.fn.finddir(".git", vim.fn.getcwd() .. ";") + if is_git then + builtin.git_files() + else + builtin.find_files() + end + end, { desc = "Grep through all files tracked by git, or fall back to just cwd" }) + + vim.keymap.set("n", "ff", builtin.find_files, { desc = "Grep through all files in cwd" }) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action) + vim.keymap.set("n", "/", builtin.live_grep) + vim.keymap.set("n", "k", builtin.buffers) + vim.keymap.set("n", "gd", builtin.lsp_definitions, { desc = "Go to LSP definition" }) + vim.keymap.set("n", "gi", builtin.lsp_implementations, { desc = "Go to implementations" }) + vim.keymap.set("n", "j", builtin.lsp_document_symbols, { desc = "Search through document symbols" }) + vim.keymap.set("n", "fs", builtin.lsp_workspace_symbols, { desc = "Search through entire workspace symbols" }) + vim.keymap.set("n", "fd", builtin.diagnostics, { desc = "Search through LSP diagnostics" }) + end, + priority = 60 +} diff --git a/lua/scripts/autoroot.lua b/lua/scripts/autoroot.lua new file mode 100644 index 0000000..09e1212 --- /dev/null +++ b/lua/scripts/autoroot.lua @@ -0,0 +1,27 @@ +-- Array of file names indicating root directory. Modify to your liking. +local root_names = { '.git', 'Makefile', '.svn', '.hg' } + +-- Cache to use for speed up (at cost of possibly outdated results) +local root_cache = {} + +local set_root = function() + -- Get directory path to start search from + local path = vim.api.nvim_buf_get_name(0) + if path == "" then return end + path = vim.fs.dirname(path) + + -- Try cache and resort to searching upward for root directory + local root = root_cache[path] + if root == nil then + local root_file = vim.fs.find(root_names, { path = path, upward = true })[1] + if root_file == nil then return end + root = vim.fs.dirname(root_file) + root_cache[path] = root + end + + -- Set current directory + vim.fn.chdir(root) +end + +local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {}) +vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root })