Add treesitter, tweak completion for narrow terminal

nvim-basic-ide
Andy Teijelo 2022-09-09 13:58:41 -04:00
parent 259bf17eda
commit 5e5fedfa9c
4 changed files with 110 additions and 49 deletions

View File

@ -1,10 +1,10 @@
vim.opt.syntax = 'on'
vim.cmd([[hi MatchParen ctermfg=none ctermbg=none cterm=bold,underline gui=bold,underline guifg=fg guibg=bg
vim.cmd([[
filetype plugin indent on
]])
vim.opt.number = true
-- set relativenumber
vim.opt.relativenumber = true
vim.opt.relativenumber = false
--vim.opt.path += "**"
vim.opt.swapfile = false
vim.opt.wildmenu = true
@ -28,6 +28,8 @@ vim.opt.guicursor = ""
require("colorschemes")
vim.cmd([[hi MatchParen cterm=bold,underline gui=bold,underline]])
vim.api.nvim_set_keymap("n", "<SPACE>", "<Nop>", { noremap = true })
vim.g.mapleader = " "
@ -41,6 +43,9 @@ for _, mode in ipairs({"n", "i"}) do
end
vim.api.nvim_set_keymap("n", "<Leader>o", "<Cmd>lua vim.diagnostic.open_float()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<M-o>", "<Cmd>lua vim.diagnostic.open_float()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<Leader>i", "<Cmd>lua vim.lsp.buf.code_action()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<M-i>", "<Cmd>lua vim.lsp.buf.code_action()<CR>", { noremap = true })
require('plugins')
-- require'lspconfig'.pyright.setup{}
@ -64,53 +69,7 @@ nvim_lsp.pyright.setup{}
-- },
-- })
local cmp = require'cmp'
local snippy = require('snippy')
cmp.setup({
snippet = {
expand = function(args)
snippy.expand_snippet(args.body)
end
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif snippy.can_expand_or_advance() then
snippy.expand_or_advance()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif snippy.can_jump(-1) then
snippy.previous()
else
fallback()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'snippy' },
{ name = 'buffer' },
})
})
require('completion')
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
nvim_lsp.rust_analyzer.setup({
@ -133,6 +92,8 @@ vim.diagnostic.config({
}
})
require('treesitter')
-- -- trouble.nvim mappings
-- vim.api.nvim_set_keymap("n", "<leader>xx", "<cmd>Trouble<cr>",
-- {silent = true, noremap = true}

61
lua/completion.lua 100644
View File

@ -0,0 +1,61 @@
local cmp = require'cmp'
local snippy = require('snippy')
cmp.setup({
snippet = {
expand = function(args)
snippy.expand_snippet(args.body)
end
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif snippy.can_expand_or_advance() then
snippy.expand_or_advance()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif snippy.can_jump(-1) then
snippy.previous()
else
fallback()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'snippy' },
{ name = 'buffer' },
}),
formatting = {
fields = {
cmp.ItemField.Abbr,
cmp.ItemField.Kind,
cmp.ItemField.Menu,
},
format = function(entry, vim_item)
vim_item.abbr = string.sub(vim_item.abbr, 1, 20)
vim_item.kind = string.sub(vim_item.kind, 1, 10)
vim_item.menu = string.sub(vim_item.menu, 1, 10)
return vim_item
end
}
})

View File

@ -17,5 +17,11 @@ packer.startup(
use 'NLKNguyen/papercolor-theme'
use 'olimorris/onedarkpro.nvim'
use 'EdenEast/nightfox.nvim'
use {
'nvim-treesitter/nvim-treesitter',
run = function()
require('nvim-treesitter.install').update({ with_sync = true })
end,
}
end
)

33
lua/treesitter.lua 100644
View File

@ -0,0 +1,33 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
ensure_installed = { "rust" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
auto_install = true,
-- List of parsers to ignore installing (for "all")
ignore_install = { "javascript" },
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
highlight = {
-- `false` will disable the whole extension
enable = true,
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- the name of the parser)
-- list of language that will be disabled
--disable = { "c", "rust" },
-- 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,
},
}