Update neovim config. Remote lsp-zero

This commit is contained in:
Jan Eitzinger 2023-02-24 07:31:04 +01:00
parent 139dcc31d3
commit e115f6e8d6
7 changed files with 253 additions and 140 deletions

View File

@ -0,0 +1,85 @@
local ok, cmp = pcall(require, 'cmp')
if not ok then
return
end
require('luasnip.loaders.from_vscode').lazy_load()
local luasnip = require('luasnip')
local lspkind = require('lspkind')
local select_opts = {behavior = cmp.SelectBehavior.Select}
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
sources = {
{name = 'path'},
{name = 'nvim_lsp', keyword_length = 1},
{name = 'buffer', keyword_length = 3},
{name = 'luasnip', keyword_length = 2},
},
window = {
documentation = cmp.config.window.bordered()
},
formatting = {
format = lspkind.cmp_format({
mode = 'symbol_text', -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
})
},
mapping = {
['<Up>'] = cmp.mapping.select_prev_item(select_opts),
['<Down>'] = cmp.mapping.select_next_item(select_opts),
['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
['<C-n>'] = cmp.mapping.select_next_item(select_opts),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.abort(),
['<C-y>'] = cmp.mapping.confirm({select = true}),
['<CR>'] = cmp.mapping.confirm({select = false}),
['<C-f>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, {'i', 's'}),
['<C-b>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {'i', 's'}),
['<Tab>'] = cmp.mapping(function(fallback)
local col = vim.fn.col('.') - 1
if cmp.visible() then
cmp.select_next_item(select_opts)
elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
fallback()
else
cmp.complete()
end
end, {'i', 's'}),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item(select_opts)
else
fallback()
end
end, {'i', 's'}),
},
})

View File

@ -0,0 +1,14 @@
local ok, hop = pcall(require, 'hop')
if not ok then
return
end
hop.setup {
quit_key = '<SPC>',
uppercase_labels = true
}
local map = vim.keymap.set
map('n', 'f', function() hop.hint_char1({current_line_only = true }) end, {remap=true})
map('n', '<leader>s', function() hop.hint_char2() end, {remap=true})

View File

@ -1,95 +1,21 @@
local ok, lsp = pcall(require, 'lsp-zero')
local ok, lsp = pcall(require, 'lspconfig')
if not ok then
return
end
lsp.preset("recommended")
-- Fix Undefined global 'vim'
lsp.configure('sumneko_lua', {
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
}
}
}
})
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")
local cmp = require('cmp')
local cmp_select = {behavior = cmp.SelectBehavior.Select}
local cmp_mappings = lsp.defaults.cmp_mappings({
['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<C-e>"] = cmp.mapping.abort(),
["<C-Space>"] = cmp.mapping.complete(),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
})
local lspkind = require('lspkind')
local cmp_formatting = {
format = lspkind.cmp_format({
mode = 'symbol_text', -- show only symbol annotations
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
local sign = function(opts)
-- See :help sign_define()
vim.fn.sign_define(opts.name, {
texthl = opts.name,
text = opts.text,
numhl = ''
})
}
lsp.setup_nvim_cmp({
mapping = cmp_mappings,
formatting = cmp_formatting
})
lsp.on_attach(function(client, bufnr)
local bufmap = function(mode, lhs, rhs)
local opts = {buffer = true, remap = false}
vim.keymap.set(mode, lhs, rhs, opts)
end
-- List diagnostics in Telescope
bufmap('n', 'gA', '<cmd>Telescope diagnostics<cr>')
-- Lists all the references
bufmap('n', 'gr', '<cmd>Telescope lsp_references<cr>')
end)
local on_attach_format = function(client)
require("lsp-format").on_attach(client)
end
lsp.configure('clangd', {
on_attach = on_attach_format
})
lsp.nvim_workspace()
lsp.setup()
sign({name = 'DiagnosticSignError', text = ''})
sign({name = 'DiagnosticSignWarn', text = ''})
sign({name = 'DiagnosticSignHint', text = ''})
sign({name = 'DiagnosticSignInfo', text = ''})
vim.diagnostic.config({
virtual_text = false,
@ -101,3 +27,67 @@ vim.diagnostic.config({
prefix = '',
},
})
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
vim.lsp.handlers.hover,
{border = 'rounded'}
)
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
vim.lsp.handlers.signature_help,
{border = 'rounded'}
)
vim.lsp.handlers["workspace/diagnostic/refresh"] = function(_, _, ctx)
local ns = vim.lsp.diagnostic.get_namespace(ctx.client_id)
pcall(vim.diagnostic.reset, ns)
return true
end
require("lsp-format").setup {}
local on_attach = function(client)
local bufmap = function(mode, lhs, rhs)
local opts = {buffer = true}
vim.keymap.set(mode, lhs, rhs, opts)
end
require("lsp-format").on_attach(client)
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
bufmap('n', 'gA', '<cmd>Telescope diagnostics<cr>')
bufmap('n', 'gr', '<cmd>Telescope lsp_references<cr>')
bufmap('n', 'gi', '<cmd>Telescope lsp_implementations<cr>')
bufmap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>')
bufmap('n', '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>')
bufmap('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>')
bufmap('x', '<F4>', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
end
lsp.gopls.setup { on_attach = on_attach }
lsp.clangd.setup { on_attach = on_attach }
lsp.ltex.setup { on_attach = on_attach }
lsp.svelte.setup { on_attach = on_attach }
lsp.tsserver.setup { on_attach = on_attach }
lsp.lua_ls.setup {
settings = {
Lua = {
diagnostics = {
globals = { 'vim' }
},
-- workspace = {
-- library = vim.api.nvim_get_runtime_file("", true),
-- },
-- telemetry = {
-- enable = false,
-- },
}
},
on_attach = on_attach
}

View File

@ -32,3 +32,4 @@ map('n',"<leader>f", "<cmd>Telescope live_grep<cr>")
map('n',"<leader>g", "<cmd>Telescope grep_string<cr>")
map('n',"<leader>b", "<cmd>Telescope buffers<cr>")
map('n',"<leader>h", "<cmd>Telescope help_tags<cr>")
map('n',"z=", "<cmd>Telescope spell_suggest<cr>")

View File

@ -5,24 +5,31 @@ end
treesitter.setup {
-- A list of parser names, or "all"
ensure_installed = "all",
-- Install parsers synchronously (only applied to `ensure_installed`)
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
}
},
},
ensure_installed = {
'javascript',
'typescript',
'css',
'json',
'c',
'lua',
'go'
},
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
highlight = {
-- `false` will disable the whole extension
enable = true,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}

View File

@ -1,26 +1,24 @@
HOME = os.getenv("HOME")
vim.cmd([[colorscheme gruvbox]])
vim.g.mapleader = " "
vim.g.mapleader = ' '
vim.g.maplocalleader = '\\'
-- Plugins
require "paq" {
"savq/paq-nvim";
{"nvim-treesitter/nvim-treesitter", run=function() vim.cmd "TSUpdate" end};
"nvim-treesitter/nvim-treesitter";
"nvim-treesitter/nvim-treesitter-textobjects";
"nvim-tree/nvim-web-devicons";
"onsails/lspkind.nvim";
"VonHeikemen/lsp-zero.nvim";
-- LSP support
"onsails/lspkind.nvim";
"lukas-reineke/lsp-format.nvim";
"neovim/nvim-lspconfig";
"williamboman/mason.nvim";
"williamboman/mason-lspconfig.nvim";
-- "williamboman/mason.nvim";
-- "williamboman/mason-lspconfig.nvim";
-- Autocomplete
"hrsh7th/nvim-cmp";
@ -34,38 +32,52 @@ require "paq" {
"L3MON4D3/LuaSnip";
"rafamadriz/friendly-snippets";
-- Programming support
"kylechui/nvim-surround";
"windwp/nvim-autopairs";
"numToStr/Comment.nvim";
{"phaazon/hop.nvim", branch="v2"};
"nvim-lua/plenary.nvim";
-- Fuzzy search
{"nvim-telescope/telescope-fzf-native.nvim", run="gmake"};
"nvim-telescope/telescope-file-browser.nvim";
"nvim-telescope/telescope.nvim";
"folke/trouble.nvim";
"mfussenegger/nvim-dap";
"theHamsta/nvim-dap-virtual-text";
"rcarriga/nvim-dap-ui";
"NvChad/nvim-colorizer.lua";
"lewis6991/gitsigns.nvim";
-- "ray-x/go.nvim";
"tpope/vim-fugitive";
"renerocksai/telekasten.nvim";
"renerocksai/calendar-vim";
"nvim-lua/plenary.nvim";
"akinsho/toggleterm.nvim";
"nvim-lualine/lualine.nvim";
"ellisonleao/gruvbox.nvim";
}
require('nvim-web-devicons').setup {}
require('lsp-format').setup {}
require('nvim-autopairs').setup()
require('nvim-surround').setup()
require('Comment').setup()
require('hop').setup()
require('dapui').setup()
require('gitsigns').setup()
require("trouble").setup()
require('nvim-autopairs').setup({
fast_wrap = {},
})
require 'colorizer'.setup {
filetypes = {
'css',
'javascript',
scss = { rgb_fn = true; };
html = { mode = 'foreground'; }
},
}
require('lualine').setup {
options = {
@ -76,29 +88,27 @@ require('lualine').setup {
}
}
require('toggleterm').setup({
open_mapping = '<C-g>',
direction = 'horizontal',
shade_terminals = true
})
require("gruvbox").setup {
italic = false,
contrast = "hard"
}
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require('go.format').goimport()
end,
group = format_sync_grp,
})
-- Options
local o = vim.opt
-- basic settings
o.encoding = "utf-8"
o.backspace = "indent,eol,start" -- backspace works on every char in insert mode
o.completeopt = 'menu,menuone,noselect'
o.completeopt = {'menu', 'menuone', 'noselect'}
o.history = 1000
o.dictionary = '/usr/share/dict/words'
-- o.dictionary = '/home/jan/.vim/dict/words'
-- o.dictionary = '/usr/share/dict/words'
o.startofline = true
o.title = true
o.clipboard='unnamedplus'
@ -108,7 +118,8 @@ o.timeoutlen = 200
o.ttimeoutlen = 0
-- Spellchecker
o.spelllang="en_us"
o.spell = false
o.spelllang = { 'en_us' }
o.spellfile= HOME .. '/.vim/spell/en.utf8.add'
o.thesaurus= HOME .. '/.vim/thesaurus/english.txt'
@ -126,7 +137,6 @@ o.list = false -- do not display white characters
o.termguicolors = true
o.background = "dark"
-- o.updatetime = 100
vim.cmd([[highlight SpellBad cterm=undercurl ctermfg=Red]])
-- Folding
o.foldenable = false
@ -140,7 +150,7 @@ o.showbreak= '↪' -- character to show when line is broken
o.number = true -- line number on the left
o.relativenumber = true
o.numberwidth = 3 -- always reserve 3 spaces for line number
o.signcolumn = 'yes' -- keep 1 column for coc.vim check
o.signcolumn = 'yes'
o.modelines = 0
-- Bottombar
@ -193,14 +203,29 @@ o.backup = true -- use backup files
o.writebackup = false
o.swapfile = false -- do not use swap file
o.undofile = true
o.undodir = HOME .. '/.vim/dirs/undo//' -- undo files
o.backupdir = HOME .. '/.vim/dirs/backup//' -- backups
o.undodir = HOME .. '/.local/share/nvim/dirs/undo//' -- undo files
o.backupdir = HOME .. '/.local/share/nvim/dirs/backup//' -- backups
-- Commands mode
o.wildmenu = true -- on TAB, complete options for system command
o.wildignore = 'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc'
-- Mappings {{{
vim.cmd([[
au BufRead,BufNewFile *.md set ft=mkd tw=80 syntax=markdown
]])
vim.api.nvim_create_user_command('ReloadConfig', 'source $MYVIMRC', {})
local group = vim.api.nvim_create_augroup('user_cmds', {clear = true})
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight on yank',
group = group,
callback = function()
vim.highlight.on_yank({higroup = 'Visual', timeout = 200})
end,
})
local map = vim.keymap.set
map({'n','v'}, '<Space>', "<Nop>", { silent = true })
@ -235,10 +260,6 @@ map('n','<leader>q', '<cmd>bdelete<CR>', { silent = true })
map('n','<S-Tab>', '<C-U>')
map('n','<Tab>', '<C-D>')
-- more natural movement with wrap on
map({'n','v'},'j', 'gj', { noremap = true, silent = true })
map({'n','v'},'k', 'gk', { noremap = true, silent = true })
-- Easy buffer navigation
map('n','<C-h>', '<C-w>h', { silent = true })
map('n','<C-j>', '<C-w>j', { silent = true })
@ -249,9 +270,3 @@ map('n','<up>', '<cmd>resize -2<CR>', { silent = true })
map('n','<down>', '<cmd>resize +2<CR>', { silent = true })
map('n','<left>', '<cmd>vertical resize -2<CR>', { silent = true })
map('n','<right>', '<cmd>vertical resize +2<CR>', { silent = true })
map({'n','i'},"<leader>s", "<cmd>HopChar2<cr>", { silent = true })
map('n',"<leader>w", "<cmd>HopWord<cr>", { silent = true })
map('n',"<silent><F6>", "<cmd>:set invspell<cr>", { silent = true })
--}}}

View File

@ -38,11 +38,12 @@ export GPG_TTY=$TTY
{{- if eq .chezmoi.os "openbsd" }}
export PORTSDIR_PATH=/usr/ports/:/usr/ports/openbsd-wip
export PATH="$HOME/local/bin:$HOME/perl5/bin:$HOME/gems/bin:$HOME/.cargo/bin:$HOME/.yarn/bin:$PATH"
export PATH="$HOME/dev/src/ltex-ls-15.2.0/bin:$HOME/local/bin:$HOME/perl5/bin:$HOME/gems/bin:$HOME/.cargo/bin:$HOME/.yarn/bin:$PATH"
export PERL5LIB=$HOME/perl5/lib/perl5
export PERL_LOCAL_LIB_ROOT=$HOME/perl5
export PERL_MB_OPT='--install_base "/home/jan/perl5"'
export PERL_MM_OPT='INSTALL_BASE=/home/jan/perl5'
export JAVA_HOME=/usr/local/jdk-11/
export PMIX_MCA_gds='hash'
alias top='htop'