nvim: tsserver should turbo-repo support v1

nix-components
pegasust 2022-11-21 22:16:34 +00:00
parent cb25a46af5
commit 9a0c7407b3
1 changed files with 116 additions and 102 deletions

View File

@ -56,11 +56,16 @@ vim.keymap.set('n', '<leader>wq', '<cmd>TroubleToggle workspace_diagnostics<cr>'
-- vim-plug -- vim-plug
local data_dir = vim.fn.stdpath('data') local data_dir = vim.fn.stdpath('data')
vim.cmd([[ vim.cmd([[
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' " Install vim-plug if not found
if empty(glob(data_dir . '/autoload/plug.vim')) if empty(glob('~/.vim/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif endif
" Run PlugInstall if there are missing plugins
autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)'))
\| PlugInstall --sync | source $MYVIMRC
\| endif
]]) ]])
local Plug = vim.fn['plug#'] local Plug = vim.fn['plug#']
@ -417,6 +422,77 @@ local on_attach = function(_client, bufnr)
end, '[W]orkspace [L]ist Folders') end, '[W]orkspace [L]ist Folders')
end end
-- nvim-cmp
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local lspkind = require('lspkind')
local source_mapping = {
buffer = '[Buffer]',
nvim_lsp = '[LSP]',
nvim_lua = '[Lua]',
-- cmp_tabnine = '[T9]',
path = '[Path]',
}
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
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' }),
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.symbolic(vim_item.kind, { mode = 'symbol' })
vim_item.menu = source_mapping[entry.source_name]
-- if entry.source.name == "cmp_tabnine" then
-- local detail = (entry.completion_item.data or {}).detail
-- vim_item.kind = ""
-- if detail and detail:find('.*%%.*') then
-- vim_item.kind = vim_item.kind .. ' ' .. detail
-- end
--
-- if (entry.completion_item.data or {}).multiline then
-- vim_item.kind = vim_item.kind .. ' ' .. '[ML]'
-- end
-- end
local maxwidth = 80
vim_item.abbr = string.sub(vim_item.abbr, 1, maxwidth)
return vim_item
end,
},
sources = cmp.config.sources {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
-- { name = 'cmp_tabnine' },
},
}
-- nvim-cmp supports additional completion capabilities -- nvim-cmp supports additional completion capabilities
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
-- local tabnine = require('cmp_tabnine.config') -- local tabnine = require('cmp_tabnine.config')
@ -475,13 +551,22 @@ require('mason-lspconfig').setup_handlers({
enable = true, enable = true,
defaultConfig = { defaultConfig = {
indent_style = "space", indent_style = "space",
indent_size = 2, indent_size = 4,
} }
} }
} }
} }
} }
end, end,
["tsserver"] = function()
require('lspconfig').tsserver.setup {
on_attach = on_attach,
capabilities = capabilities,
-- Monorepo support: spawn one instance of lsp within the git
-- repos.
root_dir = require('lspconfig.util').root_pattern('.git')
}
end,
-- ["rust_analyzer"] = function() -- ["rust_analyzer"] = function()
-- require('lspconfig').rust_analyzer.setup { -- require('lspconfig').rust_analyzer.setup {
-- on_attach = on_attach, -- on_attach = on_attach,
@ -737,77 +822,6 @@ require('zk.commands').add("ZkGrep", function(match_ctor)
require('zk').edit(match, { title = "Grep: '" .. grep_str .. "'" }) require('zk').edit(match, { title = "Grep: '" .. grep_str .. "'" })
end) end)
-- nvim-cmp
local cmp = require 'cmp'
local luasnip = require 'luasnip'
local lspkind = require('lspkind')
local source_mapping = {
buffer = '[Buffer]',
nvim_lsp = '[LSP]',
nvim_lua = '[Lua]',
-- cmp_tabnine = '[T9]',
path = '[Path]',
}
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert {
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
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' }),
},
formatting = {
format = function(entry, vim_item)
vim_item.kind = lspkind.symbolic(vim_item.kind, { mode = 'symbol' })
vim_item.menu = source_mapping[entry.source_name]
-- if entry.source.name == "cmp_tabnine" then
-- local detail = (entry.completion_item.data or {}).detail
-- vim_item.kind = ""
-- if detail and detail:find('.*%%.*') then
-- vim_item.kind = vim_item.kind .. ' ' .. detail
-- end
--
-- if (entry.completion_item.data or {}).multiline then
-- vim_item.kind = vim_item.kind .. ' ' .. '[ML]'
-- end
-- end
local maxwidth = 80
vim_item.abbr = string.sub(vim_item.abbr, 1, maxwidth)
return vim_item
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
-- { name = 'cmp_tabnine' },
},
}
-- Gitsigns -- Gitsigns
require('gitsigns').setup { require('gitsigns').setup {