Compare commits
3 commits
feed555e48
...
45e9b409d3
Author | SHA1 | Date | |
---|---|---|---|
45e9b409d3 | |||
904e29db71 | |||
1757b0b11f |
9 changed files with 164 additions and 205 deletions
|
@ -48,6 +48,9 @@ with final.pkgs.lib; let
|
|||
lualine-nvim
|
||||
noice-nvim
|
||||
indent-blankline-nvim
|
||||
|
||||
# Editor
|
||||
neo-tree-nvim
|
||||
];
|
||||
|
||||
extraPackages = with pkgs; [
|
||||
|
|
|
@ -5,6 +5,8 @@ vim.cmd.filetype('plugin', 'indent', 'on')
|
|||
---@diagnostic disable-next-line:missing-parameter
|
||||
vim.g.sqlite_clib_path = require('luv').os_getenv('LIBSQLITE')
|
||||
|
||||
_G.MarleyVim = require('lib')
|
||||
|
||||
require('options')
|
||||
require('keymaps')
|
||||
require('autocmds')
|
||||
|
|
|
@ -14,5 +14,7 @@ return {
|
|||
added = ' ',
|
||||
modified = ' ',
|
||||
removed = ' ',
|
||||
unstaged = '',
|
||||
staged = '',
|
||||
},
|
||||
}
|
||||
|
|
22
nvim/lua/lib/init.lua
Normal file
22
nvim/lua/lib/init.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
---@class lib
|
||||
local M = {}
|
||||
|
||||
---Find the root of a project based on `vim.g.root_spec`. Defaults to
|
||||
---`{ '.git' }` if unset.
|
||||
---@return string?
|
||||
function M.root()
|
||||
local root_spec = vim.g.root_spec or { '.git' }
|
||||
|
||||
return vim.fs.root(0, root_spec)
|
||||
end
|
||||
|
||||
---Require a file relative to the given prefix, to avoid repetition.
|
||||
---@param prefix string The string to prefix to all req calls.
|
||||
function M.local_require(prefix)
|
||||
---@param mod string The module to require.
|
||||
return function(mod)
|
||||
return require(prefix .. '.' .. mod)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
|
@ -1,197 +0,0 @@
|
|||
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/util/root.lua
|
||||
|
||||
local lazy_util = require('lib.lazy.util')
|
||||
local lazyvim_lsp = require('lib.lazyvim.lsp')
|
||||
|
||||
---@class lib.lazyvim.root
|
||||
---@overload fun(): string
|
||||
local M = setmetatable({}, {
|
||||
__call = function(m)
|
||||
return m.get()
|
||||
end,
|
||||
})
|
||||
|
||||
---@class LazyRoot
|
||||
---@field paths string[]
|
||||
---@field spec LazyRootSpec
|
||||
|
||||
---@alias LazyRootFn fun(buf:number): (string|string[])
|
||||
---@alias LazyRootSpec string|string[]|LazyRootFn
|
||||
|
||||
---@type LazyRootSpec[]
|
||||
M.spec = { 'lsp', { '.git', 'lua' }, 'cwd' }
|
||||
|
||||
M.detectors = {}
|
||||
|
||||
function M.detectors.cwd()
|
||||
return { vim.uv.cwd() }
|
||||
end
|
||||
|
||||
function M.realpath(path)
|
||||
if path == '' or path == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
path = vim.uv.fs_realpath(path) or path
|
||||
|
||||
return lazy_util.norm(path)
|
||||
end
|
||||
|
||||
function M.bufpath(buf)
|
||||
return M.realpath(vim.api.nvim_buf_get_name(assert(buf)))
|
||||
end
|
||||
|
||||
function M.detectors.lsp(buf)
|
||||
local bufpath = M.bufpath(buf)
|
||||
|
||||
if not bufpath then
|
||||
return {}
|
||||
end
|
||||
|
||||
local roots = {} ---@type string[]
|
||||
local clients = lazyvim_lsp.get_clients({ bufnr = buf })
|
||||
|
||||
clients = vim.tbl_filter(function(client)
|
||||
return not vim.tbl_contains(vim.g.root_lsp_ignore or {}, client.name)
|
||||
end, clients)
|
||||
|
||||
for _, client in pairs(clients) do
|
||||
local workspace = client.config.workspace_folders
|
||||
|
||||
for _, ws in pairs(workspace or {}) do
|
||||
roots[#roots + 1] = vim.uri_to_fname(ws.uri)
|
||||
end
|
||||
|
||||
if client.root_dir then
|
||||
roots[#roots + 1] = client.root_dir
|
||||
end
|
||||
end
|
||||
|
||||
return vim.tbl_filter(function(path)
|
||||
path = lazy_util.norm(path)
|
||||
|
||||
return path and bufpath:find(path, 1, true) == 1
|
||||
end, roots)
|
||||
end
|
||||
|
||||
---@param patterns string[]|string
|
||||
function M.detectors.pattern(buf, patterns)
|
||||
if type(patterns) == 'string' then
|
||||
patterns = { patterns }
|
||||
end
|
||||
|
||||
local path = M.bufpath(buf) or vim.uv.cwd()
|
||||
local pattern = vim.fs.find(function(name)
|
||||
for _, p in ipairs(patterns) do
|
||||
if name == p then
|
||||
return true
|
||||
end
|
||||
|
||||
if p:sub(1, 1) == '*' and name:find(vim.pesc(p:sub(2)) .. '$') then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end, { path = path, upward = true })[1]
|
||||
|
||||
return pattern and { vim.fs.dirname(pattern) } or {}
|
||||
end
|
||||
|
||||
---@param spec LazyRootSpec
|
||||
---@return LazyRootFn
|
||||
function M.resolve(spec)
|
||||
if M.detectors[spec] then
|
||||
return M.detectors[spec]
|
||||
elseif type(spec) == 'function' then
|
||||
return spec
|
||||
end
|
||||
|
||||
return function(buf)
|
||||
return M.detectors.pattern(buf, spec)
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts? {buf?:number, spec?:LazyRootSpec[], all?:boolean}
|
||||
function M.detect(opts)
|
||||
opts = opts or {}
|
||||
opts.spec = opts.spec
|
||||
or type(vim.g.root_spec) == 'table' and vim.g.root_spec
|
||||
or M.spec
|
||||
opts.buf = (opts.buf == nil or opts.buf == 0)
|
||||
and vim.api.nvim_get_current_buf()
|
||||
or opts.buf
|
||||
|
||||
local ret = {} ---@type LazyRoot[]
|
||||
|
||||
for _, spec in ipairs(opts.spec) do
|
||||
local paths = M.resolve(spec)(opts.buf)
|
||||
|
||||
paths = paths or {}
|
||||
paths = type(paths) == 'table' and paths or { paths }
|
||||
|
||||
local roots = {} ---@type string[]
|
||||
|
||||
for _, p in ipairs(paths) do
|
||||
local pp = M.realpath(p)
|
||||
|
||||
if pp and not vim.tbl_contains(roots, pp) then
|
||||
roots[#roots + 1] = pp
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(roots, function(a, b)
|
||||
return #a > #b
|
||||
end)
|
||||
|
||||
if #roots > 0 then
|
||||
ret[#ret + 1] = { spec = spec, paths = roots }
|
||||
|
||||
if opts.all == false then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
---@type table<number, string>
|
||||
M.cache = {}
|
||||
|
||||
-- Returns the root directory based on:
|
||||
-- * lsp workspace folders
|
||||
-- * lsp root_dir
|
||||
-- * root pattern of filename of the current buffer
|
||||
-- * root pattern of cwd
|
||||
---@param opts? {normalize?:boolean, buf?:number}
|
||||
function M.get(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local buf = opts.buf or vim.api.nvim_get_current_buf()
|
||||
local ret = M.cache[buf]
|
||||
|
||||
if not ret then
|
||||
local roots = M.detect({ all = false, buf = buf })
|
||||
|
||||
ret = roots[1] and roots[1].paths[1] or vim.uv.cwd()
|
||||
|
||||
M.cache[buf] = ret
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
function M.git()
|
||||
local root = M.get()
|
||||
local git_root = vim.fs.find('.git', { path = root, upward = true })[1]
|
||||
local ret = git_root and vim.fn.fnamemodify(git_root, ':h') or root
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
function M.cwd()
|
||||
return M.realpath(vim.uv.cwd()) or ''
|
||||
end
|
||||
|
||||
return M
|
|
@ -2,11 +2,8 @@ local g = vim.g
|
|||
local opt = vim.opt
|
||||
|
||||
-- Root dir detection options.
|
||||
-- Each entry can be:
|
||||
-- * the name of a detector function like `lsp` or `cwd`
|
||||
-- * a pattern or array of patterns like `.git` or `lua`
|
||||
-- * a function with signature `function(buf) -> string|string[]`
|
||||
g.root_spec = { 'lsp', { '.git', 'lua' }, 'cwd' }
|
||||
-- Each entry can be a pattern `.git` or `package.json`
|
||||
g.root_spec = { '.git', 'package.json' }
|
||||
|
||||
-- Only set clipboard if not in SSH, to make sure the OSC 52 integration works
|
||||
-- automatically. Requires Neovim >= 0.10.0.
|
||||
|
|
5
nvim/lua/plugins/editor/init.lua
Normal file
5
nvim/lua/plugins/editor/init.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
local req = require('lib.marleyvim').localRequire('plugins.editor')
|
||||
|
||||
return {
|
||||
req('neo-tree-nvim'),
|
||||
}
|
126
nvim/lua/plugins/editor/neo-tree-nvim.lua
Normal file
126
nvim/lua/plugins/editor/neo-tree-nvim.lua
Normal file
|
@ -0,0 +1,126 @@
|
|||
---@param root? boolean
|
||||
---@param grouped? boolean
|
||||
local function make_toggle_mapping(root, grouped)
|
||||
root = root or false
|
||||
grouped = grouped or false
|
||||
|
||||
local lhs = grouped and '<LEADER>fe' or '<LEADER>e'
|
||||
lhs = root and lhs or (lhs:gsub('%l$', string.upper))
|
||||
|
||||
return {
|
||||
lhs,
|
||||
function()
|
||||
require('neo-tree.command').execute({
|
||||
toggle = true,
|
||||
dir = root and (MarleyVim.root()) or (vim.uv.cwd()),
|
||||
})
|
||||
end,
|
||||
desc = 'Explorer (' .. (root and 'root' or 'cwd') .. ')',
|
||||
}
|
||||
end
|
||||
|
||||
return {
|
||||
'neo-tree.nvim',
|
||||
cmd = 'Neotree',
|
||||
keys = {
|
||||
make_toggle_mapping(true, true), -- root / grouped
|
||||
make_toggle_mapping(false, true), -- cwd / grouped
|
||||
make_toggle_mapping(true, false), -- root / non-grouped
|
||||
make_toggle_mapping(false, false), -- cwd / non-grouped
|
||||
{
|
||||
'<LEADER>ge',
|
||||
function()
|
||||
require('neo-tree.command').execute({
|
||||
source = 'git_status',
|
||||
toggle = true,
|
||||
})
|
||||
end,
|
||||
desc = 'Git explorer',
|
||||
},
|
||||
{
|
||||
'<LEADER>be',
|
||||
function()
|
||||
require('neo-tree.command').execute({
|
||||
source = 'buffers',
|
||||
toggle = true,
|
||||
})
|
||||
end,
|
||||
desc = 'Buffer explorer',
|
||||
},
|
||||
},
|
||||
before = function()
|
||||
require('lz.n').trigger_load({ 'plenary.nvim', 'mini.icons', 'nui.nvim' })
|
||||
end,
|
||||
after = function()
|
||||
local icons = require('icons')
|
||||
local events = require('neo-tree.events')
|
||||
|
||||
for _, type in ipairs({ 'Error', 'Warn', 'Info', 'Hint' }) do
|
||||
vim.fn.sign_define(
|
||||
'DiagnosticSign' .. type,
|
||||
{ text = icons.diagnostics[type], texthl = 'DiagnosticSign' .. type }
|
||||
)
|
||||
end
|
||||
|
||||
local function on_move(data)
|
||||
Snacks.rename.on_rename_file(data.source, data.destination)
|
||||
end
|
||||
|
||||
require('neo-tree').setup({
|
||||
close_if_last_window = true,
|
||||
sources = { 'filesystem', 'buffers', 'git_status' },
|
||||
open_files_do_not_replace_types = {
|
||||
'terminal',
|
||||
'Trouble',
|
||||
'trouble',
|
||||
'qf',
|
||||
'Outline',
|
||||
},
|
||||
|
||||
filesystem = {
|
||||
bind_to_cwd = false,
|
||||
follow_current_file = { enabled = true },
|
||||
use_libuv_file_watcher = true,
|
||||
filtered_items = {
|
||||
visible = true,
|
||||
hide_dotfiles = false,
|
||||
},
|
||||
},
|
||||
|
||||
window = {
|
||||
mappings = {
|
||||
['l'] = 'open',
|
||||
['h'] = 'close_node',
|
||||
['<SPACE>'] = 'none',
|
||||
['Y'] = {
|
||||
function(state)
|
||||
local node = state.tree:get_node()
|
||||
local path = node:get_id()
|
||||
vim.fn.setreg('+', path, 'c')
|
||||
end,
|
||||
desc = 'copy path to clipboard',
|
||||
},
|
||||
['P'] = { 'toggle_preview', config = { use_float = false } },
|
||||
},
|
||||
},
|
||||
default_component_configs = {
|
||||
indent = {
|
||||
with_expanders = true,
|
||||
expanders_collapsed = '',
|
||||
expander_expanded = '',
|
||||
expander_highlight = 'NeoTreeExpander',
|
||||
},
|
||||
git_status = {
|
||||
symbols = {
|
||||
unstaged = icons.git.unstaged,
|
||||
staged = icons.git.staged,
|
||||
},
|
||||
},
|
||||
},
|
||||
event_handlers = {
|
||||
{ event = events.FILE_MOVED, handler = on_move },
|
||||
{ event = events.FILE_RENAMED, handler = on_move },
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
-- Snacks needs to be loaded very early, so it gets its own special file.
|
||||
local set = vim.keymap.set
|
||||
local lazyvim_format = require('lib.lazyvim.format')
|
||||
local lazyvim_root = require('lib.lazyvim.root')
|
||||
|
||||
require('snacks').setup({
|
||||
bigfile = { enabled = true },
|
||||
|
@ -88,7 +87,7 @@ end, { desc = 'Git browse (copy)' })
|
|||
|
||||
if vim.fn.executable('lazygit') == 1 then
|
||||
set({ 'n' }, '<LEADER>gg', function()
|
||||
Snacks.lazygit({ cwd = lazyvim_root.git() })
|
||||
Snacks.lazygit({ cwd = MarleyVim.root() })
|
||||
end, { desc = 'Lazygit (root dir)' })
|
||||
|
||||
-- set({ 'n' }, '<LEADER>gG', function()
|
||||
|
@ -100,7 +99,7 @@ if vim.fn.executable('lazygit') == 1 then
|
|||
end, { desc = 'Lazygit current file history' })
|
||||
|
||||
set({ 'n' }, '<LEADER>gl', function()
|
||||
Snacks.lazygit.log({ cwd = lazyvim_root.git() })
|
||||
Snacks.lazygit.log({ cwd = MarleyVim.root() })
|
||||
end, { desc = 'Lazygit log' })
|
||||
|
||||
-- set({ 'n' }, '<LEADER>gL', function()
|
||||
|
|
Loading…
Reference in a new issue