update vimrc from hermia

This commit is contained in:
Barak Michener 2022-07-19 14:11:08 -07:00
parent c864b6df9f
commit 9cac6e0f85
2 changed files with 162 additions and 150 deletions

View file

@ -1,7 +1,7 @@
require('nvim-autopairs').setup{}
require('nvim-autopairs').setup {}
-- nvim_lsp object
local nvim_lsp = require'lspconfig'
local nvim_lsp = require 'lspconfig'
-- function to attach completion when setting up lsp
local on_attach = function(client)
@ -18,19 +18,29 @@ rust_capabilities.textDocument.completion.completionItem.resolveSupport = {
}
-- Enable rust_analyzer
nvim_lsp.rust_analyzer.setup({
on_attach=on_attach,
capabilities=rust_capabilities,
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 })
nvim_lsp.gopls.setup({ on_attach = on_attach })
nvim_lsp.pyright.setup({ on_attach = on_attach })
nvim_lsp.clangd.setup({ on_attach = on_attach })
nvim_lsp.tsserver.setup {
cmd = { "/home/barak/.yarn/bin/typescript-language-server", "--stdio" }
}
nvim_lsp.vuels.setup {
cmd = { "/home/barak/.yarn/bin/vls" }
}
nvim_lsp.svelte.setup {
cmd = { "/home/barak/.yarn/bin/svelteserver", "--stdio" }
}
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
require'lspconfig'.sumneko_lua.setup {
require 'lspconfig'.sumneko_lua.setup {
settings = {
Lua = {
runtime = {
@ -41,7 +51,7 @@ require'lspconfig'.sumneko_lua.setup {
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
globals = { 'vim' },
},
workspace = {
-- Make the server aware of Neovim runtime files
@ -56,52 +66,52 @@ require'lspconfig'.sumneko_lua.setup {
}
function org_imports(wait_ms)
local params = vim.lsp.util.make_range_params()
local params = vim.lsp.util.make_range_params()
params.context = {only = {"source.organizeImports"}}
params.context = { only = { "source.organizeImports" } }
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms)
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, "utf-8")
else
vim.lsp.buf.execute_command(r.command)
end
end
end
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, "utf-8")
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 }
}
}
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,
}
virtual_text = false,
signs = true,
update_in_insert = false,
}
)
-- Compe setup
require'compe'.setup {
require 'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
@ -122,21 +132,21 @@ require'compe'.setup {
}
--signature_cfg = {
--hint_enable = true,
--hint_prefix = "% ",
--handler_opts = {
--border = "none"
--},
--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,
},
code_action_prompt = {
enable = false,
sign = false,
virtual_text = false,
},
}
-- require'lspsaga'.init_lsp_saga(saga_cfg)
@ -145,12 +155,12 @@ local t = function(str)
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
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:
@ -173,49 +183,49 @@ _G.s_tab_complete = function()
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})
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,
-- disables text annotations
--with_text = false,
--with_text = true,
-- defines how annotations are shown
-- default: symbol
-- options: 'text', 'text_symbol', 'symbol_text', 'symbol'
mode = 'symbol',
-- defines how annotations are shown
-- default: symbol
-- options: 'text', 'text_symbol', 'symbol_text', 'symbol'
mode = 'symbol',
-- default symbol map
-- can be either 'default' or 'codicons'
preset = 'default',
-- 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',
--},
-- 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('rust-tools').setup({
@ -224,27 +234,27 @@ require('lspkind').init({
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
},
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
},
}
local trouble_telescope = require("trouble.providers.telescope")
@ -283,23 +293,23 @@ require('telescope').setup {
},
}
local builtin = require'telescope.builtin'
local builtin = require 'telescope.builtin'
local dropdown = require'telescope.themes'.get_dropdown({
local dropdown = require 'telescope.themes'.get_dropdown({
--previewer = false,
--prompt_title = "",
--results_height = 16,
--width = 0.6,
--borderchars = {
--{"─", "│", "─", "│", "╭", "╮", "╯", "╰"},
--prompt = {"─", "│", " ", "│", "╭", "╮", "│", "│"},
--results = {"─", "│", "─", "│", "├", "┤", "╯", "╰"},
--preview = {"─", "│", "─", "│", "╭", "╮", "╯", "╰"}
--{"─", "│", "─", "│", "╭", "╮", "╯", "╰"},
--prompt = {"─", "│", " ", "│", "╭", "╮", "│", "│"},
--results = {"─", "│", "─", "│", "├", "┤", "╯", "╰"},
--preview = {"─", "│", "─", "│", "╭", "╮", "╯", "╰"}
--},
--winblend = 10
})
local telescope_ivy = require'telescope.themes'.get_ivy({
local telescope_ivy = require 'telescope.themes'.get_ivy({
})
@ -308,7 +318,7 @@ local telescope_ivy = require'telescope.themes'.get_ivy({
-- Treesitter
--
require'nvim-treesitter.configs'.setup {
require 'nvim-treesitter.configs'.setup {
-- One of "all", "maintained" (parsers with maintainers), or a list of languages
ensure_installed = {
"c",
@ -374,13 +384,13 @@ require'nvim-treesitter.configs'.setup {
}
}
require"nvim-treesitter.highlight".set_custom_captures {
require "nvim-treesitter.highlight".set_custom_captures {
-- Highlight the @foo.bar capture group with the "Identifier" highlight group.
-- ["foo.bar"] = "Identifier",
["generic_type_param"] = "TSCGenericTypeParam",
}
require"neogen".setup {}
require "neogen".setup {}
--
-- Helper functions for my own grepping commands.
@ -391,9 +401,9 @@ live_grep_repo = function(conf)
local opt = telescope_ivy
opt['cwd'] = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
--local opt = {
--cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
--cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
--}
for k,v in pairs(conf) do opt[k] = v end
for k, v in pairs(conf) do opt[k] = v end
builtin.live_grep(opt)
end
@ -402,21 +412,21 @@ git_grep_word = function(conf)
local opt = telescope_ivy
opt['cwd'] = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
--local opt = {
--cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
--cwd = vim.fn.systemlist("git rev-parse --show-toplevel")[1]
--}
for k,v in pairs(conf) do opt[k] = v end
for k, v in pairs(conf) do opt[k] = v end
builtin.grep_string(opt)
end
buffer_telescope = function(conf)
local opt = telescope_ivy
for k,v in pairs(conf) do opt[k] = v end
for k, v in pairs(conf) do opt[k] = v end
builtin.buffers(opt)
end
file_list = function(conf)
local opt = telescope_ivy
for k,v in pairs(conf) do opt[k] = v end
for k, v in pairs(conf) do opt[k] = v end
builtin.git_files(opt)
end
@ -425,15 +435,15 @@ end
--- My own "where" clause generator for Rust
---
function string.insert(str1, str2, pos)
return str1:sub(1,pos)..str2..str1:sub(pos+1)
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;
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)
@ -456,13 +466,14 @@ local function rust_whereify_line(line, var_name)
local whitespace = string.match(line, "^(%s*)")
local generic = "<"..var_name..">"
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)
out = string.insert(out, "\n" .. whitespace .. "where\n" .. whitespace .. " " .. var_name .. ": ,\n" .. whitespace,
brace - 1)
return string.split(out, "\n")
end
@ -471,8 +482,8 @@ 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})
vim.api.nvim_buf_set_lines(0, lineNum - 1, lineNum, false, replacements)
vim.api.nvim_win_set_cursor(0, { lineNum + 2, 4 })
end
function neogen_dwim()
@ -483,17 +494,17 @@ function neogen_dwim()
["function_signature_item"] = "func",
["struct_item"] = "class",
["trait_item"] = "class",
["package_clause"] = "type",
["const_declaration"] = "type",
["package_clause"] = "type",
["const_declaration"] = "type",
["var_declaration"] = "type",
["class_definition"] = "class",
}
local ts_utils = require'nvim-treesitter.ts_utils'
local ts_utils = require 'nvim-treesitter.ts_utils'
local current_node = ts_utils.get_node_at_cursor()
while (current_node) do
local v = table[current_node:type()]
if v then
if v then
require('neogen').generate({ type = v })
break
else

9
.vimrc
View file

@ -171,7 +171,7 @@ Plug 'plytophogy/vim-virtualenv'
Plug 'lunaru/vim-less'
Plug 'hylang/vim-hy', {'for': 'hy'}
"Plug 'mhartington/nvim-typescript'
Plug 'leafgarland/typescript-vim'
"Plug 'leafgarland/typescript-vim'
Plug 'leafOfTree/vim-svelte-plugin'
"Plug 'posva/vim-vue'
Plug 'Shougo/context_filetype.vim'
@ -272,9 +272,10 @@ nnoremap <silent> gr <cmd>lua require('telescope.builtin').lsp_references({ini
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
"nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<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> 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 <cmd>lua vim.lsp.buf.range_code_action()<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.diagnostic.open_float({focusable = false})<CR>