merge nvim settings for 0.6.1
This commit is contained in:
commit
a64bc16a23
3 changed files with 78 additions and 5 deletions
|
|
@ -118,4 +118,8 @@ autocmd FileType java let b:auto_trim_whitespace=1
|
|||
|
||||
augroup templates
|
||||
autocmd BufNewFile *.vue 0r ~/.vim/skeletons/skeleton.vue
|
||||
augroup END
|
||||
augroup end
|
||||
|
||||
augroup rust
|
||||
autocmd FileType rust nnoremap <Leader>lg <cmd>lua rust_where_at_line()<CR>
|
||||
augroup end
|
||||
|
|
|
|||
|
|
@ -7,8 +7,21 @@ local nvim_lsp = require'lspconfig'
|
|||
local on_attach = function(client)
|
||||
end
|
||||
|
||||
local rust_capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
rust_capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
rust_capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||
properties = {
|
||||
'documentation',
|
||||
'detail',
|
||||
'additionalTextEdits',
|
||||
}
|
||||
}
|
||||
|
||||
-- Enable rust_analyzer
|
||||
nvim_lsp.rust_analyzer.setup({ on_attach=on_attach })
|
||||
nvim_lsp.rust_analyzer.setup({
|
||||
on_attach=on_attach,
|
||||
capabilities=rust_capabilities,
|
||||
})
|
||||
nvim_lsp.gopls.setup({ on_attach=on_attach })
|
||||
nvim_lsp.pyright.setup({ on_attach=on_attach })
|
||||
nvim_lsp.clangd.setup({ on_attach=on_attach })
|
||||
|
|
@ -41,6 +54,9 @@ nvim_lsp.efm.setup {
|
|||
},
|
||||
python = {
|
||||
{ formatCommand = 'black --quiet -', formatStdin = true }
|
||||
},
|
||||
rust = {
|
||||
{ formatCommand = 'rustfmt', formatStdin = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -169,7 +185,7 @@ require('lspkind').init({
|
|||
})
|
||||
|
||||
require('trouble').setup {
|
||||
mode = "lsp_document_diagnostics",
|
||||
mode = "document_diagnostics",
|
||||
auto_close = true,
|
||||
action_keys = { -- key mappings for actions in the trouble list
|
||||
-- map to {} to remove a mapping, for example:
|
||||
|
|
@ -257,3 +273,55 @@ git_grep_word = function(conf)
|
|||
for k,v in pairs(conf) do opt[k] = v end
|
||||
builtin.grep_string(opt)
|
||||
end
|
||||
|
||||
|
||||
function string.insert(str1, str2, pos)
|
||||
return str1:sub(1,pos)..str2..str1:sub(pos+1)
|
||||
end
|
||||
|
||||
function string.split(s, delimiter)
|
||||
result = {};
|
||||
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
|
||||
table.insert(result, match);
|
||||
end
|
||||
return result;
|
||||
end
|
||||
|
||||
local function rust_whereify_line(line, var_name)
|
||||
if string.find(line, "fn") == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local paren = string.find(line, "%(")
|
||||
if paren == nil then return nil end
|
||||
|
||||
local open_generic = string.find(line, "<")
|
||||
if open_generic ~= nil then
|
||||
if open_generic < paren then
|
||||
-- TODO(barakmich): it's already generic, we need to do something for that
|
||||
-- probably a different function
|
||||
return nil
|
||||
end
|
||||
-- just continue otherwise
|
||||
end
|
||||
|
||||
local whitespace = string.match(line, "^(%s*)")
|
||||
|
||||
local generic = "<"..var_name..">"
|
||||
local out = string.insert(line, generic, paren - 1)
|
||||
|
||||
local brace = string.find(out, "%{")
|
||||
if brace == nil then brace = string.len(out) end
|
||||
|
||||
out = string.insert(out, "\n"..whitespace.."where\n"..whitespace.." "..var_name..": ,\n"..whitespace, brace - 1)
|
||||
|
||||
return string.split(out, "\n")
|
||||
end
|
||||
|
||||
function rust_where_at_line()
|
||||
local var_name = vim.fn.input("Variable: ")
|
||||
local lineNum, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
local replacements = rust_whereify_line(vim.api.nvim_get_current_line(), var_name)
|
||||
vim.api.nvim_buf_set_lines(0, lineNum-1, lineNum, false, replacements)
|
||||
vim.api.nvim_win_set_cursor(0, {lineNum + 2, 4})
|
||||
end
|
||||
|
|
|
|||
5
.vimrc
5
.vimrc
|
|
@ -268,7 +268,8 @@ nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
|
|||
"nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
|
||||
nnoremap <silent> ga <cmd>lua require('telescope.builtin').lsp_code_actions({initial_mode = "normal"})<cr>
|
||||
vnoremap <silent> ga :<C-U>lua require('telescope.builtin').lsp_range_code_actions({initial_mode = "normal"})<cr>
|
||||
nnoremap <silent> ge <cmd>lua vim.lsp.diagnostic.show_line_diagnostics({show_header = false, focusable = false})<CR>
|
||||
"nnoremap <silent> ge <cmd>lua vim.lsp.diagnostic.show_line_diagnostics({show_header = false, focusable = false})<CR>
|
||||
nnoremap <silent> ge <cmd>lua vim.diagnostic.open_float({focusable = false})<CR>
|
||||
|
||||
nnoremap <leader>xx <cmd>TroubleToggle<cr>
|
||||
|
||||
|
|
@ -276,7 +277,7 @@ nnoremap <leader>xx <cmd>TroubleToggle<cr>
|
|||
" 300ms of no cursor movement to trigger CursorHold
|
||||
set updatetime=500
|
||||
" Show diagnostic popup on cursor hold
|
||||
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics({show_header = false, focusable = false})
|
||||
autocmd CursorHold * lua vim.diagnostic.open_float({focusable = false})
|
||||
|
||||
" Autoformat on save
|
||||
autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 1000)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue