move to lua and make a poor man's ide
This commit is contained in:
parent
8017c2ac22
commit
f551318edc
14 changed files with 418 additions and 143 deletions
7
lua/completion.lua
Normal file
7
lua/completion.lua
Normal file
|
@ -0,0 +1,7 @@
|
|||
local utils = require('utils')
|
||||
utils.opt('o', 'completeopt', 'menuone,noinsert,noselect')
|
||||
vim.cmd [[set shortmess+=c]]
|
||||
vim.g.completion_confirm_key = ""
|
||||
vim.g.completion_matching_strategy_list = {'exact', 'substring', 'fuzzy'}-- <Tab> to navigate the completion menu
|
||||
utils.map('i', '<S-Tab>', 'pumvisible() ? "\\<C-p>" : "\\<Tab>"', {expr = true})
|
||||
utils.map('i', '<Tab>', 'pumvisible() ? "\\<C-n>" : "\\<Tab>"', {expr = true})
|
78
lua/config/compe.lua
Normal file
78
lua/config/compe.lua
Normal file
|
@ -0,0 +1,78 @@
|
|||
-- Configuration for nvim-compe
|
||||
|
||||
local utils = require('utils')
|
||||
|
||||
vim.cmd [[set shortmess+=c]]
|
||||
utils.opt('o', 'completeopt', 'menuone,noselect')
|
||||
|
||||
require'compe'.setup {
|
||||
enabled = true;
|
||||
autocomplete = true;
|
||||
debug = false;
|
||||
min_length = 1;
|
||||
preselect = 'enable';
|
||||
throttle_time = 80;
|
||||
source_timeout = 200;
|
||||
incomplete_delay = 400;
|
||||
allow_prefix_unmatch = false;
|
||||
max_abbr_width = 1000;
|
||||
max_kind_width = 1000;
|
||||
max_menu_width = 1000000;
|
||||
documentation = true;
|
||||
|
||||
|
||||
source = {
|
||||
path = true;
|
||||
buffer = true;
|
||||
calc = true;
|
||||
vsnip = true;
|
||||
nvim_lsp = true;
|
||||
nvim_lua = true;
|
||||
spell = true;
|
||||
tags = true;
|
||||
snippets_nvim = true;
|
||||
treesitter = true;
|
||||
};
|
||||
}
|
||||
|
||||
local t = function(str)
|
||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||
end
|
||||
|
||||
local check_back_space = function()
|
||||
local col = vim.fn.col('.') - 1
|
||||
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Use (s-)tab to:
|
||||
--- move to prev/next item in completion menuone
|
||||
--- jump to prev/next snippet's placeholder
|
||||
-- _G.tab_complete = function()
|
||||
-- if vim.fn.pumvisible() == 1 then
|
||||
-- return t "<C-n>"
|
||||
-- elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
||||
-- return t "<Plug>(vsnip-expand-or-jump)"
|
||||
-- elseif check_back_space() then
|
||||
-- return t "<Tab>"
|
||||
-- else
|
||||
-- return vim.fn['compe#complete']()
|
||||
-- end
|
||||
-- end
|
||||
-- _G.s_tab_complete = function()
|
||||
-- if vim.fn.pumvisible() == 1 then
|
||||
-- return t "<C-p>"
|
||||
-- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
|
||||
-- return t "<Plug>(vsnip-jump-prev)"
|
||||
-- else
|
||||
-- return t "<S-Tab>"
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- utils.map("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||
-- utils.map("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||
-- utils.map("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||
-- utils.map("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
2
lua/config/init.lua
Normal file
2
lua/config/init.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- nvim-compe
|
||||
require('config.compe')
|
2
lua/keymappings.lua
Normal file
2
lua/keymappings.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
local utils = require('utils')
|
||||
utils.map('n', '<C-h>', '<cmd>noh<CR>') -- Clear highlights
|
133
lua/lang.lua
Normal file
133
lua/lang.lua
Normal file
|
@ -0,0 +1,133 @@
|
|||
USER = vim.fn.expand('$USER')
|
||||
|
||||
-- Language specific key mappings
|
||||
--require('lang.keymappings')
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
|
||||
require'lsp_signature'.on_attach(client)
|
||||
|
||||
local function buf_set_keymap(...)
|
||||
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
||||
end
|
||||
local function buf_set_option(...)
|
||||
vim.api.nvim_buf_set_option(bufnr, ...)
|
||||
end
|
||||
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings.
|
||||
local opts = {noremap = true, silent = true}
|
||||
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||
buf_set_keymap('n', '[l', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
||||
buf_set_keymap('n', ']l', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||
buf_set_keymap('n', '<leader>law', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||
buf_set_keymap('n', '<leader>lrw', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||
buf_set_keymap('n', '<leader>llw', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||
buf_set_keymap('n', '<leader>lt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||
buf_set_keymap('n', '<leader>lrn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||
buf_set_keymap('n', '<leader>lca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||
|
||||
-- Set some keybinds conditional on server capabilities
|
||||
if client.resolved_capabilities.document_formatting then
|
||||
buf_set_keymap("n", "<leader>lf",
|
||||
"<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
||||
elseif client.resolved_capabilities.document_range_formatting then
|
||||
buf_set_keymap("n", "<leader>lf",
|
||||
"<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
||||
end
|
||||
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.api.nvim_exec([[
|
||||
hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
|
||||
hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
|
||||
hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
|
||||
augroup lsp_document_highlight
|
||||
autocmd! * <buffer>
|
||||
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]], false)
|
||||
end
|
||||
end
|
||||
|
||||
local nvim_lsp = require('lspconfig')
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
|
||||
-- Code actions
|
||||
capabilities.textDocument.codeAction = {
|
||||
dynamicRegistration = true,
|
||||
codeActionLiteralSupport = {
|
||||
codeActionKind = {
|
||||
valueSet = (function()
|
||||
local res = vim.tbl_values(vim.lsp.protocol.CodeActionKind)
|
||||
table.sort(res)
|
||||
return res
|
||||
end)()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true;
|
||||
|
||||
-- LSPs
|
||||
local servers = {"pylsp", "rust_analyzer", "vimls"}
|
||||
for _, lsp in ipairs(servers) do
|
||||
nvim_lsp[lsp].setup {capabilities = capabilities, on_attach = on_attach}
|
||||
end
|
||||
|
||||
-- symbols-outline.nvim
|
||||
vim.g.symbols_outline = {
|
||||
highlight_hovered_item = true,
|
||||
show_guides = true,
|
||||
auto_preview = false, -- experimental
|
||||
position = 'right',
|
||||
keymaps = {
|
||||
close = "<Esc>",
|
||||
goto_location = "<Cr>",
|
||||
focus_location = "o",
|
||||
hover_symbol = "<C-space>",
|
||||
rename_symbol = "r",
|
||||
code_actions = "a"
|
||||
},
|
||||
lsp_blacklist = {}
|
||||
}
|
||||
|
||||
-- LSP Enable diagnostics
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
||||
vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
virtual_text = false,
|
||||
underline = true,
|
||||
signs = true,
|
||||
update_in_insert = false
|
||||
})
|
||||
|
||||
-- Send diagnostics to quickfix list
|
||||
do
|
||||
local method = "textDocument/publishDiagnostics"
|
||||
local default_handler = vim.lsp.handlers[method]
|
||||
vim.lsp.handlers[method] = function(err, method, result, client_id, bufnr,
|
||||
config)
|
||||
default_handler(err, method, result, client_id, bufnr, config)
|
||||
local diagnostics = vim.lsp.diagnostic.get_all()
|
||||
local qflist = {}
|
||||
for bufnr, diagnostic in pairs(diagnostics) do
|
||||
for _, d in ipairs(diagnostic) do
|
||||
d.bufnr = bufnr
|
||||
d.lnum = d.range.start.line + 1
|
||||
d.col = d.range.start.character + 1
|
||||
d.text = d.message
|
||||
table.insert(qflist, d)
|
||||
end
|
||||
end
|
||||
vim.lsp.util.set_qflist(qflist)
|
||||
end
|
||||
end
|
27
lua/lsp_lua.lua
Normal file
27
lua/lsp_lua.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
-- Your custom attach function for nvim-lspconfig goes here.
|
||||
local on_attach = function(client, bufnr)
|
||||
require('completion').on_attach()
|
||||
|
||||
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
||||
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
||||
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings
|
||||
local opts = { noremap=true, silent=true }
|
||||
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||
buf_set_keymap('n', 'H', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||
buf_set_keymap('n', '<C-h>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||
|
||||
end
|
||||
|
||||
-- To get builtin LSP running, do something like:
|
||||
-- NOTE: This replaces the calls where you would have before done `require('nvim_lsp').sumneko_lua.setup()`
|
||||
--require('nlua.lsp.nvim').setup(require('lspconfig'), {
|
||||
-- on_attach = on_attach,
|
||||
--})
|
44
lua/plugins.lua
Normal file
44
lua/plugins.lua
Normal file
|
@ -0,0 +1,44 @@
|
|||
return require('packer').startup(function()
|
||||
|
||||
-- Packer can manage itself as an optional plugin
|
||||
use {'wbthomason/packer.nvim', opt = true}
|
||||
|
||||
-- Fuzzy finder
|
||||
use {
|
||||
'nvim-telescope/telescope.nvim',
|
||||
requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}
|
||||
}
|
||||
|
||||
-- LSP and completion
|
||||
use { 'neovim/nvim-lspconfig' }
|
||||
use { 'nvim-lua/completion-nvim' }
|
||||
|
||||
-- Lua development
|
||||
use { 'tjdevries/nlua.nvim' }
|
||||
|
||||
|
||||
-- Vim dispatch
|
||||
use { 'tpope/vim-dispatch' }
|
||||
|
||||
-- Fugitive for Git
|
||||
use { 'tpope/vim-fugitive' }
|
||||
|
||||
-- Fugitive for Git
|
||||
use { 'ray-x/lsp_signature.nvim' }
|
||||
|
||||
-- Airline status bar
|
||||
use { 'vim-airline/vim-airline' }
|
||||
use { 'vim-airline/vim-airline-themes' }
|
||||
|
||||
use { 'cespare/vim-toml' }
|
||||
use { 'folke/trouble.nvim' }
|
||||
use { 'glepnir/lspsaga.nvim' }
|
||||
use { 'hrsh7th/nvim-compe' }
|
||||
use { 'jacoborus/tender.vim' }
|
||||
use { 'kyazdani42/nvim-web-devicons' }
|
||||
use { 'RRethy/vim-illuminate' }
|
||||
use { 'rust-lang/rust.vim' }
|
||||
use { 'scrooloose/nerdtree' }
|
||||
use { 'vim-scripts/DrawIt' }
|
||||
|
||||
end)
|
24
lua/settings.lua
Normal file
24
lua/settings.lua
Normal file
|
@ -0,0 +1,24 @@
|
|||
local utils = require('utils')
|
||||
|
||||
local cmd = vim.cmd
|
||||
local indent = 4
|
||||
|
||||
cmd 'syntax enable'
|
||||
cmd 'filetype plugin indent on'
|
||||
utils.opt('b', 'expandtab', true)
|
||||
utils.opt('b', 'shiftwidth', indent)
|
||||
utils.opt('b', 'smartindent', true)
|
||||
utils.opt('b', 'tabstop', indent)
|
||||
utils.opt('o', 'hidden', true)
|
||||
utils.opt('o', 'ignorecase', true)
|
||||
utils.opt('o', 'scrolloff', 4 )
|
||||
utils.opt('o', 'shiftround', true)
|
||||
utils.opt('o', 'smartcase', true)
|
||||
utils.opt('o', 'splitbelow', true)
|
||||
utils.opt('o', 'splitright', true)
|
||||
utils.opt('o', 'wildmode', 'list:longest')
|
||||
utils.opt('w', 'number', true)
|
||||
utils.opt('o', 'clipboard','unnamed,unnamedplus')
|
||||
|
||||
-- Highlight on yank
|
||||
vim.cmd 'au TextYankPost * lua vim.highlight.on_yank {on_visual = false}'
|
16
lua/utils/init.lua
Normal file
16
lua/utils/init.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
local utils = { }
|
||||
|
||||
local scopes = {o = vim.o, b = vim.bo, w = vim.wo}
|
||||
|
||||
function utils.opt(scope, key, value)
|
||||
scopes[scope][key] = value
|
||||
if scope ~= 'o' then scopes['o'][key] = value end
|
||||
end
|
||||
|
||||
function utils.map(mode, lhs, rhs, opts)
|
||||
local options = {noremap = true}
|
||||
if opts then options = vim.tbl_extend('force', options, opts) end
|
||||
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
|
||||
end
|
||||
|
||||
return utils
|
Loading…
Add table
Add a link
Reference in a new issue