diff --git a/dotfiles/neovim/init.lua b/dotfiles/neovim/init.lua index 4a085fb..7e35275 100644 --- a/dotfiles/neovim/init.lua +++ b/dotfiles/neovim/init.lua @@ -49,95 +49,95 @@ vim.cmd [[autocmd BufWritePost plugins.lua PackerCompile]] -- LSP -- https://zenn.dev/botamotch/articles/21073d78bc68bf -- 1. LSP Sever management -require('mason').setup() -require('mason-lspconfig').setup_handlers({ function(server) - local opt = { - -- -- Function executed when the LSP server startup - -- on_attach = function(client, bufnr) - -- local opts = { noremap=true, silent=true } - -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) - -- vim.cmd 'autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000)' - -- end, - capabilities = require('cmp_nvim_lsp').update_capabilities( - vim.lsp.protocol.make_client_capabilities() - ) - } - require('lspconfig')[server].setup(opt) -end }) - --- 2. build-in LSP function --- keyboard shortcut -vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()') -vim.keymap.set('n', 'gf', 'lua vim.lsp.buf.formatting()') -vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()') -vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()') -vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()') -vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()') -vim.keymap.set('n', 'gt', 'lua vim.lsp.buf.type_definition()') -vim.keymap.set('n', 'gn', 'lua vim.lsp.buf.rename()') -vim.keymap.set('n', 'ga', 'lua vim.lsp.buf.code_action()') -vim.keymap.set('n', 'ge', 'lua vim.diagnostic.open_float()') -vim.keymap.set('n', 'g]', 'lua vim.diagnostic.goto_next()') -vim.keymap.set('n', 'g[', 'lua vim.diagnostic.goto_prev()') --- LSP handlers -vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( - vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = false } -) --- Reference highlight -vim.cmd [[ -set updatetime=500 -highlight LspReferenceText cterm=underline ctermfg=1 ctermbg=8 gui=underline guifg=#A00000 guibg=#104040 -highlight LspReferenceRead cterm=underline ctermfg=1 ctermbg=8 gui=underline guifg=#A00000 guibg=#104040 -highlight LspReferenceWrite cterm=underline ctermfg=1 ctermbg=8 gui=underline guifg=#A00000 guibg=#104040 -augroup lsp_document_highlight - autocmd! - autocmd CursorHold,CursorHoldI * lua vim.lsp.buf.document_highlight() - autocmd CursorMoved,CursorMovedI * lua vim.lsp.buf.clear_references() -augroup END -]] - --- 3. completion (hrsh7th/nvim-cmp) -local cmp = require("cmp") -cmp.setup({ - snippet = { - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) - end, - }, - sources = { - { name = "nvim_lsp" }, - -- { name = "buffer" }, - -- { name = "path" }, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [""] = cmp.mapping.confirm { select = true }, - }), - experimental = { - ghost_text = true, - }, -}) --- cmp.setup.cmdline('/', { --- mapping = cmp.mapping.preset.cmdline(), --- sources = { --- { name = 'buffer' } --- } --- }) --- cmp.setup.cmdline(":", { --- mapping = cmp.mapping.preset.cmdline(), --- sources = { --- { name = "path" }, --- { name = "cmdline" }, --- }, --- }) +--require('mason').setup() +--require('mason-lspconfig').setup_handlers({ function(server) +-- local opt = { +-- -- -- Function executed when the LSP server startup +-- -- on_attach = function(client, bufnr) +-- -- local opts = { noremap=true, silent=true } +-- -- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) +-- -- vim.cmd 'autocmd BufWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000)' +-- -- end, +-- capabilities = require('cmp_nvim_lsp').update_capabilities( +-- vim.lsp.protocol.make_client_capabilities() +-- ) +-- } +-- require('lspconfig')[server].setup(opt) +--end }) +-- +---- 2. build-in LSP function +---- keyboard shortcut +--vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()') +--vim.keymap.set('n', 'gf', 'lua vim.lsp.buf.formatting()') +--vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()') +--vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()') +--vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()') +--vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()') +--vim.keymap.set('n', 'gt', 'lua vim.lsp.buf.type_definition()') +--vim.keymap.set('n', 'gn', 'lua vim.lsp.buf.rename()') +--vim.keymap.set('n', 'ga', 'lua vim.lsp.buf.code_action()') +--vim.keymap.set('n', 'ge', 'lua vim.diagnostic.open_float()') +--vim.keymap.set('n', 'g]', 'lua vim.diagnostic.goto_next()') +--vim.keymap.set('n', 'g[', 'lua vim.diagnostic.goto_prev()') +---- LSP handlers +--vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( +-- vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = false } +--) +---- Reference highlight +--vim.cmd [[ +--set updatetime=500 +--highlight LspReferenceText cterm=underline ctermfg=1 ctermbg=8 gui=underline guifg=#A00000 guibg=#104040 +--highlight LspReferenceRead cterm=underline ctermfg=1 ctermbg=8 gui=underline guifg=#A00000 guibg=#104040 +--highlight LspReferenceWrite cterm=underline ctermfg=1 ctermbg=8 gui=underline guifg=#A00000 guibg=#104040 +--augroup lsp_document_highlight +-- autocmd! +-- autocmd CursorHold,CursorHoldI * lua vim.lsp.buf.document_highlight() +-- autocmd CursorMoved,CursorMovedI * lua vim.lsp.buf.clear_references() +--augroup END +--]] +-- +---- 3. completion (hrsh7th/nvim-cmp) +--local cmp = require("cmp") +--cmp.setup({ +-- snippet = { +-- expand = function(args) +-- vim.fn["vsnip#anonymous"](args.body) +-- end, +-- }, +-- sources = { +-- { name = "nvim_lsp" }, +-- -- { name = "buffer" }, +-- -- { name = "path" }, +-- }, +-- mapping = cmp.mapping.preset.insert({ +-- [""] = cmp.mapping.select_prev_item(), +-- [""] = cmp.mapping.select_next_item(), +-- [''] = cmp.mapping.complete(), +-- [''] = cmp.mapping.abort(), +-- [""] = cmp.mapping.confirm { select = true }, +-- }), +-- experimental = { +-- ghost_text = true, +-- }, +--}) +---- cmp.setup.cmdline('/', { +---- mapping = cmp.mapping.preset.cmdline(), +---- sources = { +---- { name = 'buffer' } +---- } +---- }) +---- cmp.setup.cmdline(":", { +---- mapping = cmp.mapping.preset.cmdline(), +---- sources = { +---- { name = "path" }, +---- { name = "cmdline" }, +---- }, +---- }) -- satysfi language server -require('lspconfig')['satysfi-ls'].setup{ - autostart = true -} +--require('lspconfig')['satysfi-ls'].setup{ +-- autostart = true +--} ----------------------------------------------------------- -- Ctrl + P to invoke fzf file search