Migrate Neovim config to 0.12
This commit is contained in:
@@ -92,7 +92,7 @@ au('VimEnter', {
|
||||
au('TextYankPost', {
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.highlight.on_yank({ timeout = 200 })
|
||||
vim.hl.on_yank({ timeout = 200 })
|
||||
end,
|
||||
})
|
||||
|
||||
@@ -131,6 +131,43 @@ au({ 'WinLeave', 'InsertEnter' }, {
|
||||
})
|
||||
|
||||
-- Autocompletion
|
||||
local function convert_completion_item(item)
|
||||
local converted = {}
|
||||
|
||||
if item.kind then
|
||||
local kind = vim.lsp.protocol.CompletionItemKind[item.kind] or ''
|
||||
converted.menu = '[' .. kind .. ']'
|
||||
end
|
||||
|
||||
local _, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local next_char = vim.api.nvim_get_current_line():sub(col + 1, col + 1)
|
||||
if next_char ~= '"' and next_char ~= "'" then
|
||||
return converted
|
||||
end
|
||||
|
||||
local completion_text
|
||||
if item.textEdit then
|
||||
completion_text = item.textEdit.newText
|
||||
elseif item.insertText and item.insertText ~= '' then
|
||||
completion_text = item.insertText
|
||||
else
|
||||
completion_text = item.label
|
||||
end
|
||||
|
||||
if completion_text and completion_text:sub(-1) == next_char then
|
||||
local trimmed = completion_text:sub(1, -2)
|
||||
converted.word = trimmed
|
||||
|
||||
if item.textEdit and item.textEdit.newText == completion_text then
|
||||
item.textEdit.newText = trimmed
|
||||
elseif item.insertText == completion_text then
|
||||
item.insertText = trimmed
|
||||
end
|
||||
end
|
||||
|
||||
return converted
|
||||
end
|
||||
|
||||
au('LspAttach', {
|
||||
group = group,
|
||||
callback = function(event)
|
||||
@@ -141,22 +178,12 @@ au('LspAttach', {
|
||||
|
||||
-- Enable native completion
|
||||
if client:supports_method('textDocument/completion') then
|
||||
vim.lsp.completion.enable(true, client.id, event.buf, { autotrigger = true })
|
||||
vim.lsp.completion.enable(true, client.id, event.buf, {
|
||||
convert = convert_completion_item,
|
||||
})
|
||||
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,
|
||||
|
||||
@@ -84,10 +84,20 @@ map('n', '<leader>E', cmd('NvimTreeOpen'))
|
||||
|
||||
-- Diagnostics
|
||||
map('n', ']d', function()
|
||||
vim.diagnostic.jump({ count = 1, float = true })
|
||||
vim.diagnostic.jump({
|
||||
count = 1,
|
||||
on_jump = function()
|
||||
vim.diagnostic.open_float()
|
||||
end,
|
||||
})
|
||||
end)
|
||||
map('n', '[d', function()
|
||||
vim.diagnostic.jump({ count = -1, float = true })
|
||||
vim.diagnostic.jump({
|
||||
count = -1,
|
||||
on_jump = function()
|
||||
vim.diagnostic.open_float()
|
||||
end,
|
||||
})
|
||||
end)
|
||||
map('n', '<leader>q', vim.diagnostic.setloclist)
|
||||
map('n', '<leader>d', vim.diagnostic.open_float)
|
||||
|
||||
@@ -86,7 +86,11 @@ vim.opt.hlsearch = true -- Highlight all matches after searching
|
||||
vim.opt.shortmess:remove('S') -- Show search count, e.g. [3/17]
|
||||
|
||||
vim.opt.inccommand = 'split' -- Preview substitutions live in a split
|
||||
vim.opt.completeopt = { 'fuzzy', 'menuone', 'popup', 'noselect' }
|
||||
vim.opt.autocomplete = true
|
||||
vim.opt.autocompletedelay = 60
|
||||
vim.opt.autocompletetimeout = 120
|
||||
vim.opt.complete = { 'o' }
|
||||
vim.opt.completeopt = { 'menuone', 'popup', 'noselect', 'noinsert' }
|
||||
|
||||
-- Splits
|
||||
vim.opt.splitright = true
|
||||
|
||||
@@ -39,7 +39,7 @@ function M.get()
|
||||
{ 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 = 'biome', format = 'biome' },
|
||||
{ ft = { 'json', 'jsonc' }, ts = 'json', lsp = 'biome', format = 'biome' },
|
||||
{ ft = 'html', lsp = 'html-lsp' },
|
||||
{ ft = 'css', lsp = { 'css-lsp', 'tailwindcss-language-server' } },
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local function my_on_attach(bufnr)
|
||||
local api = require('nvim-tree.api')
|
||||
local opts = { buffer = bufnr }
|
||||
local opts = { buf = bufnr }
|
||||
|
||||
-- basics: copy/cut/paste/create/rename/remove
|
||||
vim.keymap.set('n', 'c', api.fs.copy.node, opts)
|
||||
|
||||
@@ -877,7 +877,7 @@ end
|
||||
-- Input handlers
|
||||
---------------------------------------------------------------------
|
||||
local function attach_handlers()
|
||||
local opts = { buffer = S.buf_inp, nowait = true, silent = true, noremap = true }
|
||||
local opts = { buf = 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)
|
||||
|
||||
@@ -9,6 +9,7 @@ local M = {
|
||||
M.group = vim.api.nvim_create_augroup('language-manager', { clear = true })
|
||||
|
||||
local cache_path = vim.fn.stdpath('cache') .. '/language-manager.json'
|
||||
local cache_version = 2
|
||||
|
||||
local function wrap(item)
|
||||
if type(item) == 'string' then
|
||||
@@ -162,6 +163,14 @@ function M.generate_specs(specs_raw)
|
||||
spec.ts = spec.ts or spec.ft
|
||||
specs.add(spec.ts, 'ts_parsers')
|
||||
|
||||
local tree_sitter_filetypes = wrap(spec.ft)
|
||||
if #tree_sitter_filetypes == 0 then
|
||||
tree_sitter_filetypes = wrap(spec.ts)
|
||||
end
|
||||
for _, ft in ipairs(tree_sitter_filetypes) do
|
||||
specs.add(spec.ts, 'ts_parsers_by_ft', ft)
|
||||
end
|
||||
|
||||
install_spec.add(spec.lsp, 'code_tools')
|
||||
local resolved_lsps = {}
|
||||
for _, language_server in ipairs(wrap(spec.lsp)) do
|
||||
@@ -209,11 +218,11 @@ function M.load_specs()
|
||||
local specs_raw = require('modules.language-specs').get()
|
||||
local hash = hash_spec(specs_raw)
|
||||
local cache = load_cache()
|
||||
if cache and cache.hash == hash then
|
||||
if cache and cache.version == cache_version and cache.hash == hash then
|
||||
M.general = cache.spec
|
||||
else
|
||||
M.general, M.mason = M.generate_specs(specs_raw)
|
||||
save_cache({ hash = hash, spec = M.general })
|
||||
save_cache({ version = cache_version, hash = hash, spec = M.general })
|
||||
end
|
||||
return M.general, M.mason
|
||||
end
|
||||
@@ -231,8 +240,13 @@ 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)
|
||||
if vim.fn.executable('tree-sitter') == 0 then
|
||||
error('tree-sitter CLI 0.26.1+ is required to install nvim-treesitter parsers')
|
||||
end
|
||||
require('nvim-treesitter').setup({
|
||||
install_dir = vim.fn.stdpath('data') .. '/site',
|
||||
})
|
||||
require('nvim-treesitter').install(M.general.ts_parsers):wait(5 * 60 * 1000)
|
||||
end
|
||||
|
||||
function M.mason_install()
|
||||
@@ -287,9 +301,20 @@ function M.install()
|
||||
end
|
||||
|
||||
function M.ts.setup()
|
||||
require('nvim-treesitter.configs').setup({
|
||||
highlight = { enable = true },
|
||||
incremental_selection = { enable = true },
|
||||
require('nvim-treesitter').setup({
|
||||
install_dir = vim.fn.stdpath('data') .. '/site',
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
group = M.group,
|
||||
callback = function(args)
|
||||
local parsers = M.general
|
||||
and M.general.ts_parsers_by_ft
|
||||
and M.general.ts_parsers_by_ft[vim.bo[args.buf].filetype]
|
||||
if parsers and #parsers > 0 then
|
||||
vim.treesitter.start(args.buf)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ function M.get()
|
||||
{ '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/nvim-treesitter/nvim-treesitter', version = 'main' },
|
||||
{ 'https://github.com/mfussenegger/nvim-lint' },
|
||||
{ 'https://github.com/stevearc/conform.nvim' },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user