327 lines
8.4 KiB
Lua
327 lines
8.4 KiB
Lua
require('nvim-autopairs').setup{}
|
|
|
|
-- nvim_lsp object
|
|
local nvim_lsp = require'lspconfig'
|
|
|
|
-- function to attach completion when setting up lsp
|
|
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,
|
|
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 })
|
|
|
|
function org_imports(wait_ms)
|
|
local params = vim.lsp.util.make_range_params()
|
|
|
|
params.context = {only = {"source.organizeImports"}}
|
|
|
|
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms)
|
|
|
|
for _, res in pairs(result or {}) do
|
|
for _, r in pairs(res.result or {}) do
|
|
if r.edit then
|
|
vim.lsp.util.apply_workspace_edit(r.edit)
|
|
else
|
|
vim.lsp.buf.execute_command(r.command)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
nvim_lsp.efm.setup {
|
|
init_options = {documentFormatting = true},
|
|
settings = {
|
|
rootMarkers = {".git/"},
|
|
languages = {
|
|
lua = {
|
|
{ formatCommand = "lua-format -i", formatStdin = true }
|
|
},
|
|
python = {
|
|
{ formatCommand = 'black --quiet -', formatStdin = true }
|
|
},
|
|
rust = {
|
|
{ formatCommand = 'rustfmt', formatStdin = true }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
-- Enable diagnostics
|
|
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
|
vim.lsp.diagnostic.on_publish_diagnostics, {
|
|
virtual_text = false,
|
|
signs = true,
|
|
update_in_insert = false,
|
|
}
|
|
)
|
|
|
|
-- Compe setup
|
|
require'compe'.setup {
|
|
enabled = true;
|
|
autocomplete = true;
|
|
debug = false;
|
|
min_length = 1;
|
|
preselect = 'disable';
|
|
throttle_time = 80;
|
|
source_timeout = 200;
|
|
incomplete_delay = 400;
|
|
max_abbr_width = 100;
|
|
max_kind_width = 100;
|
|
max_menu_width = 100;
|
|
documentation = true;
|
|
|
|
source = {
|
|
path = true;
|
|
nvim_lsp = true;
|
|
};
|
|
}
|
|
|
|
signature_cfg = {
|
|
hint_enable = true,
|
|
hint_prefix = "% ",
|
|
handler_opts = {
|
|
border = "none"
|
|
},
|
|
}
|
|
|
|
require'lsp_signature'.on_attach(signature_cfg)
|
|
|
|
saga_cfg = {
|
|
code_action_prompt = {
|
|
enable = false,
|
|
sign = false,
|
|
virtual_text = false,
|
|
},
|
|
}
|
|
-- require'lspsaga'.init_lsp_saga(saga_cfg)
|
|
|
|
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 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>"
|
|
else
|
|
return t "<S-Tab>"
|
|
end
|
|
end
|
|
|
|
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
|
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
|
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
|
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
|
|
|
require('lspkind').init({
|
|
-- disables text annotations
|
|
--with_text = false,
|
|
with_text = true,
|
|
|
|
-- default symbol map
|
|
-- can be either 'default' or 'codicons'
|
|
preset = 'default',
|
|
|
|
-- override preset symbols
|
|
-- default: {}
|
|
--symbol_map = {
|
|
--Method = 'm',
|
|
--Function = 'f',
|
|
--Text = 'txt',
|
|
--Constructor = 'new',
|
|
--Variable = 'var',
|
|
--Class = 'cls',
|
|
--Interface = 'iface',
|
|
--Module = 'mod',
|
|
--Property = 'prop',
|
|
--Unit = 'unit',
|
|
--Value = 'val',
|
|
--Enum = 'enum',
|
|
--Keyword = 'kw',
|
|
--Snippet = 'sn',
|
|
--Color = 'color',
|
|
--File = 'file',
|
|
--Folder = 'fold',
|
|
--EnumMember = 'enum',
|
|
--Constant = 'const',
|
|
--Struct = 'struct',
|
|
--},
|
|
})
|
|
|
|
require('trouble').setup {
|
|
mode = "document_diagnostics",
|
|
auto_close = true,
|
|
action_keys = { -- key mappings for actions in the trouble list
|
|
-- map to {} to remove a mapping, for example:
|
|
-- close = {},
|
|
--close = "q", -- close the list
|
|
--cancel = "<esc>", -- cancel the preview and get back to your last window / buffer / cursor
|
|
--refresh = "r", -- manually refresh
|
|
jump = {"o", "<tab>"}, -- jump to the diagnostic or open / close folds
|
|
--open_split = { "<c-x>" }, -- open buffer in new split
|
|
--open_vsplit = { "<c-v>" }, -- open buffer in new vsplit
|
|
open_tab = { }, -- open buffer in new tab
|
|
jump_close = {"<cr>"}, -- jump to the diagnostic and close the list
|
|
toggle_mode = "m", -- toggle between "workspace" and "document" diagnostics mode
|
|
toggle_preview = "P", -- toggle auto_preview
|
|
hover = "K", -- opens a small popup with the full multiline message
|
|
preview = "p", -- preview the diagnostic location
|
|
close_folds = {"zM", "zm"}, -- close all folds
|
|
open_folds = {"zR", "zr"}, -- open all folds
|
|
toggle_fold = {"zA", "za"}, -- toggle fold of current file
|
|
previous = "k", -- previous item
|
|
next = "j" -- next item
|
|
},
|
|
}
|
|
|
|
require('telescope').setup {
|
|
defaults = {
|
|
mappings = {
|
|
n = {
|
|
["q"] = require('telescope.actions').close,
|
|
},
|
|
},
|
|
},
|
|
pickers = {
|
|
lsp_code_actions = {
|
|
theme = "ivy",
|
|
layout_config = {
|
|
height = 10,
|
|
},
|
|
},
|
|
lsp_range_code_actions = {
|
|
theme = "ivy",
|
|
layout_config = {
|
|
height = 10,
|
|
},
|
|
},
|
|
lsp_references = {
|
|
theme = "ivy",
|
|
layout_config = {
|
|
height = 15,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
local builtin = require'telescope.builtin'
|
|
|
|
local dropdown = require'telescope.themes'.get_dropdown({
|
|
--previewer = false,
|
|
--prompt_title = "",
|
|
--results_height = 16,
|
|
--width = 0.6,
|
|
--borderchars = {
|
|
--{"─", "│", "─", "│", "╭", "╮", "╯", "╰"},
|
|
--prompt = {"─", "│", " ", "│", "╭", "╮", "│", "│"},
|
|
--results = {"─", "│", "─", "│", "├", "┤", "╯", "╰"},
|
|
--preview = {"─", "│", "─", "│", "╭", "╮", "╯", "╰"}
|
|
--},
|
|
--winblend = 10
|
|
})
|
|
|
|
live_grep_repo = function(conf)
|
|
--local opt = dropdown
|
|
local opt = {
|
|
cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
|
}
|
|
for k,v in pairs(conf) do opt[k] = v end
|
|
builtin.live_grep(opt)
|
|
end
|
|
|
|
git_grep_word = function(conf)
|
|
--local opt = dropdown
|
|
local opt = {
|
|
cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
|
|
}
|
|
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
|