-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc90586
commit 1357433
Showing
3 changed files
with
143 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,114 @@ | ||
" Set completeopt to have a better completion experience | ||
" :help completeopt | ||
" Completion | ||
" Better completion | ||
" menuone: popup even when there's only one match | ||
" noinsert: Do not insert text until a selection is made | ||
" noselect: Do not select, force user to select one from the menu | ||
set completeopt=menuone,noinsert,noselect | ||
|
||
" Avoid showing extra messages when using completion | ||
set shortmess+=c | ||
|
||
" Set updatetime for CursorHold | ||
" 300ms of no cursor movement to trigger CursorHold | ||
set completeopt+=menuone,noinsert,noselect | ||
" Better display for messages | ||
set cmdheight=2 | ||
" You will have bad experience for diagnostic messages when it's default 4000. | ||
set updatetime=300 | ||
" Show diagnostic popup on cursor hold | ||
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics() | ||
|
||
" Enable type inlay hints | ||
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * | ||
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} } | ||
" LSP configuration | ||
lua << EOF | ||
local cmp = require'cmp' | ||
cmp.setup({ | ||
snippet = { | ||
-- REQUIRED by nvim-cmp. get rid of it once we can | ||
expand = function(args) | ||
vim.fn["vsnip#anonymous"](args.body) | ||
end, | ||
}, | ||
mapping = cmp.mapping.preset.insert({ | ||
-- Tab immediately completes. C-n/C-p to select. | ||
--['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}), | ||
--['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}), | ||
['<Tab>'] = cmp.mapping.confirm({ select = true }), | ||
}), | ||
sources = cmp.config.sources({ | ||
-- TODO: currently snippets from lsp end up getting prioritized -- stop that! | ||
{ name = 'nvim_lsp' }, | ||
}, { | ||
name = 'buffer' | ||
}), | ||
completion = { | ||
completeopt = 'menu,menuone,noinsert' | ||
}, | ||
experimental = { | ||
ghost_text = true, | ||
}, | ||
}) | ||
|
||
" Enable code actions (Alt + .) | ||
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR> | ||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). | ||
cmp.setup.cmdline(':', { | ||
mapping = cmp.mapping.preset.cmdline({ | ||
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}), | ||
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}), | ||
['<Tab>'] = cmp.mapping.confirm({ select = true }), | ||
}), | ||
sources = cmp.config.sources({ | ||
{ name = 'path' } | ||
}, { | ||
{ name = 'cmdline' } | ||
}) | ||
}) | ||
|
||
" Auto format (Ctrl + Shift + I) | ||
nnoremap <silent> <C-S-I> <cmd>lua vim.lsp.buf.formatting()<CR> | ||
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR> | ||
-- Setup lspconfig. | ||
local on_attach = function(client, bufnr) | ||
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 | ||
|
||
lua << EOF | ||
-- nvim_lsp object | ||
local nvim_lsp = require'lspconfig' | ||
--Enable completion triggered by <c-x><c-o> | ||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | ||
|
||
-- Mappings. | ||
local opts = { noremap=true, silent=true } | ||
-- function to attach completion when setting up lsp | ||
local on_attach = function(client) | ||
require'completion'.on_attach(client) | ||
-- See `:help vim.lsp.*` for documentation on any of the below functions | ||
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', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | ||
buf_set_keymap('n', '<space>r', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | ||
buf_set_keymap('n', '<space>a', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | ||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | ||
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<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', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | ||
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | ||
end | ||
|
||
-- enable rust_analyzer | ||
nvim_lsp.rust_analyzer.setup { | ||
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) | ||
local lspconfig = require'lspconfig' | ||
lspconfig.rust_analyzer.setup { | ||
on_attach = on_attach, | ||
flags = { | ||
debounce_text_changes = 150, | ||
}, | ||
settings = { | ||
["rust-analyzer"] = { | ||
assist = { | ||
importMergeBehavior = "last", | ||
importPrefix = "by_self", | ||
}, | ||
diagnostics = { | ||
disabled = { "unresolved-import" } | ||
}, | ||
cargo = { | ||
loadOutDirsFromCheck = true | ||
}, | ||
procMacro = { | ||
enable = true | ||
allFeatures = true, | ||
}, | ||
checkOnSave = { | ||
command = "clippy" | ||
}, | ||
} | ||
} | ||
}, | ||
}, | ||
capabilities = capabilities, | ||
} | ||
|
||
-- enable ccls | ||
nvim_lsp.ccls.setup{on_attach=on_attach} | ||
-- Enable diagnostics | ||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( | ||
vim.lsp.diagnostic.on_publish_diagnostics, { | ||
virtual_text = true, | ||
signs = true, | ||
update_in_insert = true, | ||
} | ||
) | ||
EOF | ||
|
||
" Enable type inlay hints | ||
autocmd CursorHold,CursorHoldI *.rs | ||
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} } | ||
|
This file was deleted.
Oops, something went wrong.