Compare commits

...

7 Commits

Author SHA1 Message Date
8687a1cf31 fix: rever mouse vert scroll 2025-10-26 15:33:01 +02:00
7f10891dcd feat: paq sync command 2025-10-26 09:14:51 +02:00
84dd394f31 fix/finder (#2)
Reviewed-on: #2
Co-authored-by: Tomas Mirchev <contact@tomastm.com>
Co-committed-by: Tomas Mirchev <contact@tomastm.com>
2025-10-26 06:35:47 +00:00
be67d7a67a feat: terminal events 2025-10-26 06:31:49 +02:00
3075a218b8 feat/pack (#1)
Reviewed-on: #1
Co-authored-by: Tomas Mirchev <contact@tomastm.com>
Co-committed-by: Tomas Mirchev <contact@tomastm.com>
2025-10-26 04:18:14 +00:00
2b1b3ebbf0 feat: language-manager 2025-10-24 02:21:21 +03:00
9bca643408 feat: tailwindcss 2025-10-23 20:44:51 +03:00
26 changed files with 2039 additions and 1051 deletions

View File

@@ -1,30 +1,10 @@
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
local out =
vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ 'Failed to clone lazy.nvim:\n', 'ErrorMsg' },
{ out, 'WarningMsg' },
{ '\nPress any key to exit...' },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
if #vim.api.nvim_list_uis() == 0 then
require('setup')
return
end
vim.opt.rtp:prepend(lazypath)
require('config.options')
require('config.keymaps')
require('config.autocmds')
require('config.clipboard')
require('config.terminal')
require('custom.navigation')
require('custom.tabline').setup()
require('lazy').setup({
spec = { { import = 'plugins' } },
install = { missing = false },
change_detection = { notify = false },
rocks = { enabled = false },
})
vim.env.PATH = vim.fn.stdpath('data') .. '/mason/bin:' .. vim.env.PATH
require('core.options')
require('core.keymaps')
require('core.events')

View File

@@ -1,11 +0,0 @@
{
"conform.nvim": { "branch": "master", "commit": "9fd3d5e0b689ec1bf400c53cbbec72c6fdf24081" },
"invero.nvim": { "branch": "main", "commit": "6acdefa2f2fdf544b53b5786e748be0ae8e9fd23" },
"lazy.nvim": { "branch": "main", "commit": "1ea3c4085785f460fb0e46d2fe1ee895f5f9e7c1" },
"mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" },
"nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" },
"nvim-lint": { "branch": "master", "commit": "9da1fb942dd0668d5182f9c8dee801b9c190e2bb" },
"nvim-tree.lua": { "branch": "master", "commit": "7c0f7e906ab6f11b61eec52171eaf7dc06726ef1" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
"nvim-ts-autotag": { "branch": "main", "commit": "c4ca798ab95b316a768d51eaaaee48f64a4a46bc" }
}

View File

@@ -1,3 +1,31 @@
local utils = {}
function utils.root_markers_with_field(root_files, new_names, field, fname)
local path = vim.fn.fnamemodify(fname, ':h')
local found = vim.fs.find(new_names, { path = path, upward = true })
for _, f in ipairs(found or {}) do
-- Match the given `field`.
for line in io.lines(f) do
if line:find(field) then
root_files[#root_files + 1] = vim.fs.basename(f)
break
end
end
end
return root_files
end
function utils.insert_package_json(root_files, field, fname)
return utils.root_markers_with_field(
root_files,
{ 'package.json', 'package.json5' },
field,
fname
)
end
--- @brief
---
--- https://github.com/hrsh7th/vscode-langservers-extracted
@@ -39,7 +67,6 @@
---
--- /!\ When using flat config files, you need to use them across all your packages in your monorepo, as it's a global setting for the server.
local utils = require('utils')
local lsp = vim.lsp
local eslint_config_files = {

163
lsp/tailwindcss.lua Normal file
View File

@@ -0,0 +1,163 @@
local utils = {}
function utils.root_markers_with_field(root_files, new_names, field, fname)
local path = vim.fn.fnamemodify(fname, ':h')
local found = vim.fs.find(new_names, { path = path, upward = true })
for _, f in ipairs(found or {}) do
-- Match the given `field`.
for line in io.lines(f) do
if line:find(field) then
root_files[#root_files + 1] = vim.fs.basename(f)
break
end
end
end
return root_files
end
function utils.insert_package_json(root_files, field, fname)
return utils.root_markers_with_field(
root_files,
{ 'package.json', 'package.json5' },
field,
fname
)
end
---@brief
--- https://github.com/tailwindlabs/tailwindcss-intellisense
---
--- Tailwind CSS Language Server can be installed via npm:
---
--- npm install -g @tailwindcss/language-server
---@type vim.lsp.Config
return {
cmd = { 'tailwindcss-language-server', '--stdio' },
-- filetypes copied and adjusted from tailwindcss-intellisense
filetypes = {
-- html
'aspnetcorerazor',
'astro',
'astro-markdown',
'blade',
'clojure',
'django-html',
'htmldjango',
'edge',
'eelixir', -- vim ft
'elixir',
'ejs',
'erb',
'eruby', -- vim ft
'gohtml',
'gohtmltmpl',
'haml',
'handlebars',
'hbs',
'html',
'htmlangular',
'html-eex',
'heex',
'jade',
'leaf',
'liquid',
'markdown',
'mdx',
'mustache',
'njk',
'nunjucks',
'php',
'razor',
'slim',
'twig',
-- css
'css',
'less',
'postcss',
'sass',
'scss',
'stylus',
'sugarss',
-- js
'javascript',
'javascriptreact',
'reason',
'rescript',
'typescript',
'typescriptreact',
-- mixed
'vue',
'svelte',
'templ',
},
settings = {
tailwindCSS = {
validate = true,
lint = {
cssConflict = 'warning',
invalidApply = 'error',
invalidScreen = 'error',
invalidVariant = 'error',
invalidConfigPath = 'error',
invalidTailwindDirective = 'error',
recommendedVariantOrder = 'warning',
},
classAttributes = {
'class',
'className',
'class:list',
'classList',
'ngClass',
},
includeLanguages = {
eelixir = 'html-eex',
elixir = 'phoenix-heex',
eruby = 'erb',
heex = 'phoenix-heex',
htmlangular = 'html',
templ = 'html',
},
},
},
before_init = function(_, config)
if not config.settings then
config.settings = {}
end
if not config.settings.editor then
config.settings.editor = {}
end
if not config.settings.editor.tabSize then
config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop()
end
end,
workspace_required = true,
root_dir = function(bufnr, on_dir)
local root_files = {
-- Generic
'tailwind.config.js',
'tailwind.config.cjs',
'tailwind.config.mjs',
'tailwind.config.ts',
'postcss.config.js',
'postcss.config.cjs',
'postcss.config.mjs',
'postcss.config.ts',
-- Django
'theme/static_src/tailwind.config.js',
'theme/static_src/tailwind.config.cjs',
'theme/static_src/tailwind.config.mjs',
'theme/static_src/tailwind.config.ts',
'theme/static_src/postcss.config.js',
-- Fallback for tailwind v4, where tailwind.config.* is not required anymore
'.git',
}
local fname = vim.api.nvim_buf_get_name(bufnr)
root_files = utils.insert_package_json(root_files, 'tailwindcss', fname)
root_files =
utils.root_markers_with_field(root_files, { 'mix.lock', 'Gemfile.lock' }, 'tailwind', fname)
on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1]))
end,
}

View File

@@ -1,55 +0,0 @@
-- Automatically create a scratch buffer if Neovim starts with no files
vim.api.nvim_create_autocmd('VimEnter', {
callback = function()
-- Only trigger if no file arguments are passed
if vim.fn.argc() == 0 then
vim.cmd('enew')
vim.bo.buftype = 'nofile'
vim.bo.bufhidden = 'wipe'
vim.bo.swapfile = false
end
end,
})
-- Highlight when yanking (copying) text
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
})
-- Disable comment continuation only when using 'o'/'O', but keep it for <Enter>
vim.api.nvim_create_autocmd('FileType', {
pattern = '*',
callback = function()
vim.opt_local.formatoptions:remove('o')
end,
})
-- Show cursor line only in active window
vim.api.nvim_create_autocmd({ 'WinEnter', 'InsertLeave' }, {
callback = function()
if vim.w.auto_cursorline then
vim.wo.cursorline = true
vim.w.auto_cursorline = nil
end
end,
})
vim.api.nvim_create_autocmd({ 'WinLeave', 'InsertEnter' }, {
callback = function()
if vim.bo.filetype == 'NvimTree' then
return
end
if vim.wo.cursorline then
vim.w.auto_cursorline = true
vim.wo.cursorline = false
end
end,
})
-- Removes trailing whitespace before saving
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
pattern = '*',
command = [[%s/\s\+$//e]],
})

View File

@@ -1,25 +0,0 @@
if vim.env.CONTAINER then
vim.g.clipboard = {
name = 'osc52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
end
-- vim.schedule(function()
-- vim.opt.clipboard = 'unnamedplus'
-- end)
-- TEMP: Check if it helps with edge cases
vim.api.nvim_create_user_command('FixClipboard', function()
vim.cmd('lua require("vim.ui.clipboard.osc52")')
vim.schedule(function()
vim.notify('Clipboard provider reloaded (OSC52)')
end)
end, {})

View File

@@ -1,62 +0,0 @@
local term_group = vim.api.nvim_create_augroup('custom-term-open', { clear = true })
vim.api.nvim_create_autocmd('TermOpen', {
group = term_group,
callback = function()
vim.opt_local.number = false
vim.opt_local.relativenumber = false
vim.opt_local.scrolloff = 0
vim.bo.filetype = 'terminal'
vim.cmd.startinsert()
end,
})
-- Close all terminal buffers before quitting
vim.api.nvim_create_autocmd('QuitPre', {
group = vim.api.nvim_create_augroup('shoutoff_terminals', { clear = true }),
callback = function()
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].buftype == 'terminal' then
vim.api.nvim_buf_delete(buf, { force = true })
end
end
end,
})
-- Insert when re-entering a terminal window (after switching back)
vim.api.nvim_create_autocmd('BufEnter', {
group = term_group,
pattern = 'term://*',
callback = function()
if vim.bo.buftype == 'terminal' and vim.fn.mode() ~= 'i' then
vim.cmd.startinsert()
end
end,
})
local function open_default()
vim.cmd('terminal')
end
local function open_relative()
local shell = vim.o.shell or 'zsh'
local dir = vim.fn.expand('%:p:h')
vim.cmd(string.format('edit term://%s//%s', dir, shell))
end
local function open_split()
vim.cmd('new')
vim.cmd('wincmd J')
vim.api.nvim_win_set_height(0, 12)
vim.wo.winfixheight = true
vim.cmd('term')
end
local function open_vertical()
vim.cmd('vsplit')
vim.cmd('term')
end
vim.api.nvim_create_user_command('TermDefault', open_default, {})
vim.api.nvim_create_user_command('TermRelative', open_relative, {})
vim.api.nvim_create_user_command('TermSplit', open_split, {})
vim.api.nvim_create_user_command('TermVSplit', open_vertical, {})

111
lua/core/events.lua Normal file
View File

@@ -0,0 +1,111 @@
require('modules.theme')
require('modules.terminal')
local api = vim.api
local au = api.nvim_create_autocmd
local group = api.nvim_create_augroup('core.events', { clear = true })
-- Automatically create a scratch buffer if Neovim starts with no files
au('VimEnter', {
group = group,
callback = function()
-- Only trigger if no file arguments are passed
if vim.fn.argc() == 0 then
vim.cmd('enew')
vim.bo.buftype = 'nofile'
vim.bo.bufhidden = 'wipe'
vim.bo.swapfile = false
end
end,
})
-- Highlight when yanking (copying) text
au('TextYankPost', {
group = group,
callback = function()
vim.highlight.on_yank({ timeout = 200 })
end,
})
-- Disable comment continuation only when using 'o'/'O', but keep it for <Enter>
au('FileType', {
group = group,
pattern = '*',
callback = function()
vim.opt_local.formatoptions:remove('o')
end,
})
-- Show cursor line only in active window
au({ 'WinEnter', 'InsertLeave' }, {
group = group,
callback = function()
if vim.w.auto_cursorline then
vim.wo.cursorline = true
vim.w.auto_cursorline = nil
end
end,
})
au({ 'WinLeave', 'InsertEnter' }, {
group = group,
callback = function()
-- Keep it on NvimTree to show current file
if vim.bo.filetype == 'NvimTree' then
return
end
if vim.wo.cursorline then
vim.w.auto_cursorline = true
vim.wo.cursorline = false
end
end,
})
-- Autocompletion
au('LspAttach', {
group = group,
callback = function(event)
local client = vim.lsp.get_client_by_id(event.data.client_id)
if not client then
return
end
-- Enable native completion
if client:supports_method('textDocument/completion') then
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
end
end,
})
vim.lsp.handlers['textDocument/completion'] = function(err, result, ctx, config)
if err or not result then
return
end
for _, item in ipairs(result.items or result) do
if item.kind then
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
item.menu = '[' .. kind .. ']'
end
end
return vim.lsp.completion._on_completion_result(err, result, ctx, config)
end
au('InsertEnter', {
group = group,
once = true,
callback = function()
require('nvim-ts-autotag').setup()
require('nvim-autopairs').setup()
end,
})
au('UIEnter', {
group = group,
once = true,
callback = function()
vim.schedule(function()
require('modules.navigation')
require('plugins.language-manager').setup()
require('modules.diagnostics')
end)
end,
})

View File

@@ -9,6 +9,7 @@ end
-- QOL
map('i', 'jk', '<Esc>')
map('i', '<C-c>', '<Esc>')
map('n', '<Esc>', cmd('nohlsearch'))
map('n', 'q:', '<nop>')
@@ -21,7 +22,7 @@ vim.keymap.set('x', 'K', ":m '<-2<CR>gv=gv")
vim.keymap.set('n', '<leader>s', [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/g<Left><Left><Left>]])
-- Proper registers
-- Easy to use registers
map('x', '<leader>p', '"_dP')
map({ 'n', 'x' }, '<leader>y', '"+y')
map('n', '<leader>Y', '"+y$')
@@ -60,8 +61,12 @@ map('n', '<leader>xr', cmd('TermRelative'))
map('n', '<leader>xs', cmd('TermSplit'))
map('n', '<leader>xv', cmd('TermVSplit'))
map('t', '<Esc>', '<C-\\><C-n>')
map('t', '<C-w>', '<C-\\><C-n><C-w>')
map('t', '<C-w>c', '<C-\\><C-n>:bd!<CR>')
map('t', '<C-w>h', [[<C-\><C-n><C-w>h]])
map('t', '<C-w>j', [[<C-\><C-n><C-w>j]])
map('t', '<C-w>k', [[<C-\><C-n><C-w>k]])
map('t', '<C-w>l', [[<C-\><C-n><C-w>l]])
map('t', '<C-w>c', [[<C-\><C-n><cmd>bd!<CR>]])
map('t', '<C-w><C-w>', [[<C-\><C-n><C-w>w]])
-- File explorer
map('n', '<leader>e', cmd('NvimTreeToggle'))
@@ -76,4 +81,8 @@ map('n', '[d', function()
end)
map('n', '<leader>q', vim.diagnostic.setloclist)
map('n', '<leader>d', vim.diagnostic.open_float)
map('n', '<leader>s', vim.lsp.buf.signature_help)
map('n', 'K', vim.lsp.buf.hover)
map('n', 'gd', vim.lsp.buf.definition)
map('n', 'gr', vim.lsp.buf.references)
map('n', '<C-s>', vim.lsp.buf.signature_help)

View File

@@ -16,11 +16,14 @@ vim.g.loaded_vimballPlugin = 1
vim.g.loaded_matchit = 1
vim.g.loaded_2html_plugin = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_tutor_mode_plugin = 1
vim.g.loaded_spellfile_plugin = 1
vim.g.loaded_logipat = 1
vim.g.loaded_rplugin = 1
vim.g.loaded_netrw = 1 -- use nvim-tree instead
vim.g.loaded_netrwPlugin = 1
-- UI
vim.g.health = { style = 'float' }
vim.g.have_nerd_font = true
vim.opt.termguicolors = false
@@ -31,9 +34,10 @@ vim.opt.signcolumn = 'no'
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.cursorline = true
vim.opt.ruler = false
vim.opt.winborder = 'rounded'
vim.opt.guicursor = 'n-v-i-c:block'
vim.opt.ruler = false
vim.opt.laststatus = 3
vim.opt.statusline = '── %f %h%w%m%r %= [%l,%c-%L] ──'
vim.opt.fillchars = {
@@ -64,14 +68,14 @@ vim.opt.smartindent = true -- Automatically inserts indents in code blocks (for
-- Scroll and mouse
vim.opt.scrolloff = 10
vim.opt.sidescrolloff = 5
vim.opt.mousescroll = 'hor:1,ver:5'
vim.opt.mousescroll = 'hor:1,ver:1'
vim.opt.mouse = 'a' -- Enable mouse support
-- Search
vim.opt.ignorecase = true
vim.opt.smartcase = true -- Override ignorecase if search contains upper case chars
vim.opt.inccommand = 'split' -- Live substitution preview
vim.opt.completeopt = { 'fuzzy,menuone,popup,preview,noselect' }
vim.opt.completeopt = { 'fuzzy', 'menuone', 'popup', 'noselect' }
-- Splits
vim.opt.splitright = true
@@ -82,8 +86,23 @@ vim.opt.undofile = true
vim.opt.swapfile = false
-- Tweaks
vim.opt.updatetime = 1000
vim.opt.updatetime = 50
vim.opt.timeout = true
vim.opt.ttimeout = true
vim.opt.timeoutlen = 500
vim.opt.ttimeoutlen = 10
-- Clipboard
if vim.env.CONTAINER then
vim.g.clipboard = {
name = 'osc52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
end

View File

@@ -1,323 +0,0 @@
-- Minimal fuzzy finder + content search for Neovim 0.11+
-- Optional: `fdfind` or `fd` for file listing, and `rg` (ripgrep) for text search.
local Fuzzy = {}
--------------------------------------------------------------------
-- 🧩 Helpers
--------------------------------------------------------------------
-- Collect all files (try fdfind/fd first, then globpath)
local function get_file_list()
local handle = io.popen('fdfind --type f 2>/dev/null || fd --type f 2>/dev/null')
if handle then
local result = handle:read('*a')
handle:close()
if result and result ~= '' then
return vim.split(result, '\n', { trimempty = true })
end
end
return vim.fn.globpath('.', '**/*', false, true)
end
-- Create floating input + result windows
local function open_float(prompt)
local input_buf = vim.api.nvim_create_buf(false, true)
local result_buf = vim.api.nvim_create_buf(false, true)
-- mark both buffers as scratch/unlisted
for _, b in ipairs({ input_buf, result_buf }) do
vim.bo[b].bufhidden = 'wipe'
vim.bo[b].buflisted = false
vim.bo[b].swapfile = false
end
vim.bo[input_buf].buftype = 'prompt'
vim.bo[result_buf].buftype = 'nofile'
local width = math.floor(vim.o.columns * 0.7)
local height = 20
local row = math.floor((vim.o.lines - height) / 2)
local col = math.floor((vim.o.columns - width) / 2)
local input_win = vim.api.nvim_open_win(input_buf, true, {
relative = 'editor',
row = row,
col = col,
width = width,
height = 1,
style = 'minimal',
border = 'rounded',
})
vim.fn.prompt_setprompt(input_buf, prompt)
local result_win = vim.api.nvim_open_win(result_buf, false, {
relative = 'editor',
row = row + 2,
col = col,
width = width,
height = height - 2,
style = 'minimal',
border = 'single',
})
return input_buf, result_buf, input_win, result_win
end
--------------------------------------------------------------------
-- 🔵 Highlight current selection
--------------------------------------------------------------------
function Fuzzy:highlight_selection()
if not self.result_buf then
return
end
if not self.ns_id then
self.ns_id = vim.api.nvim_create_namespace('FuzzyHighlight')
end
vim.api.nvim_buf_clear_namespace(self.result_buf, self.ns_id, 0, -1)
if self.matches and self.matches[self.cursor] then
local rel_cursor = self.cursor - (self.scroll or 0)
if rel_cursor >= 1 and rel_cursor <= self.page_size then
vim.api.nvim_buf_set_extmark(self.result_buf, self.ns_id, rel_cursor - 1, 0, {
end_line = rel_cursor,
hl_group = 'Visual',
hl_eol = true,
})
end
end
end
--------------------------------------------------------------------
-- 🔴 Close all floating windows
--------------------------------------------------------------------
function Fuzzy.close()
local wins = { Fuzzy.input_win, Fuzzy.result_win }
for _, win in ipairs(wins) do
if win and vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_close(win, true)
end
end
Fuzzy.active = false
end
--------------------------------------------------------------------
-- 🟢 File finder
--------------------------------------------------------------------
function Fuzzy.open()
if Fuzzy.active then
Fuzzy.close()
end
Fuzzy.active = true
Fuzzy.files = get_file_list()
Fuzzy.matches = Fuzzy.files
Fuzzy.cursor = 1
Fuzzy.scroll = 0
Fuzzy.page_size = 50
Fuzzy.input_buf, Fuzzy.result_buf, Fuzzy.input_win, Fuzzy.result_win = open_float('Search: ')
local function render_results()
local total = #Fuzzy.matches
if total == 0 then
vim.api.nvim_buf_set_lines(Fuzzy.result_buf, 0, -1, false, { '-- no matches --' })
return
end
local start_idx = Fuzzy.scroll + 1
local end_idx = math.min(start_idx + Fuzzy.page_size - 1, total)
local display = {}
for i = start_idx, end_idx do
display[#display + 1] = Fuzzy.matches[i]
end
vim.api.nvim_buf_set_lines(Fuzzy.result_buf, 0, -1, false, display)
Fuzzy:highlight_selection()
end
local function update_results(text)
if text == '' then
Fuzzy.matches = Fuzzy.files
else
Fuzzy.matches = vim.fn.matchfuzzy(Fuzzy.files, text)
end
Fuzzy.cursor, Fuzzy.scroll = 1, 0
render_results()
end
vim.api.nvim_create_autocmd({ 'TextChangedI', 'TextChangedP' }, {
buffer = Fuzzy.input_buf,
callback = function()
local text = vim.fn.getline('.'):gsub('^Search:%s*', '')
update_results(text)
end,
})
vim.keymap.set('i', '<C-n>', function()
if Fuzzy.cursor < #Fuzzy.matches then
Fuzzy.cursor = Fuzzy.cursor + 1
if Fuzzy.cursor > Fuzzy.scroll + Fuzzy.page_size then
Fuzzy.scroll = Fuzzy.scroll + 1
end
render_results()
end
end, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<C-p>', function()
if Fuzzy.cursor > 1 then
Fuzzy.cursor = Fuzzy.cursor - 1
if Fuzzy.cursor <= Fuzzy.scroll then
Fuzzy.scroll = math.max(Fuzzy.scroll - 1, 0)
end
render_results()
end
end, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<CR>', function()
local choice = Fuzzy.matches[Fuzzy.cursor]
if choice then
Fuzzy.close()
vim.cmd.edit(vim.fn.fnameescape(choice))
end
end, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<Esc>', Fuzzy.close, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<C-c>', Fuzzy.close, { buffer = Fuzzy.input_buf })
vim.keymap.set('n', '<Esc>', Fuzzy.close, { buffer = Fuzzy.input_buf })
vim.keymap.set('n', 'q', Fuzzy.close, { buffer = Fuzzy.input_buf })
vim.cmd.startinsert()
end
--------------------------------------------------------------------
-- 🟣 Ripgrep-based content search (scrolling + match highlighting)
--------------------------------------------------------------------
function Fuzzy.open_grep()
if Fuzzy.active then
Fuzzy.close()
end
Fuzzy.active = true
Fuzzy.input_buf, Fuzzy.result_buf, Fuzzy.input_win, Fuzzy.result_win = open_float('Grep: ')
Fuzzy.matches, Fuzzy.cursor, Fuzzy.scroll = {}, 1, 0
Fuzzy.page_size = 50
Fuzzy.ns_id = vim.api.nvim_create_namespace('FuzzyHighlight')
local function render_results(query)
local total = #Fuzzy.matches
if total == 0 then
vim.api.nvim_buf_set_lines(Fuzzy.result_buf, 0, -1, false, { '-- no matches --' })
return
end
local start_idx = Fuzzy.scroll + 1
local end_idx = math.min(start_idx + Fuzzy.page_size - 1, total)
local display = {}
for i = start_idx, end_idx do
display[#display + 1] = Fuzzy.matches[i]
end
vim.api.nvim_buf_set_lines(Fuzzy.result_buf, 0, -1, false, display)
vim.api.nvim_buf_clear_namespace(Fuzzy.result_buf, Fuzzy.ns_id, 0, -1)
-- highlight selection
local rel_cursor = math.min(Fuzzy.cursor - Fuzzy.scroll, #display)
vim.api.nvim_buf_set_extmark(Fuzzy.result_buf, Fuzzy.ns_id, rel_cursor - 1, 0, {
end_line = rel_cursor,
hl_group = 'Visual',
hl_eol = true,
})
-- highlight query matches
if query and query ~= '' then
local pattern = vim.pesc(query)
for i, line in ipairs(display) do
for s, e in line:gmatch('()' .. pattern .. '()') do
vim.api.nvim_buf_set_extmark(Fuzzy.result_buf, Fuzzy.ns_id, i - 1, s - 1, {
end_col = e - 1,
hl_group = 'Search',
})
end
end
end
end
local function run_grep(query)
if query == '' then
vim.api.nvim_buf_set_lines(Fuzzy.result_buf, 0, -1, false, { '-- type to search --' })
return
end
local handle = io.popen('rg --vimgrep --hidden --smart-case ' .. vim.fn.shellescape(query))
if not handle then
return
end
local result = handle:read('*a')
handle:close()
Fuzzy.matches = vim.split(result, '\n', { trimempty = true })
Fuzzy.cursor, Fuzzy.scroll = 1, 0
render_results(query)
end
vim.api.nvim_create_autocmd({ 'TextChangedI', 'TextChangedP' }, {
buffer = Fuzzy.input_buf,
callback = function()
local text = vim.fn.getline('.'):gsub('^Grep:%s*', '')
run_grep(text)
end,
})
vim.keymap.set('i', '<C-n>', function()
if Fuzzy.cursor < #Fuzzy.matches then
Fuzzy.cursor = Fuzzy.cursor + 1
if Fuzzy.cursor > Fuzzy.scroll + Fuzzy.page_size then
Fuzzy.scroll = Fuzzy.scroll + 1
end
local query = vim.fn.getline('.'):gsub('^Grep:%s*', '')
render_results(query)
end
end, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<C-p>', function()
if Fuzzy.cursor > 1 then
Fuzzy.cursor = Fuzzy.cursor - 1
if Fuzzy.cursor <= Fuzzy.scroll then
Fuzzy.scroll = math.max(Fuzzy.scroll - 1, 0)
end
local query = vim.fn.getline('.'):gsub('^Grep:%s*', '')
render_results(query)
end
end, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<CR>', function()
local line = Fuzzy.matches[Fuzzy.cursor]
if line then
local parts = vim.split(line, ':')
local file, lnum = parts[1], tonumber(parts[2]) or 1
Fuzzy.close()
vim.cmd.edit(vim.fn.fnameescape(file))
vim.api.nvim_win_set_cursor(0, { lnum, 0 })
end
end, { buffer = Fuzzy.input_buf })
vim.keymap.set('i', '<Esc>', function()
Fuzzy.close()
end, { buffer = Fuzzy.input_buf })
vim.cmd.startinsert()
end
--------------------------------------------------------------------
-- 🧩 Commands & Keymaps
--------------------------------------------------------------------
vim.api.nvim_create_user_command('FuzzyLive', function()
Fuzzy.open()
end, {})
vim.api.nvim_create_user_command('FuzzyGrep', function()
Fuzzy.open_grep()
end, {})
vim.keymap.set('n', '<leader>f', function()
vim.cmd.FuzzyLive()
end, { desc = 'Open fuzzy file finder' })
vim.keymap.set('n', '<leader>g', function()
vim.cmd.FuzzyGrep()
end, { desc = 'Search file contents with ripgrep' })
return Fuzzy

View File

@@ -0,0 +1,42 @@
-- Diagnostics
local special_sources = {
lua_ls = 'lua',
}
vim.diagnostic.config({
underline = true,
severity_sort = true,
virtual_text = {
format = function(diagnostic)
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
if src then
return string.format('%s: %s', src, diagnostic.message)
end
return diagnostic.message
end,
},
float = {
border = 'rounded',
header = '',
format = function(diagnostic)
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
if src then
return string.format('%s: %s', src, diagnostic.message)
end
return diagnostic.message
end,
},
})
-- Override the virtual text diagnostic handler so that the most severe diagnostic is shown first.
local show_handler = vim.diagnostic.handlers.virtual_text.show
assert(show_handler)
local hide_handler = vim.diagnostic.handlers.virtual_text.hide
vim.diagnostic.handlers.virtual_text = {
show = function(ns, bufnr, diagnostics, opts)
table.sort(diagnostics, function(diag1, diag2)
return diag1.severity > diag2.severity
end)
return show_handler(ns, bufnr, diagnostics, opts)
end,
hide = hide_handler,
}

View File

@@ -0,0 +1,23 @@
local M = {}
function M.get()
return {
{ ts = { 'yaml', 'toml', 'sql', 'diff', 'dockerfile', 'gitcommit', 'gitignore' } },
{ ts = { 'c', 'cpp', 'go', 'rust', 'python' } },
{ ft = 'markdown', ts = { 'markdown', 'markdown_inline' }, format = 'prettier' },
{ ft = 'bash', lsp = 'bash-language-server', lint = 'shellcheck', format = 'shfmt' },
{ ft = 'lua', lsp = 'lua-language-server', lint = 'luacheck', format = 'stylua' },
{ ft = { 'json', 'jsonc' }, lsp = 'json-lsp' },
{ ft = 'html', lsp = 'html-lsp' },
{ ft = 'css', lsp = { 'css-lsp', 'tailwindcss-language-server' } },
{
ft = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact' },
ts = { 'javascript', 'typescript', 'tsx' },
lsp = { 'vtsls', 'eslint-lsp' },
format = { 'prettierd', 'prettier' },
},
}
end
return M

View File

@@ -0,0 +1,13 @@
require('plugins.filetree')
require('plugins.finder').setup({
exclude_patterns = { 'node_modules', 'dist', 'build', '.git', '.cache', '.turbo', '*-lock.json' },
use_disk_cache = true, -- optional
})
vim.keymap.set('n', '<leader>f', function()
require('plugins.finder').files()
end)
vim.keymap.set('n', '<leader>g', function()
require('plugins.finder').grep()
end)

67
lua/modules/terminal.lua Normal file
View File

@@ -0,0 +1,67 @@
local api = vim.api
local au = api.nvim_create_autocmd
local group = api.nvim_create_augroup('triimd.term', { clear = true })
-- Custom terminal
au('TermOpen', {
group = group,
callback = function()
vim.opt_local.number = false
vim.opt_local.relativenumber = false
vim.opt_local.scrolloff = 0
vim.bo.filetype = 'terminal'
vim.cmd.startinsert()
end,
})
-- Insert when re-entering a terminal window (after switching back)
au('BufEnter', {
group = group,
pattern = 'term://*',
callback = function()
if vim.bo.buftype == 'terminal' and vim.fn.mode() ~= 'i' then
vim.cmd.startinsert()
end
end,
})
-- Close all terminal buffers before quitting
au('QuitPre', {
group = group,
callback = function()
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].buftype == 'terminal' then
vim.api.nvim_buf_delete(buf, { force = true })
end
end
end,
})
local commands = {
TermDefault = function()
vim.cmd('terminal')
end,
TermRelative = function()
local shell = vim.o.shell or 'zsh'
local dir = vim.fn.expand('%:p:h')
vim.cmd(string.format('edit term://%s//%s', dir, shell))
end,
TermSplit = function()
vim.cmd('new')
vim.cmd('wincmd J')
vim.api.nvim_win_set_height(0, 12)
vim.wo.winfixheight = true
vim.cmd('term')
end,
TermVSplit = function()
vim.cmd('vsplit')
vim.cmd('term')
end,
}
for name, fn in pairs(commands) do
vim.api.nvim_create_user_command(name, fn, {})
end

33
lua/modules/theme.lua Normal file
View File

@@ -0,0 +1,33 @@
local function load_theme()
require('invero').setup({
highlights = function(c, tool)
c.bg_float = tool(152)
return {
ModeMsg = { fg = c.yellow, bg = c.none, bold = true },
WinSeparator = { fg = c.outline, bg = c.base },
StatusLine = { fg = c.outline, bg = c.base },
StatusLineNC = { fg = c.text, bg = c.base, bold = true },
TabLine = { fg = c.muted, bg = c.none },
TabLineSel = { fg = c.text, bg = c.none, bold = true },
TabLineFill = { fg = c.outline_light, bg = c.none },
Pmenu = { fg = c.text, bg = c.surface },
PmenuSel = { fg = c.text, bg = c.accent_light },
QuickFixLine = { fg = c.accent, bg = c.none, bold = true },
['@lsp'] = { fg = c.syntax, bg = c.none },
['@variable'] = { fg = c.syntax, bg = c.none },
}
end,
})
vim.o.background = 'light'
vim.cmd.colorscheme('invero')
end
vim.api.nvim_create_user_command('ReloadInvero', function()
require('invero').invalidate_cache()
load_theme()
end, {})
load_theme()
require('plugins.tabline').setup()

View File

@@ -1,36 +0,0 @@
return {
'triimdev/invero.nvim',
lazy = false,
priority = 1000,
config = function()
vim.api.nvim_create_user_command('ReloadInvero', function()
require('invero').invalidate_cache()
vim.cmd('Lazy reload invero.nvim')
end, {})
require('invero').setup({
highlights = function(c, tool)
c.bg_float = tool(152)
return {
ModeMsg = { fg = c.yellow, bg = c.none, bold = true },
WinSeparator = { fg = c.outline, bg = c.base },
StatusLine = { fg = c.outline, bg = c.base },
StatusLineNC = { fg = c.text, bg = c.base, bold = true },
TabLine = { fg = c.muted, bg = c.none },
TabLineSel = { fg = c.text, bg = c.none, bold = true },
TabLineFill = { fg = c.outline_light, bg = c.none },
Pmenu = { fg = c.text, bg = c.surface },
PmenuSel = { fg = c.text, bg = c.accent_light },
QuickFixLine = { fg = c.accent, bg = c.none, bold = true },
-- PmenuSbar = { bg = c.surface },
-- PmenuThumb = { bg = c.outline },
-- PmenuBorder = { fg = c.outline },
}
end,
})
vim.o.background = 'light'
vim.cmd.colorscheme('invero')
end,
}

View File

@@ -46,18 +46,12 @@ local function my_on_attach(bufnr)
vim.keymap.set('n', 'U', api.tree.reload, opts)
end
return {
'https://gitea.tomastm.com/tomas.mirchev/nvim-tree.lua',
branch = 'master',
opts = {
require('nvim-tree').setup({
on_attach = my_on_attach,
view = { signcolumn = 'no' },
actions = { file_popup = { open_win_config = { border = 'rounded' } } },
renderer = {
root_folder_label = false,
-- root_folder_label = function(path)
-- return '-- ' .. vim.fn.fnamemodify(path, ':t') .. ' --'
-- end,
special_files = {},
highlight_hidden = 'all',
@@ -74,7 +68,7 @@ return {
show = {
file = false,
folder = false,
folder_arrow = false, -- KEEP FALSE
folder_arrow = false,
git = true,
modified = false,
hidden = false,
@@ -82,30 +76,13 @@ return {
bookmarks = true,
},
glyphs = {
-- default = '•',
default = ' ',
symlink = '',
bookmark = '󰆤',
modified = '',
hidden = '󰜌',
folder = {
arrow_closed = '',
arrow_open = '',
default = '',
open = '',
empty = '',
empty_open = '',
symlink = '',
symlink_open = '',
},
git = {
unstaged = '', -- '✗',
unstaged = '',
staged = '',
unmerged = '',
renamed = '',
untracked = '',
deleted = '', -- '󰧧',
deleted = '',
ignored = '',
},
},
@@ -143,5 +120,4 @@ return {
'/target',
},
},
},
}
})

947
lua/plugins/finder.lua Normal file
View File

@@ -0,0 +1,947 @@
-- finder.lua — Minimal, hardened async fuzzy finder + grep for Neovim ≥ 0.11
local M = {}
---------------------------------------------------------------------
-- Config
---------------------------------------------------------------------
M.config = {
file_cmd = nil, -- "fd" | "fdfind" | nil (auto)
grep_cmd = 'rg', -- ripgrep binary
page_size = 60, -- soft cap; real viewport height is measured
debounce_ms = 80,
instant_items = 1500, -- <= this count + cached => 0 ms debounce
fast_items = 4000, -- <= this count => debounce_ms/2
cache_ttl_sec = 20,
max_items = 5000, -- safety cap for massive outputs
debug = false,
-- Exclusion controls (added to tool flags and used in glob fallback)
exclude_patterns = { 'node_modules', 'dist', 'build', '.git' },
-- Optional on-disk filelist cache at $ROOT/.devflow/finder_cache.json
use_disk_cache = false,
}
---------------------------------------------------------------------
-- State
---------------------------------------------------------------------
local S = {
active = false,
mode = nil, -- "files" | "grep"
root = nil,
cache = {},
timer = nil,
ns = vim.api.nvim_create_namespace('finder_ns'),
aug = nil,
gen = 0, -- session generation id
-- async jobs
job_files = nil,
job_rg = nil,
-- UI
win_inp = nil,
buf_inp = nil,
win_res = nil,
buf_res = nil,
-- Data
query = '',
items = {}, -- full set (files or grep lines)
filtered = {}, -- current view
positions = {}, -- positions[i] = { {scol, ecol}, ... } for filtered[i]
select = 1, -- absolute index in filtered (1-based)
scroll = 0, -- top index (0-based)
user_moved = false, -- has user navigated during this session?
-- meta
files_cached = false,
}
---------------------------------------------------------------------
-- Utils
---------------------------------------------------------------------
local function L(msg, data)
if not M.config.debug then
return
end
local s = '[finder] ' .. msg
if data ~= nil then
s = s .. ' ' .. vim.inspect(data)
end
vim.schedule(function()
pcall(vim.notify, s)
end)
end
local function now_sec()
return vim.loop.now() / 1000
end
local function clamp(v, lo, hi)
return (v < lo) and lo or ((v > hi) and hi or v)
end
local function cmd_exists(bin)
return vim.fn.executable(bin) == 1
end
-- single reusable timer to avoid churn; caller controls ms
local function debounce(fn, ms)
if not S.timer then
S.timer = vim.loop.new_timer()
end
S.timer:stop()
S.timer:start(ms, 0, function()
S.timer:stop()
vim.schedule(fn)
end)
end
local function read_gitignore(root)
local p = root .. '/.gitignore'
local f = io.open(p, 'r')
if not f then
return {}
end
local lines = {}
for line in f:lines() do
local l = vim.trim(line)
if #l > 0 and not l:match('^#') and not l:match('^!') then
l = l:gsub('/+$', '')
table.insert(lines, l)
end
end
f:close()
return lines
end
local function ensure_cache_dir(root)
local dir = root .. '/.devflow'
local ok = vim.loop.fs_stat(dir)
if not ok then
pcall(vim.loop.fs_mkdir, dir, 448)
end -- 0700
return dir
end
local function load_cache(root)
if not M.config.use_disk_cache then
return nil
end
local file = ensure_cache_dir(root) .. '/finder_cache.json'
local f = io.open(file, 'r')
if not f then
return nil
end
local content = f:read('*a')
f:close()
local ok, data = pcall(vim.json.decode, content)
if not ok or type(data) ~= 'table' or type(data.files) ~= 'table' then
return nil
end
if now_sec() - (data.timestamp or 0) > M.config.cache_ttl_sec then
pcall(os.remove, file) -- proactively clear stale
return nil
end
return data.files
end
local function save_cache(root, files)
if not M.config.use_disk_cache then
return
end
local file = ensure_cache_dir(root) .. '/finder_cache.json'
local payload = { timestamp = now_sec(), files = files }
local ok, json = pcall(vim.json.encode, payload)
if not ok then
return
end
local f = io.open(file, 'w')
if not f then
return
end
f:write(json)
f:close()
end
local function project_root()
local obj = vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait()
if obj.code == 0 and obj.stdout and obj.stdout ~= '' then
return vim.trim(obj.stdout)
end
return vim.fn.getcwd(0, 0)
end
-- Robust relative-to-root
local function normalize_rel(root, p)
if not p or p == '' then
return ''
end
local abs = vim.fs.normalize(vim.fn.fnamemodify(p, ':p'))
local root_norm = vim.fs.normalize(root)
if abs == root_norm then
return ''
end
if abs:find(root_norm, 1, true) == 1 then
local ch = abs:sub(#root_norm + 1, #root_norm + 1)
if ch == '/' or ch == '\\' then
return abs:sub(#root_norm + 2)
end
end
-- strip leading ./ as last resort
return (p:gsub('^%./', ''))
end
local function to_abs_path(root, rel)
if not rel or rel == '' then
return root
end
return vim.fs.normalize(root .. '/' .. rel)
end
local function to_display_path(abs)
-- relative to current working dir if possible, else absolute
return vim.fn.fnamemodify(abs, ':.')
end
local function page_rows()
if S.win_res and vim.api.nvim_win_is_valid(S.win_res) then
return math.max(1, vim.api.nvim_win_get_height(S.win_res))
end
return math.max(1, math.min(M.config.page_size, vim.o.lines))
end
local function effective_debounce_ms()
if S.mode == 'files' then
local n = #S.items
if S.files_cached and n > 0 and n <= (M.config.instant_items or 1500) then
return 0
elseif n > 0 and n <= (M.config.fast_items or 4000) then
return math.max(0, math.floor((M.config.debounce_ms or 80) / 2))
end
end
return M.config.debounce_ms or 80
end
---------------------------------------------------------------------
-- Render helpers
---------------------------------------------------------------------
local function ensure_visible()
local page = page_rows()
local sel = clamp(S.select, 1, #S.filtered)
local top = S.scroll + 1
local bot = S.scroll + page
if sel < top then
S.scroll = sel - 1
elseif sel > bot then
S.scroll = sel - page
end
S.scroll = clamp(S.scroll, 0, math.max(#S.filtered - page, 0))
end
---------------------------------------------------------------------
-- Render
---------------------------------------------------------------------
local function render()
if not (S.buf_res and vim.api.nvim_buf_is_valid(S.buf_res)) then
return
end
ensure_visible()
local total = #S.filtered
local view = {}
if total == 0 then
view = { '-- no matches --' }
else
local start_idx = S.scroll + 1
local end_idx = math.min(start_idx + page_rows() - 1, total)
for i = start_idx, end_idx do
local line = S.filtered[i]
view[#view + 1] = tostring(line or '')
end
end
vim.bo[S.buf_res].modifiable = true
vim.bo[S.buf_res].readonly = false
vim.api.nvim_buf_set_lines(S.buf_res, 0, -1, false, view)
vim.api.nvim_buf_clear_namespace(S.buf_res, S.ns, 0, -1)
-- match highlights (visible window only)
vim.api.nvim_set_hl(0, 'FinderMatch', { link = 'Search', default = true })
for i = 1, #view do
local idx = S.scroll + i
local spans = S.positions[idx]
if spans then
for _, se in ipairs(spans) do
local scol, ecol = se[1], se[2]
if ecol > scol then
vim.api.nvim_buf_set_extmark(S.buf_res, S.ns, i - 1, scol, {
end_col = ecol,
hl_group = 'FinderMatch',
})
end
end
end
end
-- selection highlight
if total > 0 and #view > 0 then
vim.api.nvim_set_hl(0, 'FinderSelection', { link = 'CursorLine', default = true })
local rel = clamp(S.select - S.scroll, 1, #view)
vim.api.nvim_buf_set_extmark(S.buf_res, S.ns, rel - 1, 0, {
end_line = rel,
hl_group = 'FinderSelection',
hl_eol = true,
})
end
vim.bo[S.buf_res].modifiable = false
L('render', { select = S.select, scroll = S.scroll, total = total, lines = #view })
end
---------------------------------------------------------------------
-- Querying / Filtering
---------------------------------------------------------------------
local function compute_positions_files(items, q)
local ok, res = pcall(vim.fn.matchfuzzypos, items, q)
if not ok or type(res) ~= 'table' then
return {}, {}
end
local out_items = res[1] or {}
local pos = res[2] or {}
local filtered, positions = {}, {}
for i, v in ipairs(out_items) do
filtered[i] = tostring(v or '')
local cols = pos[i] or {}
table.sort(cols)
local spans = {}
local start_col, last_col = nil, nil
for _, c in ipairs(cols) do
local c0 = c
if not start_col then
start_col, last_col = c0, c0
elseif c0 == last_col + 1 then
last_col = c0
else
table.insert(spans, { start_col, last_col + 1 }) -- end exclusive
start_col, last_col = c0, c0
end
end
if start_col then
table.insert(spans, { start_col, last_col + 1 })
end
positions[i] = (#spans > 0) and spans or nil
end
return filtered, positions
end
local function compute_positions_grep(lines, q)
if q == '' then
return lines, {}
end
local qlow = q:lower()
local positions = {}
for i, line in ipairs(lines) do
local llow = tostring(line or ''):lower()
local spans = {}
local sidx = 1
while true do
local s, e = llow:find(qlow, sidx, true)
if not s then
break
end
table.insert(spans, { s - 1, e })
sidx = e + 1
if #spans > 64 then
break
end
end
positions[i] = (#spans > 0) and spans or nil
end
return lines, positions
end
---------------------------------------------------------------------
-- set_items
---------------------------------------------------------------------
local function set_items(list)
list = list or {}
if #list > M.config.max_items then
local tmp = {}
for i = 1, M.config.max_items do
tmp[i] = list[i]
end
list = tmp
end
-- sanitize to strings
for i, v in ipairs(list) do
list[i] = tostring(v or '')
end
S.items = list
S.filtered = list
S.positions = {}
S.select = 1
S.scroll = 0
render()
end
---------------------------------------------------------------------
-- set_query
---------------------------------------------------------------------
local function set_query(q)
local prev_val = S.filtered[S.select]
S.query = q
if S.mode == 'grep' then
local filtered, pos = compute_positions_grep(S.items, q)
S.filtered, S.positions = filtered, pos
else
if q == '' then
S.filtered = S.items
S.positions = {}
else
local filtered, pos = compute_positions_files(S.items, q)
S.filtered, S.positions = filtered, pos
end
end
-- selection policy:
if not S.user_moved then
S.select = 1
else
local idx = nil
if prev_val then
for i, v in ipairs(S.filtered) do
if v == prev_val then
idx = i
break
end
end
end
S.select = idx or 1
end
ensure_visible()
render()
L('set_query', { query = q, filtered = #S.filtered, user_moved = S.user_moved })
end
---------------------------------------------------------------------
-- Move / Accept
---------------------------------------------------------------------
local function move_down()
if #S.filtered == 0 then
return
end
S.user_moved = true
S.select = clamp(S.select + 1, 1, #S.filtered)
ensure_visible()
render()
end
local function move_up()
if #S.filtered == 0 then
return
end
S.user_moved = true
S.select = clamp(S.select - 1, 1, #S.filtered)
ensure_visible()
render()
end
-- Correct parser for rg --vimgrep (file:line:col:match)
local function parse_vimgrep(line)
if type(line) ~= 'string' then
return nil
end
local file, lnum = line:match('^(.-):(%d+):%d+:')
if not file then
return nil
end
return file, tonumber(lnum) or 1
end
local function accept_selection_files()
local pick = S.filtered[S.select]
if type(pick) ~= 'string' or pick == '' then
return
end
local abs = to_abs_path(S.root, pick)
local path = to_display_path(abs)
M.close()
vim.schedule(function()
vim.cmd.edit(vim.fn.fnameescape(path))
end)
end
local function accept_selection_grep()
local pick = S.filtered[S.select]
if type(pick) ~= 'string' or pick == '' then
return
end
local file, lnum = parse_vimgrep(pick)
if not file then
return
end
local abs = to_abs_path(S.root, file)
local path = to_display_path(abs)
local ln = tonumber(lnum) or 1
M.close()
vim.schedule(function()
vim.cmd.edit(vim.fn.fnameescape(path))
pcall(vim.api.nvim_win_set_cursor, 0, { ln, 0 })
end)
end
---------------------------------------------------------------------
-- Backends
---------------------------------------------------------------------
local function cancel_job(job)
if not job then
return
end
pcall(function()
job:kill(15)
end) -- SIGTERM if available
end
local function collect_files_async(cb)
local root = S.root
local gen = S.gen
local disk = load_cache(root)
if disk and type(disk) == 'table' then
S.files_cached = true
cb(disk)
return
end
S.files_cached = false
local file_cmd = M.config.file_cmd
if not file_cmd then
if cmd_exists('fd') then
file_cmd = 'fd'
elseif cmd_exists('fdfind') then
file_cmd = 'fdfind'
end
end
local excludes = {}
for _, p in ipairs(M.config.exclude_patterns or {}) do
table.insert(excludes, p)
end
local gi = read_gitignore(root)
for _, p in ipairs(gi) do
table.insert(excludes, p)
end
if file_cmd then
local args = { file_cmd, '--type', 'f', '--hidden', '--color', 'never' }
if file_cmd == 'fd' or file_cmd == 'fdfind' then
table.insert(args, '--strip-cwd-prefix')
end
for _, ex in ipairs(excludes) do
table.insert(args, '--exclude')
table.insert(args, ex)
end
cancel_job(S.job_files)
S.job_files = vim.system(args, { text = true, cwd = root }, function(obj)
if not (S.active and gen == S.gen) then
return
end
local list = {}
if obj.stdout then
local raw = vim.split(obj.stdout, '\n', { trimempty = true })
for _, p in ipairs(raw) do
list[#list + 1] = normalize_rel(root, p)
end
end
if #list > M.config.max_items then
local tmp = {}
for i = 1, M.config.max_items do
tmp[i] = list[i]
end
list = tmp
end
save_cache(root, list)
vim.schedule(function()
if S.active and gen == S.gen then
cb(list)
end
end)
end)
return
end
-- Try git ls-files as async fallback
if cmd_exists('git') then
cancel_job(S.job_files)
S.job_files = vim.system(
{ 'git', 'ls-files', '-co', '--exclude-standard', '-z' },
{ text = true, cwd = root },
function(o2)
if not (S.active and gen == S.gen) then
return
end
local list = {}
if o2.stdout then
for p in o2.stdout:gmatch('([^%z]+)') do
list[#list + 1] = normalize_rel(root, p)
end
end
if #list > M.config.max_items then
local tmp = {}
for i = 1, M.config.max_items do
tmp[i] = list[i]
end
list = tmp
end
save_cache(root, list)
vim.schedule(function()
if S.active and gen == S.gen then
cb(list)
end
end)
end
)
return
end
-- Last resort omitted: blocking glob removed to keep async-only behavior
cb({})
end
local function grep_async(query, cb)
if query == '' then
cb({})
return
end
local gen = S.gen
local rg = M.config.grep_cmd
if not cmd_exists(rg) then
cb({})
return
end
local root = S.root
local args = {
rg,
'--vimgrep',
'--hidden',
'--smart-case',
'--no-heading',
'--no-config',
'--color',
'never',
'--path-separator',
'/',
'--',
query,
}
-- Apply excludes as negative globs
for _, p in ipairs(M.config.exclude_patterns or {}) do
table.insert(args, 2, '--glob')
table.insert(args, 3, '!' .. p)
end
for _, p in ipairs(read_gitignore(root)) do
table.insert(args, 2, '--glob')
table.insert(args, 3, '!' .. p)
end
cancel_job(S.job_rg)
S.job_rg = vim.system(args, { text = true, cwd = root }, function(obj)
if not (S.active and gen == S.gen) then
return
end
local list = {}
-- Accept output even if exit code != 0 (no matches or partial errors)
if obj.stdout and #obj.stdout > 0 then
list = vim.split(obj.stdout, '\n', { trimempty = true })
end
if #list > M.config.max_items then
local tmp = {}
for i = 1, M.config.max_items do
tmp[i] = list[i]
end
list = tmp
end
vim.schedule(function()
if S.active and gen == S.gen then
cb(list)
end
end)
end)
end
---------------------------------------------------------------------
-- Layout
---------------------------------------------------------------------
local function open_layout(prompt)
S.buf_inp = vim.api.nvim_create_buf(false, true)
S.buf_res = vim.api.nvim_create_buf(false, true)
for _, b in ipairs({ S.buf_inp, S.buf_res }) do
if b and vim.api.nvim_buf_is_valid(b) then
vim.bo[b].buflisted = false
vim.bo[b].bufhidden = 'wipe'
vim.bo[b].swapfile = false
end
end
if S.buf_inp and vim.api.nvim_buf_is_valid(S.buf_inp) then
vim.bo[S.buf_inp].buftype = 'prompt'
end
if S.buf_res and vim.api.nvim_buf_is_valid(S.buf_res) then
vim.bo[S.buf_res].buftype = 'nofile'
vim.bo[S.buf_res].modifiable = false
vim.bo[S.buf_res].readonly = false
end
local width = math.floor(vim.o.columns * 0.8)
local height = math.min(math.floor(vim.o.lines * 0.5), M.config.page_size + 2)
local col = math.floor((vim.o.columns - width) / 2)
local row = math.floor((vim.o.lines - height) * 0.7)
S.win_inp = vim.api.nvim_open_win(S.buf_inp, true, {
relative = 'editor',
style = 'minimal',
border = 'rounded',
width = width,
height = 1,
col = col,
row = row,
focusable = true,
zindex = 200,
})
if S.buf_inp and vim.api.nvim_buf_is_valid(S.buf_inp) then
vim.fn.prompt_setprompt(S.buf_inp, prompt or '')
end
S.win_res = vim.api.nvim_open_win(S.buf_res, false, {
relative = 'editor',
style = 'minimal',
border = 'single',
width = width,
height = math.max(1, height - 2),
col = col,
row = row + 2,
focusable = false,
zindex = 199,
})
if S.win_res and vim.api.nvim_win_is_valid(S.win_res) then
vim.wo[S.win_res].cursorline = false
vim.wo[S.win_res].cursorlineopt = 'line'
end
if S.aug then
pcall(vim.api.nvim_del_augroup_by_id, S.aug)
end
S.aug = vim.api.nvim_create_augroup('finder_session', { clear = true })
-- Close if focus enters a non-floating window that isn't ours
vim.api.nvim_create_autocmd('WinEnter', {
group = S.aug,
callback = function()
if not S.active then
return
end
local w = vim.api.nvim_get_current_win()
if w == S.win_inp or w == S.win_res then
return
end
local cfg = vim.api.nvim_win_get_config(w)
if cfg and cfg.relative == '' then
M.close()
end
end,
})
-- Close if prompt buffer hides or leaves
if S.buf_inp and vim.api.nvim_buf_is_valid(S.buf_inp) then
vim.api.nvim_create_autocmd({ 'BufHidden', 'BufLeave' }, {
group = S.aug,
buffer = S.buf_inp,
callback = function()
if S.active then
M.close()
end
end,
})
end
-- Re-render on resize to respect new viewport height
vim.api.nvim_create_autocmd('VimResized', {
group = S.aug,
callback = function()
if S.active then
render()
end
end,
})
vim.cmd.startinsert()
L('open_layout', { win_inp = S.win_inp, win_res = S.win_res })
end
local function close_layout()
for _, win in ipairs({ S.win_inp, S.win_res }) do
if win and vim.api.nvim_win_is_valid(win) then
pcall(vim.api.nvim_win_close, win, true)
end
end
for _, buf in ipairs({ S.buf_inp, S.buf_res }) do
if buf and vim.api.nvim_buf_is_valid(buf) then
pcall(vim.api.nvim_buf_delete, buf, { force = true })
end
end
if S.aug then
pcall(vim.api.nvim_del_augroup_by_id, S.aug)
S.aug = nil
end
L('close_layout')
end
---------------------------------------------------------------------
-- Input handlers
---------------------------------------------------------------------
local function attach_handlers()
local opts = { buffer = S.buf_inp, nowait = true, silent = true, noremap = true }
vim.keymap.set('i', '<C-n>', move_down, opts)
vim.keymap.set('i', '<C-p>', move_up, opts)
vim.keymap.set('i', '<Down>', move_down, opts)
vim.keymap.set('i', '<Up>', move_up, opts)
vim.keymap.set('i', '<CR>', function()
if S.mode == 'grep' then
accept_selection_grep()
else
accept_selection_files()
end
end, opts)
vim.keymap.set('i', '<Esc>', function()
M.close()
end, opts)
vim.keymap.set('i', '<C-c>', function()
M.close()
end, opts)
if S.buf_inp and vim.api.nvim_buf_is_valid(S.buf_inp) then
vim.api.nvim_create_autocmd({ 'TextChangedI', 'TextChangedP' }, {
group = S.aug,
buffer = S.buf_inp,
callback = function()
local delay = effective_debounce_ms()
debounce(function()
if not (S.active and S.buf_inp and vim.api.nvim_buf_is_valid(S.buf_inp)) then
return
end
local raw = vim.fn.getline('.')
raw = type(raw) == 'string' and raw or ''
local prompt_pat = (S.mode == 'files') and '^Search:%s*' or '^Grep:%s*'
local q = raw:gsub(prompt_pat, '')
if S.mode == 'grep' then
grep_async(q, function(list)
if not S.active then
return
end
S.items = list or {}
set_query(q)
end)
else
set_query(q)
end
end, delay)
end,
})
end
L('keymaps attached', opts)
end
---------------------------------------------------------------------
-- Public
---------------------------------------------------------------------
function M.files()
if S.active then
M.close()
end
S.active = true
S.gen = S.gen + 1
S.user_moved = false
S.mode = 'files'
S.root = project_root()
open_layout('Search: ')
attach_handlers()
collect_files_async(function(list)
if not S.active then
return
end
set_items(list) -- render initial list (relative to root)
end)
end
function M.grep()
if S.active then
M.close()
end
S.active = true
S.gen = S.gen + 1
S.user_moved = false
S.mode = 'grep'
S.root = project_root()
open_layout('Grep: ')
attach_handlers()
S.items = {}
set_query('')
end
function M.close()
if not S.active then
return
end
-- stop timers and jobs first
if S.timer then
pcall(function()
S.timer:stop()
S.timer:close()
end)
S.timer = nil
end
cancel_job(S.job_rg)
S.job_rg = nil
cancel_job(S.job_files)
S.job_files = nil
close_layout()
S.active = false
S.mode, S.root = nil, nil
S.items, S.filtered, S.positions = {}, {}, {}
S.query, S.select, S.scroll = '', 1, 0
S.user_moved = false
S.files_cached = false
L('session closed')
end
function M.setup(opts)
M.config = vim.tbl_deep_extend('force', M.config, opts or {})
if M.config.file_cmd and not cmd_exists(M.config.file_cmd) then
pcall(
vim.notify,
("finder: file_cmd '%s' not found"):format(M.config.file_cmd),
vim.log.levels.WARN
)
end
if M.config.grep_cmd and not cmd_exists(M.config.grep_cmd) then
pcall(
vim.notify,
("finder: grep_cmd '%s' not found, will try 'rg'"):format(M.config.grep_cmd),
vim.log.levels.WARN
)
end
L('setup', M.config)
end
return M

View File

@@ -0,0 +1,359 @@
local utils = require('utils')
local M = {
ts = {},
lsp = {},
lint = {},
format = {},
}
M.group = vim.api.nvim_create_augroup('language-manager', { clear = true })
local cache_path = vim.fn.stdpath('cache') .. '/language-manager.json'
local function wrap(item)
if type(item) == 'string' then
return { item }
elseif type(item) == 'table' then
return item
else
return {}
end
end
local function create_set()
local seen = {}
return function(ref, item)
if not seen[ref] then
seen[ref] = {}
end
if item and not seen[ref][item] then
seen[ref][item] = true
return true
end
return false
end
end
local function read_file(path)
local f = io.open(path, 'r')
if not f then
return nil
end
local content = f:read('*a')
f:close()
return content
end
local function write_file(path, content)
local f = io.open(path, 'w')
if not f then
return false
end
f:write(content)
f:close()
return true
end
local function to_json(tbl)
local ok, result = pcall(vim.json.encode, tbl)
return ok and result or nil
end
local function from_json(str)
local ok, result = pcall(vim.json.decode, str)
return ok and result or nil
end
local function hash_spec(tbl)
local encoded = to_json(tbl) or ''
if vim.fn.exists('*sha256') == 1 then
return vim.fn.sha256(encoded)
else
local tmp = vim.fn.tempname()
write_file(tmp, encoded)
local handle = io.popen('openssl dgst -sha256 ' .. tmp)
local result = handle and handle:read('*a') or ''
if handle then
handle:close()
end
return result:match('([a-f0-9]+)') or ''
end
end
local function save_cache(data)
local encoded = to_json(data)
if encoded then
write_file(cache_path, encoded)
end
end
local function load_cache()
local raw = read_file(cache_path)
if not raw then
return nil
end
return from_json(raw)
end
-- ======== Spec Builder ========
local function create_spec()
local S = {}
local unique = create_set()
local specs = {}
function S.set(item, group)
specs[group] = item
end
function S.get()
return specs
end
function S.add(list, ...)
local groups = { ... }
local ref = table.concat(groups, '.')
local pointer = specs
local last_i = #groups
for i = 1, last_i do
local group = groups[i]
if i == last_i then
for _, item in ipairs(wrap(list)) do
if unique(ref, item) then
pointer[group] = pointer[group] or {}
table.insert(pointer[group], item)
end
end
else
pointer[group] = pointer[group] or {}
pointer = pointer[group]
end
end
end
return S
end
-- ======== Spec Generation ========
local function get_mason_registry()
vim.cmd.packadd('mason.nvim')
require('mason').setup()
local registry = require('mason-registry')
registry.refresh()
return registry
end
function M.generate_specs(specs_raw)
local install_spec = create_spec()
local specs = create_spec()
local registry = get_mason_registry()
local lsp_map = {}
for _, spec in ipairs(specs_raw) do
if type(spec) == 'string' then
spec = { ft = spec }
end
spec.ts = spec.ts or spec.ft
specs.add(spec.ts, 'ts_parsers')
install_spec.add(spec.lsp, 'code_tools')
local resolved_lsps = {}
for _, language_server in ipairs(wrap(spec.lsp)) do
if registry.has_package(language_server) then
local pkg = registry.get_package(language_server)
if pkg.spec and pkg.spec.neovim and pkg.spec.neovim.lspconfig then
local lspconfig_name = pkg.spec and pkg.spec.neovim and pkg.spec.neovim.lspconfig
lsp_map[lspconfig_name] = language_server
table.insert(resolved_lsps, lspconfig_name)
else
print('Package found but not lspconfig name: ' .. language_server)
end
else
print('Package not found: ' .. language_server)
end
end
specs.add(resolved_lsps, 'language_servers')
install_spec.add(spec.lint, 'code_tools')
install_spec.add(spec.format, 'code_tools')
for _, ft in ipairs(wrap(spec.ft)) do
specs.add(spec.lint, 'linters_by_ft', ft)
specs.add(spec.format, 'formatters_by_ft', ft)
end
end
local result = specs.get()
result.lsp_map = lsp_map
return result, install_spec.get()
end
-- ======== Cache ========
function M.load_specs()
local cache = load_cache()
if cache then
M.general = cache.spec
else
local specs_raw = require('modules.language-specs').get()
M.general, M.mason = M.generate_specs(specs_raw)
save_cache({ hash = hash_spec(specs_raw), spec = M.general })
end
return M.general, M.mason
end
function M.invalidate_cache()
local ok = os.remove(cache_path)
if ok then
vim.notify('Language manager cache invalidated', vim.log.levels.INFO)
else
vim.notify('No cache to invalidate or failed to delete', vim.log.levels.WARN)
end
M.general = nil
M.mason = nil
end
function M.ts.install()
vim.cmd.packadd('nvim-treesitter')
local ts_install = require('nvim-treesitter.install').ensure_installed_sync
ts_install(M.general.ts_parsers)
end
function M.mason_install()
local packages = M.mason.code_tools
local registry = get_mason_registry()
local pending = #packages
local result = utils.await(function(resolve)
for _, name in ipairs(packages) do
local pkg = registry.get_package(name)
if pkg:is_installed() then
print('Mason package already installed: ' .. name)
pending = pending - 1
if pending == 0 then
resolve(true)
end
else
print('Mason package installing: ' .. name)
pkg:install({}, function(success, error)
if success then
print('Mason package installed: ' .. name)
else
print('Mason package failed: ' .. name)
print(' > Error: ' .. vim.inspect(error))
end
pending = pending - 1
if pending == 0 then
resolve(true)
end
end)
end
end
end, 5 * 60 * 1000, 200)
if not result.ok or pending ~= 0 then
print('\n!! >> Exited timeout, possible clean up needed!')
print(' > status: ' .. result.ok)
print(' > pending: ' .. pending)
end
end
-- ======== Public API ========
function M.install()
print('\n> Starting ts parsers install')
M.ts.install()
print('\n> Starting mason install: lsp, lint, format')
M.mason_install()
end
function M.ts.setup()
require('nvim-treesitter.configs').setup({
highlight = { enable = true },
incremental_selection = { enable = true },
})
end
function M.lsp.setup()
for _, lsp_name in ipairs((M.general and M.general.language_servers) or {}) do
vim.lsp.enable(lsp_name)
end
vim.api.nvim_buf_create_user_command(0, 'LspInfo', function()
vim.cmd('checkhealth vim.lsp')
end, {})
end
function M.lint.setup()
vim.api.nvim_create_autocmd({ 'BufReadPre', 'BufNewFile' }, {
group = M.group,
once = true,
callback = function()
local lint = require('lint')
lint.linters_by_ft = M.general.linters_by_ft
function M.debounce(ms, fn)
local timer = vim.uv.new_timer()
return function(...)
local argv = { ... }
timer:start(ms, 0, function()
timer:stop()
vim.schedule_wrap(fn)(unpack(argv))
end)
end
end
function M.lint()
if vim.bo.modifiable then
lint.try_lint()
end
end
vim.api.nvim_create_autocmd({ 'BufReadPost', 'InsertLeave', 'TextChanged' }, {
group = vim.api.nvim_create_augroup('language-manager.lint', { clear = true }),
callback = M.debounce(100, M.lint),
})
vim.api.nvim_create_autocmd('BufEnter', {
group = M.group,
callback = function(args)
local bufnr = args.buf
local ft = vim.bo[bufnr].filetype
local linters = lint.linters_by_ft[ft]
if linters then
vim.api.nvim_buf_create_user_command(bufnr, 'LintInfo', function()
print('Linters for ' .. ft .. ': ' .. table.concat(linters, ', '))
end, {})
end
end,
})
end,
})
end
function M.format.setup()
require('conform').setup({
formatters_by_ft = (M.general and M.general.formatters_by_ft) or {},
default_format_opts = { stop_after_first = true, lsp_format = 'fallback' },
format_on_save = { timeout_ms = 500 },
})
end
function M.setup()
M.load_specs()
M.ts.setup()
M.lsp.setup()
M.lint.setup()
M.format.setup()
end
return M

View File

@@ -1,379 +0,0 @@
-- language_spec = { treesitter?, lsp?, linter?, formatter?, filetype? }
local language_specs = {
-- Docs / Config
'vim',
'vimdoc',
{ 'markdown', nil, nil, 'prettier' },
'markdown_inline',
'yaml',
'toml',
-- Data
'gitcommit',
'gitignore',
'dockerfile',
'diff',
{ 'json', 'json-lsp' },
{ 'jsonc', 'json-lsp' },
-- Shell / scripting
{ 'bash', 'bash-language-server', 'shellcheck', 'shfmt' },
{ 'lua', 'lua-language-server', 'luacheck', 'stylua' },
'sql',
-- Programming
'c',
'cpp',
'go',
'rust',
'python',
-- { 'python', 'pyright', 'ruff', 'ruff' }, -- install ensurepip
-- Web stack
{ 'html', 'html-lsp' },
{ 'css', 'css-lsp' },
{ 'javascript', { 'vtsls', 'eslint-lsp' }, nil, 'prettier' },
{ 'typescript', { 'vtsls', 'eslint-lsp' }, nil, 'prettier' },
{ nil, { 'vtsls', 'eslint-lsp' }, nil, 'prettier', filetype = 'javascriptreact' },
{ 'tsx', { 'vtsls', 'eslint-lsp' }, nil, 'prettier', filetype = 'typescriptreact' },
}
local function normalize(spec)
if type(spec) == 'string' then
spec = { spec }
end
return {
treesitter = spec[1],
lsp = spec[2],
linter = spec[3],
formatter = spec[4],
filetype = spec.filetype or spec[1],
}
end
local normalized = vim.tbl_map(normalize, language_specs)
local function uniq(tbl)
local seen, out = {}, {}
for _, v in ipairs(tbl) do
if v and not seen[v] then
seen[v] = true
table.insert(out, v)
end
end
return out
end
local function collect(specs)
local ts, lsps, linters, formatters = {}, {}, {}, {}
for _, s in ipairs(specs) do
if s.treesitter then
table.insert(ts, s.treesitter)
end
if s.lsp then
if type(s.lsp) == 'table' then
for _, v in ipairs(s.lsp) do
table.insert(lsps, v)
end
else
table.insert(lsps, s.lsp)
end
end
if s.linter then
linters[s.filetype] = { s.linter }
end
if s.formatter then
formatters[s.filetype] = { s.formatter }
end
end
return {
ts_parsers = uniq(ts),
lsps = uniq(lsps),
linters_by_ft = linters,
formatters_by_ft = formatters,
}
end
local general = collect(normalized)
---------------------------------------------------------------------
-- Mason Install Command
---------------------------------------------------------------------
vim.api.nvim_create_user_command('MasonInstallAll', function()
local registry = require('mason-registry')
local list = vim.list_extend(vim.list_extend({}, general.lsps), {})
for _, ftmap in pairs({ general.linters_by_ft, general.formatters_by_ft }) do
for _, tools in pairs(ftmap) do
vim.list_extend(list, tools)
end
end
list = uniq(list)
local installed = {}
for _, pkg in ipairs(registry.get_installed_packages()) do
installed[pkg.name] = true
end
for _, name in ipairs(list) do
if registry.has_package(name) then
if not installed[name] then
vim.notify('Installing ' .. name, vim.log.levels.INFO)
registry.get_package(name):install()
else
vim.notify('Already installed ' .. name, vim.log.levels.INFO)
end
else
vim.notify('Package not found in registry: ' .. name, vim.log.levels.WARN)
end
end
end, { desc = 'Install all Mason LSPs, linters, and formatters' })
---------------------------------------------------------------------
-- Fetch LSP default configs from nvim-lspconfig
---------------------------------------------------------------------
vim.api.nvim_create_user_command('FetchLspConfigs', function()
local registry = require('mason-registry')
local lspconfig_names = {}
for _, lsp in ipairs(general.lsps) do
if registry.has_package(lsp) then
local pkg = registry.get_package(lsp)
local spec = pkg.spec and pkg.spec.neovim
if spec and spec.lspconfig then
table.insert(lspconfig_names, spec.lspconfig)
else
table.insert(lspconfig_names, lsp)
end
else
table.insert(lspconfig_names, lsp)
end
end
lspconfig_names = uniq(lspconfig_names)
-- base URL same as your original
local base_url = 'https://raw.githubusercontent.com/neovim/nvim-lspconfig/master/lsp/'
-- write to current working directory
local lsp_dir = vim.fs.joinpath(vim.fn.getcwd(), 'lsp')
vim.fn.mkdir(lsp_dir, 'p')
for _, name in ipairs(lspconfig_names) do
local file = vim.fs.joinpath(lsp_dir, name .. '.lua')
if vim.fn.filereadable(file) == 0 then
local url = base_url .. name .. '.lua'
local cmd = string.format('curl -fsSL -o %q %q', file, url)
vim.fn.system(cmd)
if vim.v.shell_error ~= 0 then
vim.notify('Failed to fetch ' .. name .. '.lua', vim.log.levels.ERROR)
vim.fn.delete(file)
else
vim.notify('Fetched ' .. name .. '.lua', vim.log.levels.INFO)
end
else
vim.notify('Skipped existing ' .. name .. '.lua', vim.log.levels.INFO)
end
end
end, { desc = 'Fetch default LSP configs into ./lsp in cwd' })
vim.api.nvim_create_user_command('TreesitterInstallAll', function()
local parsers = require('nvim-treesitter.parsers')
local configs = require('nvim-treesitter.configs')
local langs = configs.get_module('ensure_installed') or {}
if type(langs) == 'string' and langs == 'all' then
vim.notify('Treesitter ensure_installed = "all" not supported here', vim.log.levels.WARN)
return
end
for _, lang in ipairs(langs) do
if not parsers.has_parser(lang) then
vim.cmd('TSInstall ' .. lang)
else
vim.notify('Parser already installed: ' .. lang, vim.log.levels.INFO)
end
end
end, { desc = 'Install all Treesitter parsers defined in ensure_installed' })
vim.api.nvim_create_user_command('General', function()
print(vim.inspect(general))
end, {})
local special_sources = {
lua_ls = 'lua',
eslint = 'eslint',
}
vim.diagnostic.config({
underline = true,
severity_sort = true,
update_in_insert = true,
virtual_text = {
format = function(diagnostic)
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
if src then
return string.format('%s: %s', src, diagnostic.message)
end
return diagnostic.message
end,
},
float = {
border = 'rounded',
header = '',
format = function(diagnostic)
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
if src then
return string.format('%s: %s', src, diagnostic.message)
end
return diagnostic.message
end,
},
})
-- Override the virtual text diagnostic handler so that the most severe diagnostic is shown first.
local show_handler = vim.diagnostic.handlers.virtual_text.show
assert(show_handler)
local hide_handler = vim.diagnostic.handlers.virtual_text.hide
vim.diagnostic.handlers.virtual_text = {
show = function(ns, bufnr, diagnostics, opts)
table.sort(diagnostics, function(diag1, diag2)
return diag1.severity > diag2.severity
end)
return show_handler(ns, bufnr, diagnostics, opts)
end,
hide = hide_handler,
}
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('minimal_lsp', { clear = true }),
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if not client then
return
end
-- Enable native completion
if client:supports_method('textDocument/completion') then
vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true })
end
end,
})
---------------------------------------------------------------------
-- Optional: annotate completion items with their kind
---------------------------------------------------------------------
vim.lsp.handlers['textDocument/completion'] = function(err, result, ctx, config)
if err or not result then
return
end
for _, item in ipairs(result.items or result) do
if item.kind then
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
item.menu = '[' .. kind .. ']'
end
end
return vim.lsp.completion._on_completion_result(err, result, ctx, config)
end
---------------------------------------------------------------------
-- Plugins
---------------------------------------------------------------------
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('lsp_attach_timing', { clear = true }),
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client then
vim.notify(
string.format('LSP attached: %s (buf: %d)', client.name, ev.buf),
vim.log.levels.INFO
)
end
end,
})
local function enable_lsp_with_timing(lsp_name)
local start_time = vim.uv.hrtime()
vim.lsp.enable(lsp_name)
-- Track when the server actually attaches
local group = vim.api.nvim_create_augroup('lsp_timing_' .. lsp_name, { clear = true })
vim.api.nvim_create_autocmd('LspAttach', {
group = group,
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client and client.name == lsp_name then
local elapsed = (vim.uv.hrtime() - start_time) / 1e6 -- Convert to milliseconds
vim.notify(string.format('%s attached in %.2f ms', lsp_name, elapsed), vim.log.levels.INFO)
vim.api.nvim_del_augroup_by_id(group)
end
end,
})
end
return {
{ 'windwp/nvim-ts-autotag', config = true },
{ 'windwp/nvim-autopairs', event = 'InsertEnter', config = true },
{
'mason-org/mason.nvim',
config = function()
local mason = require('mason')
local registry = require('mason-registry')
mason.setup()
local lsp_configs = {}
for _, lsp in ipairs(general.lsps) do
if registry.has_package(lsp) then
local pkg = registry.get_package(lsp)
local spec = pkg.spec and pkg.spec.neovim
local lsp_name = (spec and spec.lspconfig) or lsp
table.insert(lsp_configs, lsp_name)
-- Native enable call (Neovim ≥ 0.11)
-- vim.lsp.enable(lsp_name)
enable_lsp_with_timing(lsp_name)
else
vim.notify('Unknown LSP: ' .. lsp, vim.log.levels.WARN)
end
end
vim.notify('Enabled LSPs: ' .. table.concat(lsp_configs, ', '), vim.log.levels.INFO)
end,
},
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
main = 'nvim-treesitter.configs',
opts = {
highlight = { enable = true },
incremental_selection = { enable = true },
ensure_installed = general.ts_parsers,
},
},
{
'mfussenegger/nvim-lint',
event = { 'BufReadPre', 'BufNewFile' },
opts = { linters_by_ft = general.linters_by_ft },
config = function(_, opts)
local lint = require('lint')
lint.linters_by_ft = opts.linters_by_ft
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWritePost', 'InsertLeave' }, {
group = vim.api.nvim_create_augroup('lint_autocmd', { clear = true }),
callback = function()
lint.try_lint()
end,
})
end,
},
{
'stevearc/conform.nvim',
event = { 'BufWritePre' },
opts = {
format_on_save = { timeout_ms = 500, lsp_format = 'fallback' },
default_format_opts = { stop_after_first = true },
formatters_by_ft = general.formatters_by_ft,
},
},
}

View File

@@ -1,6 +1,3 @@
-- ~/.config/nvim/lua/custom/tabline.lua
-- Custom Lua tabline with proper modified/unsaved and window count handling
local M = {}
-- Helper to get label for each tab page
@@ -79,8 +76,8 @@ function M.tabline()
end
function M.setup()
vim.o.showtabline = 1
vim.o.tabline = "%!v:lua.require'custom.tabline'.tabline()"
vim.opt.showtabline = 1
vim.opt.tabline = "%!v:lua.require'plugins.tabline'.tabline()"
end
return M

101
lua/setup/init.lua Normal file
View File

@@ -0,0 +1,101 @@
local function clone_package_manager()
local path = vim.fn.stdpath('data') .. '/site/pack/paqs/opt/paq-nvim'
if not vim.uv.fs_stat(path) then
local repo = 'https://github.com/savq/paq-nvim.git'
local cmd = { 'git', 'clone', '--depth=1', repo, path }
local result = vim.system(cmd):wait()
if result.code == 0 then
print('Package manager installed correctly')
end
end
end
local function load_paq()
vim.cmd.packadd('paq-nvim')
local paq = require('paq')
local packages = require('setup.packages').get()
paq:setup({ lock = vim.fn.stdpath('config') .. '/paq-lock.json' })(packages)
return paq
end
local function install_packages()
local done = false
vim.api.nvim_create_autocmd('User', {
pattern = 'PaqDoneInstall',
once = true,
callback = function()
done = true
end,
})
local paq = load_paq()
paq.install()
local to_install = paq.query('to_install')
if #to_install == 0 then
return
end
vim.wait(60000, function()
return done
end, 200)
if not done then
print('Paq installation timeout or failed')
else
print('Paq installation completed')
end
end
local function install_languages()
vim.cmd.packadd('mason.nvim')
require('mason').setup()
local lm = require('plugins.language-manager')
lm.invalidate_cache()
lm.load_specs()
lm.install()
end
vim.api.nvim_create_user_command('InstallAll', function()
print('> Starting clone package manager...')
clone_package_manager()
print('\n> Starting installing packages...')
install_packages()
print('\n> Starting installing languages: ts parsers, language servers, linters, formatters...')
install_languages()
print('\n=== Install Finished ===\n\n')
end, {})
vim.api.nvim_create_user_command('Sync', function()
local paq = load_paq()
paq:sync()
end, {})
vim.api.nvim_create_user_command('FetchLspConfigs', function()
local base_url = 'https://raw.githubusercontent.com/neovim/nvim-lspconfig/master/lsp/'
local lm = require('plugins.language-manager')
lm.invalidate_cache()
local general = lm.load_specs()
local lsp_dir = vim.fs.joinpath(vim.fn.getcwd(), 'lsp')
vim.fn.mkdir(lsp_dir, 'p')
for _, name in ipairs(general.language_servers or {}) do
local file = vim.fs.joinpath(lsp_dir, name .. '.lua')
if vim.fn.filereadable(file) == 0 then
local url = base_url .. name .. '.lua'
local cmd = string.format('curl -fsSL -o %q %q', file, url)
vim.fn.system(cmd)
if vim.v.shell_error ~= 0 then
vim.notify('Failed to fetch ' .. name .. '.lua', vim.log.levels.ERROR)
vim.fn.delete(file)
else
vim.notify('Fetched ' .. name .. '.lua', vim.log.levels.INFO)
end
else
vim.notify('Skipped existing ' .. name .. '.lua', vim.log.levels.INFO)
end
end
end, { desc = 'Fetch default LSP configs into ./lsp in cwd' })

20
lua/setup/packages.lua Normal file
View File

@@ -0,0 +1,20 @@
local M = {}
function M.get()
return {
{ 'savq/paq-nvim', opt = true },
{ 'https://github.com/mason-org/mason.nvim', opt = true },
{ 'https://github.com/triimd/invero.nvim' },
{ 'https://gitea.tomastm.com/tomas.mirchev/nvim-tree.lua', version = 'master' },
{ 'https://github.com/windwp/nvim-ts-autotag' },
{ 'https://github.com/windwp/nvim-autopairs' },
{ 'https://github.com/nvim-treesitter/nvim-treesitter', version = 'master' },
{ 'https://github.com/mfussenegger/nvim-lint' },
{ 'https://github.com/stevearc/conform.nvim' },
}
end
return M

View File

@@ -1,33 +1,24 @@
-- utils.lua
local M = {}
--- Appends `new_names` to `root_files` if `field` is found in any such file in any ancestor of `fname`.
---
--- NOTE: this does a "breadth-first" search, so is broken for multi-project workspaces:
--- https://github.com/neovim/nvim-lspconfig/issues/3818#issuecomment-2848836794
---
--- @param root_files string[] List of root-marker files to append to.
--- @param new_names string[] Potential root-marker filenames (e.g. `{ 'package.json', 'package.json5' }`) to inspect for the given `field`.
--- @param field string Field to search for in the given `new_names` files.
--- @param fname string Full path of the current buffer name to start searching upwards from.
function M.root_markers_with_field(root_files, new_names, field, fname)
local path = vim.fn.fnamemodify(fname, ':h')
local found = vim.fs.find(new_names, { path = path, upward = true })
function M.await(fn, timeout, interval)
local done = false
local ok, data
for _, f in ipairs(found or {}) do
-- Match the given `field`.
for line in io.lines(f) do
if line:find(field) then
root_files[#root_files + 1] = vim.fs.basename(f)
break
end
end
end
-- Wrap resolve in vim.schedule so it runs on main loop
fn(function(success, result)
vim.schedule(function()
done = true
ok = success
data = result
end)
end)
return root_files
end
vim.wait(timeout, function()
return done
end, interval)
function M.insert_package_json(root_files, field, fname)
return M.root_markers_with_field(root_files, { 'package.json', 'package.json5' }, field, fname)
return { ok = ok or false, data = data }
end
return M

1
paq-lock.json Normal file
View File

@@ -0,0 +1 @@
{"nvim-ts-autotag":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/nvim-ts-autotag","name":"nvim-ts-autotag","url":"https://github.com/windwp/nvim-ts-autotag","hash":""},"nvim-autopairs":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/nvim-autopairs","name":"nvim-autopairs","url":"https://github.com/windwp/nvim-autopairs","hash":""},"conform.nvim":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/conform.nvim","name":"conform.nvim","url":"https://github.com/stevearc/conform.nvim","hash":""},"nvim-tree.lua":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/nvim-tree.lua","name":"nvim-tree.lua","url":"https://gitea.tomastm.com/tomas.mirchev/nvim-tree.lua","hash":""},"invero.nvim":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/invero.nvim","name":"invero.nvim","url":"https://github.com/triimd/invero.nvim","hash":""},"mason.nvim":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/opt/mason.nvim","name":"mason.nvim","url":"https://github.com/mason-org/mason.nvim","hash":""},"nvim-lint":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/nvim-lint","name":"nvim-lint","url":"https://github.com/mfussenegger/nvim-lint","hash":""},"paq-nvim":{"status":0,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/opt/paq-nvim","name":"paq-nvim","url":"https://github.com/savq/paq-nvim.git","hash":"971344d1fe1fd93580961815e7b7c8853c3605e4"},"nvim-treesitter":{"status":1,"dir":"/home/tomas/.local/share/nvim/site/pack/paqs/start/nvim-treesitter","name":"nvim-treesitter","url":"https://github.com/nvim-treesitter/nvim-treesitter","hash":""}}