Update deprecated function calls in Neovim 0.10

Also replace nvim-ts-context-commentstring with ts-comments.nvim.
This commit is contained in:
Hoang Nguyen 2024-05-22 00:00:00 +07:00
parent 1a0cfdbf8b
commit e62f1ccebc
Signed by: folliehiyuki
GPG key ID: B0567C20730E9B11
19 changed files with 62 additions and 71 deletions

View file

@ -43,11 +43,11 @@ This Neovim config used to live within [my dotfiles](/FollieHiyuki/dotfiles-ansi
- [otter.nvim](https://github.com/jmbuhr/otter.nvim)
- [nvim-rulebook](https://github.com/chrisgrieser/nvim-rulebook)
- [lazy-nix-helper.nvim](https://github.com/b-src/lazy-nix-helper.nvim) (to turn this repo into a proper Nix Flake)
- LuaSnip -> [nvim-snippets](https://github.com/garymjr/nvim-snippets)
### Logic
- Smooth colorschemes changing (dynamic highlight groups registration via event hooks)
- `vim.loop` -> `vim.uv` in Neovim 0.10.0
- [Neorocks](https://github.com/nvim-neorocks) looks cool :)
## FAQ

View file

@ -1,6 +0,0 @@
local o = vim.opt_local
o.list = false
o.softtabstop = 2
o.tabstop = 2
o.expandtab = false
o.commentstring = "// %s"

1
after/ftplugin/cue.lua Symbolic link
View file

@ -0,0 +1 @@
go.lua

View file

@ -57,7 +57,7 @@ vim.filetype.add {
['.*'] = {
priority = -math.huge,
function(_, bufnr)
local first_line = vim.filetype.getlines(bufnr, 1)
local first_line = vim.api.nvim_buf_get_lines(bufnr, 0, 1, false)[1] or ''
---@diagnostic disable-next-line: param-type-mismatch
if first_line:find('^#!.*[%s/]nft %-f$') then
return 'nftables'

View file

@ -1,6 +1,6 @@
{
"LuaSnip": { "branch": "master", "commit": "de1a287c9cb525ae52bc846e8f6207e5ef1da5ac" },
"SchemaStore.nvim": { "branch": "main", "commit": "de73a884679a2461c53f96035894ef073a5a7f4f" },
"SchemaStore.nvim": { "branch": "main", "commit": "4d30877ccb3499e74d3a835956258e51501785ff" },
"aerial.nvim": { "branch": "master", "commit": "97a838ccc03ba010a667cba49d9820f6823f4d51" },
"alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" },
"better-escape.nvim": { "branch": "master", "commit": "7e86edafb8c7e73699e0320f225464a298b96d12" },
@ -14,16 +14,15 @@
"codesnap.nvim": { "branch": "main", "commit": "a223fd882953e56ae1a8747fdc44b8d6a2ff7a9b" },
"conform.nvim": { "branch": "master", "commit": "00f9d91391b04b1935e2f15948bd96cc111e7d3a" },
"dial.nvim": { "branch": "master", "commit": "7af2daaaf933b0617ded0f78b49f4d5fc45f9f64" },
"diffview.nvim": { "branch": "main", "commit": "9bdd5537575c2ea7925b71ae06585b934beea13d" },
"diffview.nvim": { "branch": "main", "commit": "ad03c42b2899117ff039d84ac24860a77116204b" },
"dressing.nvim": { "branch": "master", "commit": "572314728cb1ce012e825fd66331f52c94acac12" },
"emmylua-nvim": { "branch": "master", "commit": "e82defceb9235f8ea0307be61f833c454c961967" },
"flash.nvim": { "branch": "main", "commit": "11a2e667d19d8f48c93c6ed2e2e525ac6b1b79be" },
"flatten.nvim": { "branch": "main", "commit": "e420e531d2ab24aebcf7b3c9fca28e6c5c34964d" },
"friendly-snippets": { "branch": "main", "commit": "dd2fd1281d4b22e7b4a5bfafa3e142d958e251f2" },
"git-conflict.nvim": { "branch": "main", "commit": "4c8e252b87d54d944c1e56bfb477f78b6fdaf661" },
"gitsigns.nvim": { "branch": "main", "commit": "805610a9393fa231f2c2b49cb521bfa413fadb3d" },
"headlines.nvim": { "branch": "master", "commit": "618ef1b2502c565c82254ef7d5b04402194d9ce3" },
"heirline.nvim": { "branch": "master", "commit": "fe7a8e8a747f156f6eac86ec75122652cf9563f4" },
"heirline.nvim": { "branch": "master", "commit": "0d797435e54645a5f98bad7ad6046aac1ef95c1e" },
"hurl.nvim": { "branch": "main", "commit": "ca3e78a9039ef3faa8e813bf215efba9687df487" },
"icon-picker.nvim": { "branch": "master", "commit": "3ee9a0ea9feeef08ae35e40c8be6a2fa2c20f2d3" },
"inc-rename.nvim": { "branch": "main", "commit": "7c6125b1ee476b56708a6518a37b2a3357f57bfc" },
@ -40,11 +39,11 @@
"mini.move": { "branch": "main", "commit": "251d541a8ab745e81295a53c128829cb2bff18e3" },
"mini.pairs": { "branch": "main", "commit": "5c975d8f68dc1e11bf4b20ced71e7987ed782513" },
"mini.surround": { "branch": "main", "commit": "c52aa751daf62d4a9e6ee24c4a91882ef6842f99" },
"neo-tree.nvim": { "branch": "main", "commit": "8c75e8a2949cd6cd35525799200a8d34471ee9eb" },
"neoconf.nvim": { "branch": "main", "commit": "d321ba056f06e079da99924b948a45dfbacdfba9" },
"neo-tree.nvim": { "branch": "main", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" },
"neoconf.nvim": { "branch": "main", "commit": "9092129e9a42ae26375001bd2e6118f8d57c7f2a" },
"neogen": { "branch": "main", "commit": "6de0add4805165317ab7d3d36b5cef48b1b865f3" },
"neogit": { "branch": "master", "commit": "b93316d15c590377f50ca61e70e9129e4aa9b848" },
"neotest": { "branch": "master", "commit": "5caac5cc235d495a2382bc2980630ef36ac87032" },
"neogit": { "branch": "master", "commit": "5b7bad8056a65578a7fbd1c703850245594d0f9f" },
"neotest": { "branch": "master", "commit": "420288eb84d228986131d3e6ac1d099514bc502c" },
"neotest-go": { "branch": "main", "commit": "92950ad7be2ca02a41abca5c6600ff6ffaf5b5d6" },
"neotest-jest": { "branch": "main", "commit": "514fd4eae7da15fd409133086bb8e029b65ac43f" },
"neotest-python": { "branch": "master", "commit": "2e83d2bc00acbcc1fd529dbf0a0e677cabfe6b50" },
@ -57,29 +56,28 @@
"nvim-coverage": { "branch": "main", "commit": "aa4b4400588e2259e87e372b1e4e90ae13cf5a39" },
"nvim-dap": { "branch": "master", "commit": "5a2f7121869394502521c52b2bc581ab22c69447" },
"nvim-dap-repl-highlights": { "branch": "master", "commit": "a7512fc0a0de0c0be8d58983939856dda6f72451" },
"nvim-dap-ui": { "branch": "master", "commit": "71bfe9bd6b3465e169b53bea4f83775034d822dd" },
"nvim-dap-ui": { "branch": "master", "commit": "334cf3038c4756e6ab999cbac67c847fb654c190" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "3e8e207513e6ef520894950acd76b79902714103" },
"nvim-lint": { "branch": "master", "commit": "1f98d6c863f91706369d74aeb2eb3f02b2e96861" },
"nvim-lspconfig": { "branch": "master", "commit": "9bda20fb967075355f253911bc066a8b5a03c77e" },
"nvim-lspconfig": { "branch": "master", "commit": "0b8165cf95806bc4bb8f745bb0c92021b2ed4b98" },
"nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" },
"nvim-scrollbar": { "branch": "main", "commit": "35f99d559041c7c0eff3a41f9093581ceea534e8" },
"nvim-spectre": { "branch": "master", "commit": "50e96602153f14c913e1969aaf9720e080394eb3" },
"nvim-treesitter": { "branch": "master", "commit": "7c9c5bed8340031f8a6dad47a58a26eaf15b9a56" },
"nvim-treesitter": { "branch": "master", "commit": "73fb37ed77b18ac357ca8e6e35835a8db6602332" },
"nvim-treesitter-context": { "branch": "master", "commit": "55e29081e73d2e4b2d62fb4dc3eebe21bf66a1e2" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "5f9bf4b1ead7707e4e74e5319ee56bdc81fb73db" },
"nvim-ts-autotag": { "branch": "main", "commit": "cb57b07803476ee902c89412aeff219a9a58be13" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "cbab9ad88036915beebd13b47e100743ff2ed2d5" },
"nvim-ts-autotag": { "branch": "main", "commit": "6f38e4231c34497259121a007c61a0fd2f16403e" },
"nvim-web-devicons": { "branch": "master", "commit": "e37bb1feee9e7320c76050a55443fa843b4b6f83" },
"nvim-window-picker": { "branch": "main", "commit": "41cfaa428577c53552200a404ae9b3a0b5719706" },
"oil.nvim": { "branch": "master", "commit": "06a19f77f1a1da37b675635e6f9c5b5d50bcaacd" },
"orgmode": { "branch": "master", "commit": "d2fde796eec52d9ecc4ac045a6d1b3bff83cbfe7" },
"orgmode": { "branch": "master", "commit": "2f9635943eb62bdbbacb3ee23c0db63ddf768513" },
"overseer.nvim": { "branch": "master", "commit": "7a9b654df4b3b246d05fff857f32e9fb8ddfb013" },
"pantran.nvim": { "branch": "main", "commit": "1417ad3630e703e9cc13d2b657149ab8891a8131" },
"parinfer-rust": { "branch": "master", "commit": "d84828b453e158d06406f6b5e9056f6b54ff76c9" },
"persistence.nvim": { "branch": "main", "commit": "5fe077056c821aab41f87650bd6e1c48cd7dd047" },
"plenary.nvim": { "branch": "master", "commit": "b5c8de02a44ffeabff678090edd6a132ff8ab77d" },
"plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" },
"project.nvim": { "branch": "main", "commit": "8c6bad7d22eef1b71144b401c9f74ed01526a4fb" },
"rainbow-delimiters.nvim": { "branch": "master", "commit": "dd1156723eb8483e4403eb8765bbdff456b6981d" },
"rainbow-delimiters.nvim": { "branch": "master", "commit": "5d0d30b201566ce1fe31415f41fe2a7bdf56f4a7" },
"scope.nvim": { "branch": "main", "commit": "86a0f5b594b08b2ad65f470ffdee81654942b6ac" },
"sniprun": { "branch": "master", "commit": "9006d4af4f7016523f8619ae1526ab4e7f0df785" },
"ssr.nvim": { "branch": "main", "commit": "bb323ba621ac647b4ac5638b47666e3ef3c279e1" },
@ -92,6 +90,7 @@
"toggleterm.nvim": { "branch": "main", "commit": "fee58a0473fd92b28c34f8f724e4918b15ba30a3" },
"treesj": { "branch": "main", "commit": "e1e82ab4237619d342c7102c9f13d4b9833bfd39" },
"trouble.nvim": { "branch": "main", "commit": "a8264a65a0b894832ea642844f5b7c30112c458f" },
"ts-comments.nvim": { "branch": "main", "commit": "02476c3371a24a15213bb5033a3bf0f47fd4d499" },
"twilight.nvim": { "branch": "main", "commit": "8b7b50c0cb2dc781b2f4262a5ddd57571556d1e4" },
"undotree": { "branch": "master", "commit": "56c684a805fe948936cda0d1b19505b84ad7e065" },
"venn.nvim": { "branch": "main", "commit": "b09c2f36ddf70b498281845109bedcf08a7e0de0" },

View file

@ -28,7 +28,7 @@ vim.api.nvim_create_autocmd('FileType', {
pattern = { 'checkhealth', 'log' },
callback = function(args)
-- Only do this to Neovim related log files
if vim.api.nvim_buf_get_option(args.buf, 'filetype') == 'log'
if vim.api.nvim_get_option_value('filetype', { buf = args.buf }) == 'log'
and vim.fn.expand('%:p:h') ~= vim.fn.stdpath('log')
then
return

View file

@ -67,7 +67,7 @@ map('n', '[w', diagnostic_goto(false, 'WARN'), { desc = 'Previous warning' })
-- toggle LSP settings
map('n', '<leader>ud', require('user.plugins.lsp.lspconfig.diagnostic').toggle, { desc = 'Toggle diagnostics' })
map('n', '<leader>uv', require('user.plugins.lsp.lspconfig.diagnostic').toggle_virtual_lines, { desc = 'Toggle virtual lines diagnostics' })
map('n', '<leader>uy', function() vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled()) end, { desc = 'Toggle inlay hints' })
map('n', '<leader>uy', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled {}) end, { desc = 'Toggle inlay hints' })
-- toggle editor settings
map('n', '<leader>ur', function() util.toggle('relativenumber', true) end, { desc = 'Toggle relativenumber' })

View file

@ -1,5 +1,5 @@
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
if not vim.uv.fs_stat(lazypath) then
vim.fn.system {
'git',
'clone',

View file

@ -8,8 +8,8 @@ M.loglevel = vim.log.levels.INFO
-- Some default LSP options (can be toggled)
M.lsp_format_on_save = false
M.lsp_virtual_lines = true
M.lsp_inlay_hints = true
M.lsp_virtual_lines = false
M.lsp_inlay_hints = false
M.lsp_document_highlight = true
-- Only 'bottom_pane', 'horizontal' or 'cursor' right now

View file

@ -44,6 +44,7 @@ cmp.setup {
},
},
formatting = {
expandable_indicator = false,
fields = { 'kind', 'abbr', 'menu' },
format = function(entry, vim_item)
vim_item.menu = sources_config[entry.source.name].item_menu

View file

@ -22,11 +22,4 @@ return {
require('user.plugins.completion.cmp')
end,
},
{
'ii14/emmylua-nvim',
-- we only care about the EmmyLua files (loaded by lua-language-server)
init = function()
require('lazy.core.loader').disable_rtp_plugin('emmylua-nvim')
end,
},
}

View file

@ -21,8 +21,8 @@ dap.adapters.go = function(callback, config)
math.randomseed(os.time())
local port = (config.connect or config).port or (38000 + math.random(1, 1000))
local stdout = vim.loop.new_pipe(false)
local stderr = vim.loop.new_pipe(false)
local stdout = vim.uv.new_pipe(false)
local stderr = vim.uv.new_pipe(false)
local handle, pid_or_err
local function on_read(err, chunk)
@ -42,7 +42,7 @@ dap.adapters.go = function(callback, config)
end)
end
handle, pid_or_err = vim.loop.spawn('dlv', {
handle, pid_or_err = vim.uv.spawn('dlv', {
stdio = { nil, stdout, stderr },
args = { 'dap', '--listen', string.format('%s:%s', host, port) },
detached = true,

View file

@ -23,6 +23,11 @@ return {
end)
end,
},
{
'folke/ts-comments.nvim',
event = 'VeryLazy',
config = true,
},
{
'folke/todo-comments.nvim',
cmd = { 'TodoTrouble', 'TodoTelescope' },
@ -95,6 +100,7 @@ return {
'glimmer',
'astro',
'handlebars',
'templ',
},
opts = {
filetypes = {
@ -335,19 +341,7 @@ return {
{ 'gc', mode = { 'n', 'x' }, desc = 'Toggle comment' },
{ 'gcc', mode = 'n', desc = 'Toggle comment on current line' },
},
dependencies = {
{ 'JoosepAlviste/nvim-ts-context-commentstring', opts = { enable_autocmd = false } },
},
opts = {
options = {
custom_commentstring = function()
return require('ts_context_commentstring.internal').calculate_commentstring() or vim.bo.commentstring
end,
},
},
config = function(_, opts)
require('mini.comment').setup(opts)
end,
config = true,
},
{
'echasnovski/mini.surround',

View file

@ -53,11 +53,11 @@ require('orgmode').setup {
local task_type = string.format('%s: <%s>', task.type, task.time:to_string())
local task_description = string.format('%s %s %s', string.rep('*', task.level), task.todo, task.title)
require('lazy.core.util').info(string.format('%s\n%s', task_description, task_type), {
title = { task.category, task.humanized_duration },
title = string.format('%s (%s)', task.category, task.humanized_duration),
icon = '󱣹 ',
on_open = function(win)
local buf = vim.api.nvim_win_get_buf(win)
vim.api.nvim_buf_set_option(buf, 'filetype', 'org')
vim.api.nvim_set_option_value('filetype', 'org', { buf = buf })
end,
})
end

View file

@ -32,7 +32,7 @@ return {
lint.linters_by_ft = opts.linters_by_ft
local function debounce(ms, fn)
local timer = vim.loop.new_timer()
local timer = vim.uv.new_timer()
return function(...)
local argv = { ... }
timer:start(ms, 0, function()

View file

@ -2,12 +2,21 @@ local M = {}
local lazy_util = require('lazy.core.util')
local vars = require('user.config.vars')
-- TODO: nvim-0.10.0 can have different virtual_text prefix per severity
local function set_virtual_text()
if vars.lsp_virtual_lines then
return false
end
return { prefix = '', spacing = 2, source = 'if_many' }
return {
prefix = function(diag)
for type, icon in pairs(vars.icons.notify) do
if diag.severity == vim.diagnostic.severity[type:upper()] then
return icon .. ' '
end
end
end,
spacing = 2,
source = 'if_many',
}
end
function M.configure_diagnostic()
@ -65,7 +74,7 @@ function M.toggle_virtual_lines()
-- Configure diagnostic again for the new settings
vim.diagnostic.config {
virtual_text = set_virtual_text(),
virtual_lines = vars.lsp_virtual_lines
virtual_lines = vars.lsp_virtual_lines,
}
if vars.lsp_virtual_lines then
@ -82,7 +91,7 @@ function M.toggle()
vim.diagnostic.enable()
lazy_util.info('LSP diagnostic enabled', { title = 'Diagnostic' })
else
vim.diagnostic.disable()
vim.diagnostic.enable(false)
lazy_util.warn('LSP diagnostic disabled', { title = 'Diagnostic' })
end
end

View file

@ -14,13 +14,12 @@ vim.api.nvim_create_autocmd('LspAttach', {
require('user.plugins.lsp.lspconfig.keymap').on_attach(client, buffer)
-- Inlay hints
-- TODO: uncomment when nvim-0.10.0 is out
-- if vars.lsp_inlay_hints and client.supports_method('textDocument/inlayHint') then
-- vim.lsp.inlay_hint.enable(buffer)
-- end
if vars.lsp_inlay_hints and client and client.supports_method('textDocument/inlayHint', { bufnr = buffer }) then
vim.lsp.inlay_hint.enable(true, { bufnr = buffer })
end
-- Bulb for code action hint in statusbar
if client.supports_method('textDocument/codeAction') then
if client and client.supports_method('textDocument/codeAction', { bufnr = buffer }) then
vim.api.nvim_create_autocmd({ 'CursorHold', 'InsertLeave' }, {
group = vim.api.nvim_create_augroup('LspCodeAction', {}),
callback = require('user.util.lsp').codeAction_on_attach,
@ -29,7 +28,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
end
-- Refresh codelens
if client.supports_method('textDocument/codeLens') then
if client and client.supports_method('textDocument/codeLens', { bufnr = buffer }) then
vim.api.nvim_create_autocmd({ 'InsertLeave', 'BufEnter', 'CursorHold' }, {
group = vim.api.nvim_create_augroup('LspCodeLens', {}),
callback = vim.lsp.codelens.refresh,
@ -38,7 +37,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
end
-- Document highlight
if vars.lsp_document_highlight and client.supports_method('textDocument/documentHighlight') then
if vars.lsp_document_highlight and client and client.supports_method('textDocument/documentHighlight', { bufnr = buffer }) then
local augroup = 'LspDocumentHighlight'
vim.api.nvim_create_augroup(augroup, {})
@ -55,7 +54,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
end
-- Prefer hover capability from other LSP servers (pylsp/pyright/pylyzer)
if client.name == 'ruff_lsp' then
if client and client.name == 'ruff_lsp' then
client.server_capabilities.hoverProvider = false
end
end,

View file

@ -47,7 +47,7 @@ local components = {
},
file_readonly = {
text = function(buffer)
return (buffer.is_readonly or not vim.api.nvim_buf_get_option(buffer.number, 'modifiable')) and '' or ''
return (buffer.is_readonly or not vim.api.nvim_get_option_value('modifiable', {buf = buffer.number })) and '' or ''
end,
fg = colors.red,
truncation = { priority = 3, direction = 'left' },

View file

@ -4,7 +4,7 @@ local lazy_util = require('lazy.core.util')
--- Return the list of active LSP clients
---@return table
function M.active_lsp_clients(opts)
local clients = vim.lsp.get_active_clients(opts)
local clients = vim.lsp.get_clients(opts)
if opts and opts.method then
clients = vim.tbl_filter(function(client)
return client.supports_method(opts.method, { bufnr = opts.bufnr })
@ -18,7 +18,7 @@ end
---@return table
function M.active_linters(bufnr)
local lint = require('lint')
local ft = vim.api.nvim_buf_get_option(bufnr, 'filetype')
local ft = vim.api.nvim_get_option_value('filetype', { buf = bufnr })
local linters = vim.list_slice(lint._resolve_linter_by_ft(ft))

View file

@ -16,7 +16,8 @@ end
---@param plugin string
---@return boolean
function M.loaded(plugin)
return require('lazy.core.config').plugins[plugin]._.loaded
local config = require('lazy.core.config')
return config.plugins[plugin] and config.plugins[plugin]._.loaded
end
--- Switch between defined values of an option