Skip to content

Commit

Permalink
chore: assorted updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rafi committed May 17, 2024
1 parent accc67c commit e6acb61
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 70 deletions.
4 changes: 3 additions & 1 deletion lua/rafi/plugins/coding.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ return {
require('luasnip.loaders.from_lua').load({ paths = { './snippets' } })
end,
},
-- Adds luasnip source to nvim-cmp.
{
'nvim-cmp',
dependencies = {
{ 'saadparwaiz1/cmp_luasnip' },
-- Luasnip completion source for nvim-cmp
'saadparwaiz1/cmp_luasnip',
},
opts = function(_, opts)
opts.snippet = {
Expand Down
2 changes: 1 addition & 1 deletion lua/rafi/plugins/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
return {

-----------------------------------------------------------------------------
-- Statusline plugin written in pure lua
-- Statusline plugin with many customizations.
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
Expand Down
65 changes: 38 additions & 27 deletions lua/rafi/plugins/neo-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@

local winwidth = 30

local function toggle_width()
local max = winwidth * 2
local cur_width = vim.fn.winwidth(0)
local half = math.floor((winwidth + (max - winwidth) / 2) + 0.4)
local new_width = winwidth
if cur_width == winwidth then
new_width = half
elseif cur_width == half then
new_width = max
else
new_width = winwidth
end
vim.cmd(new_width .. ' wincmd |')
end

local function get_current_directory(state)
local node = state.tree:get_node()
if node.type ~= 'directory' or not node:is_expanded() then
Expand Down Expand Up @@ -77,13 +92,23 @@ return {
vim.cmd([[Neotree close]])
end,
init = function()
if vim.fn.argc(-1) == 1 then
local arg = vim.fn.argv(0) --[[@as string]]
local stat = vim.uv.fs_stat(arg)
if stat and stat.type == 'directory' then
require('neo-tree')
end
end
-- FIX: use `autocmd` for lazy-loading neo-tree instead of directly requiring it,
-- because `cwd` is not set up properly.
vim.api.nvim_create_autocmd('BufEnter', {
group = vim.api.nvim_create_augroup('Neotree_start_directory', { clear = true }),
desc = 'Start Neo-tree with directory',
once = true,
callback = function()
if package.loaded['neo-tree'] then
return
else
local stats = vim.uv.fs_stat(vim.fn.argv(0))
if stats and stats.type == 'directory' then
require('neo-tree')
end
end
end,
})
end,
-- See: https://github.com/nvim-neo-tree/neo-tree.nvim
opts = {
Expand All @@ -98,8 +123,8 @@ return {
show_scrolled_off_parent_node = true,
padding = { left = 1, right = 0 },
sources = {
{ source = 'filesystem', display_name = '  Files' }, --      
{ source = 'buffers', display_name = '  Buffers' }, --     
{ source = 'filesystem', display_name = '  Files' }, --      
{ source = 'buffers', display_name = '  Buffers' }, --      
{ source = 'git_status', display_name = ' 󰊢 Git' }, -- 󰊢      
},
},
Expand Down Expand Up @@ -182,7 +207,7 @@ return {
},

-- Custom commands
['w'] = 'toggle_width',
['w'] = toggle_width,
['K'] = function(state)
local node = state.tree:get_node()
local path = node:get_id()
Expand All @@ -205,22 +230,6 @@ return {
},
},
filesystem = {
commands = {
toggle_width = function()
local max = winwidth * 2
local cur_width = vim.fn.winwidth(0)
local half = math.floor((winwidth + (max - winwidth) / 2) + 0.4)
local new_width = winwidth
if cur_width == winwidth then
new_width = half
elseif cur_width == half then
new_width = max
else
new_width = winwidth
end
vim.cmd(new_width .. ' wincmd |')
end
},
window = {
mappings = {
['d'] = 'noop',
Expand Down Expand Up @@ -267,7 +276,9 @@ return {
'.stfolder',
'.stversions',
},
never_show = {},
never_show_by_pattern = {
'vite.config.js.timestamp-*',
},
},
find_by_full_path_words = true,
group_empty_dirs = true,
Expand Down
3 changes: 2 additions & 1 deletion lua/rafi/plugins/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ return {
cmd = 'Telescope',
dependencies = {
'nvim-lua/plenary.nvim',
-- Telescope extension for Zoxide
'jvgrootveld/telescope-zoxide',
'folke/todo-comments.nvim',
-- Browse synonyms for a word
'rafi/telescope-thesaurus.nvim',
},
config = function(_, opts)
Expand Down
59 changes: 32 additions & 27 deletions lua/rafi/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ return {
version = false,
build = ':TSUpdate',
event = { 'LazyFile', 'VeryLazy' },
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
cmd = { 'TSInstall', 'TSUpdate', 'TSUpdateSync' },
keys = {
{ 'v', desc = 'Increment Selection', mode = 'x' },
Expand All @@ -33,33 +34,6 @@ return {
require('nvim-treesitter.query_predicates')
end,
dependencies = {
-- Textobjects using treesitter queries
{
'nvim-treesitter/nvim-treesitter-textobjects',
config = function()
-- When in diff mode, we want to use the default
-- vim text objects c & C instead of the treesitter ones.
local move = require('nvim-treesitter.textobjects.move') ---@type table<string,fun(...)>
local configs = require('nvim-treesitter.configs')
for name, fn in pairs(move) do
if name:find('goto') == 1 then
move[name] = function(q, ...)
if vim.wo.diff then
local config = configs.get_module('textobjects.move')[name] ---@type table<string,string>
for key, query in pairs(config or {}) do
if q == query and key:find('[%]%[][cC]') then
vim.cmd('normal! ' .. key)
return
end
end
end
return fn(q, ...)
end
end
end
end,
},

-- Modern matchit and matchparen
{
'andymass/vim-matchup',
Expand All @@ -71,6 +45,7 @@ return {
-- Wisely add "end" in various filetypes
'RRethy/nvim-treesitter-endwise',
},
---@diagnostic disable-next-line: undefined-doc-name
---@type TSConfig
---@diagnostic disable-next-line: missing-fields
opts = {
Expand Down Expand Up @@ -199,6 +174,7 @@ return {
'zig',
},
},
---@diagnostic disable-next-line: undefined-doc-name
---@param opts TSConfig
config = function(_, opts)
local langs = opts.ensure_installed
Expand All @@ -217,6 +193,35 @@ return {
end,
},

-----------------------------------------------------------------------------
-- Textobjects using treesitter queries
{
'nvim-treesitter/nvim-treesitter-textobjects',
lazy = true,
config = function()
-- When in diff mode, we want to use the default
-- vim text objects c & C instead of the treesitter ones.
local move = require('nvim-treesitter.textobjects.move') ---@type table<string,fun(...)>
local configs = require('nvim-treesitter.configs')
for name, fn in pairs(move) do
if name:find('goto') == 1 then
move[name] = function(q, ...)
if vim.wo.diff then
local config = configs.get_module('textobjects.move')[name] ---@type table<string,string>
for key, query in pairs(config or {}) do
if q == query and key:find('[%]%[][cC]') then
vim.cmd('normal! ' .. key)
return
end
end
end
return fn(q, ...)
end
end
end
end,
},

-----------------------------------------------------------------------------
-- Show context of the current function
{
Expand Down
27 changes: 15 additions & 12 deletions lua/rafi/plugins/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ return {
{ 'MunifTanjim/nui.nvim', lazy = false },

-----------------------------------------------------------------------------
-- Fancy notification manager for NeoVim
-- Fancy notification manager
{
'rcarriga/nvim-notify',
priority = 9000,
Expand Down Expand Up @@ -217,13 +217,6 @@ return {
lsp_doc_border = true,
-- inc_rename = true,
},
commands = {
all = {
view = 'split',
opts = { enter = true, format = 'details' },
filter = {},
},
},
},
},

Expand Down Expand Up @@ -329,9 +322,7 @@ return {
},

-----------------------------------------------------------------------------
-- Active indent guide and indent text objects. When you're browsing
-- code, this highlights the current level of indentation, and animates
-- the highlighting.
-- Visualize and operate on indent scope
{
'echasnovski/mini.indentscope',
event = 'LazyFile',
Expand Down Expand Up @@ -433,7 +424,7 @@ return {
},

-----------------------------------------------------------------------------
-- Better quickfix window in Neovim
-- Better quickfix window
{
'kevinhwang91/nvim-bqf',
ft = 'qf',
Expand Down Expand Up @@ -489,6 +480,18 @@ return {
highlighter = {
auto_enable = true,
lsp = true,
filetypes = {
'html',
'lua',
'css',
'scss',
'sass',
'less',
'stylus',
'javascript',
'tmux',
'typescript',
},
excludes = { 'lazy', 'mason', 'help', 'neo-tree' },
},
},
Expand Down
49 changes: 48 additions & 1 deletion lua/rafi/util/edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ function M.append_modeline()
vim.bo.textwidth,
vim.bo.expandtab and '' or 'no'
)
modeline = string.gsub(vim.bo.commentstring, '%%s', modeline)
local cs = require('ts_context_commentstring.internal').calculate_commentstring()
or vim.bo.commentstring
if not cs then
LazyVim.warn('No commentstring found')
return
end
modeline = string.gsub(cs, '%%s', modeline)
vim.api.nvim_buf_set_lines(0, -1, -1, false, { modeline })
end

Expand Down Expand Up @@ -140,4 +146,45 @@ M.get_tabpage_win_bufs = function(tabpage)
return bufs
end

-- Toggle diagnostics locally (false) or globally (true).
---@param global boolean
M.diagnostic_toggle = function(global)
local cmd, disabled

if vim.fn.has('nvim-0.10') == 1 then
local opts = {}
if not global then
opts.bufnr = vim.api.nvim_get_current_buf()
end
vim.diagnostic.enable(not vim.diagnostic.is_enabled(), opts)
cmd = disabled and 'enable' or 'disable'
else
local bufnr
if global then
bufnr = nil
disabled = vim.g.diagnostics_disabled
vim.g.diagnostics_disabled = not disabled
else
bufnr = 0
if vim.fn.has('nvim-0.9') == 1 then
disabled = vim.diagnostic.is_disabled(bufnr)
else
disabled = vim.b.diagnostics_disabled
vim.b.diagnostics_disabled = not disabled
end
end

cmd = disabled and 'enable' or 'disable'
vim.schedule(function()
vim.diagnostic[cmd](bufnr)
end)
end

local msg = cmd:gsub('^%l', string.upper) .. 'd diagnostics'
if global then
msg = msg .. ' globally'
end
LazyVim.info(msg, { title = 'Diagnostics' })
end

return M

0 comments on commit e6acb61

Please sign in to comment.