feat: add neovim rest client

This commit is contained in:
max_richter 2021-09-06 13:29:42 +02:00
parent 86614ce715
commit 92ef625f62
6 changed files with 211 additions and 83 deletions

View File

@ -9,20 +9,19 @@ bind - split-window -v
unbind '"' unbind '"'
unbind % unbind %
# switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
# Enable mouse mode (tmux 2.1 and above) # Enable mouse mode (tmux 2.1 and above)
set -g mouse on set -g mouse on
# Add some plugins # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tpm'
# Add some plugins
set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @yank_action 'copy-pipe-no-clear'
bind -T copy-mode C-c send -X copy-pipe-no-clear "xsel -i --clipboard"
bind -T copy-mode-vi C-c send -X copy-pipe-no-clear "xsel -i --clipboard"
set -g @plugin 'dracula/tmux' set -g @plugin 'dracula/tmux'
set -g @dracula-show-powerline true set -g @dracula-show-powerline true

View File

@ -72,18 +72,17 @@ if [ -d "$HOME/.local/bin" ] ; then
fi fi
#If fdfind is installed force fzf to use it #If fdfind is installed force fzf to use it
if type fdfind > /dev/null ; then if type fdfind &> /dev/null ; then
# Feed the output of fd into fzf
# fdfind --type f | fzf
# Setting fd as the default source for fzf
export FZF_DEFAULT_COMMAND='fdfind --type f' export FZF_DEFAULT_COMMAND='fdfind --type f'
# To apply the command to CTRL-T as well
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
fi fi
#If ripgrep is installed prefer it over fdfind
if type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files'
export FZF_DEFAULT_OPTS='-m --height 50% --border'
fi
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
@ -93,3 +92,5 @@ fi
export PNPM_HOME="$HOME/.local/share/pnpm" export PNPM_HOME="$HOME/.local/share/pnpm"
export PATH="$PNPM_HOME:$PATH" export PATH="$PNPM_HOME:$PATH"
alias luamake=/home/jim/.local/share/lua-language-server/3rd/luamake/luamake

View File

@ -1,43 +1,47 @@
local u = require("utils") local u = require("utils")
local o = vim.o local o = vim.o
local opt = vim.opt
local g = vim.g local g = vim.g
local cmd = vim.cmd; local cmd = vim.cmd
require("install-paq") require("install-paq")
local paq = require("paq"); local paq = require("paq")
paq:setup({verbose=true}) { paq:setup({verbose = true}) {
"savq/paq-nvim", -- Let Paq manage itself "savq/paq-nvim", -- Let Paq manage itself
-- General Helper Function
"nvim-lua/plenary.nvim",
-- Theming Plugins -- Theming Plugins
"kaicataldo/material.vim", "kaicataldo/material.vim",
"ryanoasis/vim-devicons", "ryanoasis/vim-devicons",
"junegunn/fzf",
"xiyaowong/nvim-transparent", "xiyaowong/nvim-transparent",
-- Layout Plugins -- Layout Plugins
"preservim/nerdtree",
"preservim/nerdtree", "preservim/nerdtree",
"jistr/vim-nerdtree-tabs", "jistr/vim-nerdtree-tabs",
-- Code Navigation -- Code Navigation
"junegunn/fzf",
"nvim-lua/popup.nvim", "nvim-lua/popup.nvim",
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim", "nvim-telescope/telescope.nvim",
-- Postman like featuresi
"NTBBloodbath/rest.nvim",
-- Syntax / Autocomplete -- Syntax / Autocomplete
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
"nvim-lua/lsp-status.nvim", "nvim-lua/lsp-status.nvim",
"hrsh7th/nvim-compe", "hrsh7th/nvim-cmp", -- Autocompletion plugin
"hrsh7th/cmp-nvim-lsp", -- LSP source for nvim-cmp
"saadparwaiz1/cmp_luasnip", -- Snippets source for nvim-cmp
"L3MON4D3/LuaSnip", -- Snippets plugin
{"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"}, {"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"},
-- Formatting -- Formatting
"mhartington/formatter.nvim", "mhartington/formatter.nvim",
-- Git Interface -- Git Interface
"akinsho/nvim-toggleterm.lua" "akinsho/nvim-toggleterm.lua",
-- Database Interface
"tpope/vim-dadbod",
"kristijanhusak/vim-dadbod-ui"
} }
if u.has_plugin("material") then if u.has_plugin("cmp") then
print("Load config")
-- Global options -- Global options
o.number = true o.number = true
o.tabstop = 2 o.tabstop = 2
@ -54,11 +58,15 @@ if u.has_plugin("material") then
g.NERDTreeAutoDeleteBuffer = true g.NERDTreeAutoDeleteBuffer = true
g.NERDTreeMinimalUI = true g.NERDTreeMinimalUI = true
g.NERDTreeDirArrows = true g.NERDTreeDirArrows = true
g.NERDTreeCustomOpenArgs={file = {where = 't'}} -- g.NERDTreeCustomOpenArgs = {file = {where = "t"}}
g.hidden = true g.hidden = true
g.material_style = "deep ocean" g.material_terminal_italics = 1
require("transparent").setup({enable = true}) g.material_theme_style = "darker"
cmd("colorscheme material")
-- Remove background color -- Remove background color
require("transparent").setup({enable = true})
cmd("highlight Normal guibg=none") cmd("highlight Normal guibg=none")
cmd("highlight NonText guibg=none") cmd("highlight NonText guibg=none")
@ -67,32 +75,58 @@ if u.has_plugin("material") then
require "keymappings" require "keymappings"
-- Treesitter config -- Treesitter config
require "nvim-treesitter.configs".setup {ensure_installed = {"bash", "svelte", "css", "svelte", "typescript", "javascript", "go", "lua", "yaml"}, highlight = {enable = true}} local parser_configs = require("nvim-treesitter.parsers").get_parser_configs()
parser_configs.http = {
install_info = {
url = "https://github.com/NTBBloodbath/tree-sitter-http",
files = {"src/parser.c"},
branch = "main"
}
}
require "nvim-treesitter.configs".setup {
ensure_installed = {"bash", "http", "svelte", "css", "svelte", "typescript", "javascript", "go", "lua", "yaml"},
highlight = {enable = true}
}
-- Toggleterm / Lazygit setup -- Toggleterm / Lazygit setup
require "lazy-git" require "lazy-git"
-- Autocommands -- Autocommands
u.create_augroup( u.create_augroup(
{ {
{"VimEnter", "*", "if (@% == '') | NERDTree | endif"}, {"VimEnter", "*", "if (@% == '') | NERDTree | endif"},
{"BufEnter", "*", 'if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif'} {"BufEnter", "*", 'if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif'},
{"BufWinEnter", "*", "NERDTreeMirrorOpen"}
--{"BufEnter", "*", "if &modifiable | NERDTreeFind | wincmd p | endif"}
}, },
"Nerdtree" "Nerdtree"
) )
-- Setup rest.vim
require("rest-nvim").setup(
{
-- Open request results in a horizontal split
result_split_horizontal = false,
-- Skip SSL verification, useful for unknown certificates
skip_ssl_verification = false,
-- Highlight request on run
highlight = {
enabled = true,
timeout = 150
},
-- Jump to request line on run
jump_to_request = false
}
)
-- Autocompletion Setup -- Autocompletion Setup
o.completeopt = "menuone,noselect"
require "autocomplete" require "autocomplete"
-- LSP Config -- LSP Config
require "lsp-utils" require "lsp-utils"
opt.completeopt = {"menuone", "noinsert", "noselect"}
opt.shortmess:append({c = true})
-- Autoformat -- Autoformat
require "autoformatter" require "autoformatter"
else else
paq.install(); paq.install()
end end

View File

@ -1,31 +1,51 @@
require "compe".setup {
enabled = true, -- luasnip setup
autocomplete = true, local luasnip = require 'luasnip'
debug = false,
min_length = 1, local cmp = require 'cmp'
preselect = "enable",
throttle_time = 80, cmp.setup {
source_timeout = 200, snippet = {
resolve_timeout = 800, expand = function(args)
incomplete_delay = 400, require('luasnip').lsp_expand(args.body)
max_abbr_width = 100, end,
max_kind_width = 100, },
max_menu_width = 100, mapping = {
documentation = { ['<C-p>'] = cmp.mapping.select_prev_item(),
border = "none", ['<C-n>'] = cmp.mapping.select_next_item(),
winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", ['<C-d>'] = cmp.mapping.scroll_docs(-4),
max_width = 120, ['<C-f>'] = cmp.mapping.scroll_docs(4),
min_width = 60, ['<C-Space>'] = cmp.mapping.complete(),
max_height = math.floor(vim.o.lines * 0.3), ['<C-e>'] = cmp.mapping.close(),
min_height = 1 ['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
elseif luasnip.expand_or_jumpable() then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n')
elseif luasnip.jumpable(-1) then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '')
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
}, },
source = {
path = true,
buffer = true,
calc = true,
nvim_lsp = true,
nvim_lua = true,
spell = true,
treesitter = true
}
} }
-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

View File

@ -9,7 +9,8 @@ map("n", " ", "<Nop>", remap)
g.mapleader = " " g.mapleader = " "
map("n", "<C-p>", ":Telescope find_files<CR>", options) map("n", "<C-p>", ":Telescope find_files<CR>", options)
map("n", "<C-f>", ":Telescope grep_string<CR>", options);
map("n", "<Leader><C-f>", ":Telescope live_grep<CR>", options);
-- Navigate Buffers -- Navigate Buffers
map("n", "<C-h>", "<C-w>h", options) map("n", "<C-h>", "<C-w>h", options)
map("n", "<C-j>", "<C-w>j", options) map("n", "<C-j>", "<C-w>j", options)
@ -22,6 +23,9 @@ map("n", "<Right>", ":echo 'No Right for you'<CR><dw>", options)
map("n", "<Up>", ":echo 'No Up for you'<CR><dw>", options) map("n", "<Up>", ":echo 'No Up for you'<CR><dw>", options)
map("n", "<Down>", ":echo 'No Down for you'<CR><dw>", options) map("n", "<Down>", ":echo 'No Down for you'<CR><dw>", options)
-- Run Requests
map("n", "<Leader>r", "<cmd>lua require('rest-nvim').run()<CR>", options)
-- Close on q -- Close on q
map("n", "<Leader>q", "<Esc>:q<CR>", options) map("n", "<Leader>q", "<Esc>:q<CR>", options)

View File

@ -47,19 +47,89 @@ local function on_attach(client)
) )
end end
end end
-- Use a loop to conveniently both setup defined servers
-- and map buffer local keybindings when the language server attaches -- Lua Language Server
local servers = { if vim.fn.has("mac") == 1 then
"tsserver", system_name = "macOS"
"svelte" elseif vim.fn.has("unix") == 1 then
system_name = "Linux"
elseif vim.fn.has("win32") == 1 then
system_name = "Windows"
else
print("Unsupported system for sumneko")
end
local sumneko_root_path = "/home/jim/.local/share/lua-language-server"
local sumneko_binary = sumneko_root_path .. "/bin/" .. system_name .. "/lua-language-server"
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
nvim_lsp.sumneko_lua.setup {
on_attach = on_attach,
capabilities = lsp_status.capabilities,
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
-- Setup your lua path
path = runtime_path
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {"vim"}
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true)
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false
}
}
}
} }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup { -- Go Language Server
nvim_lsp.gopls.setup {
on_attach = on_attach, on_attach = on_attach,
capabilities = lsp_status.capabilities capabilities = lsp_status.capabilities
}
-- Svelte Language Server
nvim_lsp.svelte.setup {
on_attach = on_attach,
capabilities = lsp_status.capabilities
}
-- Typescript Language Server
local function organize_imports()
local params = {
command = "_typescript.organizeImports",
arguments = {vim.api.nvim_buf_get_name(0)},
title = ""
} }
vim.lsp.buf.execute_command(params)
end end
nvim_lsp.tsserver.setup {
on_attach = on_attach,
capabilities = lsp_status.capabilities,
commands = {
OrganizeImports = {
organize_imports,
description = "Organize Imports"
}
}
}
-- Setup diagnostics formaters and linters for non LSP provided files -- Setup diagnostics formaters and linters for non LSP provided files
nvim_lsp.diagnosticls.setup { nvim_lsp.diagnosticls.setup {
on_attach = on_attach, on_attach = on_attach,