nvim-lsp-installer, nvim-cmp, and other plugins

Other plugins:
- gitsigns
- lightbulb
- indent-blankline
- treesitter
- light theme

Removed lsp install scripts b/c of nvim-lsp-installer
This commit is contained in:
Just Midi 2022-01-15 20:27:27 +00:00
parent f6d4e367d2
commit f81c4bde28
19 changed files with 429 additions and 259 deletions

View file

@ -20,10 +20,14 @@ v = vim.v -- variables
env = vim.env -- environment variables
local modules = {
'ui',
'general',
'keymap',
'ui',
'native-lsp'
'plugins',
'native-lsp',
'indent-blankline',
'gitsigns-nvim',
'lightbulb'
}
local async

65
lua/gitsigns-nvim.lua Normal file
View file

@ -0,0 +1,65 @@
require('gitsigns').setup {
signs = {
add = {hl = 'GitSignsAdd' , text = '', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'},
change = {hl = 'GitSignsChange', text = '', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
topdelete = {hl = 'GitSignsDelete', text = '', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
},
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
keymaps = {
-- Default keymap options
noremap = true,
['n ]c'] = { expr = true, "&diff ? ']c' : '<cmd>Gitsigns next_hunk<CR>'"},
['n [c'] = { expr = true, "&diff ? '[c' : '<cmd>Gitsigns prev_hunk<CR>'"},
['n <leader>hs'] = '<cmd>Gitsigns stage_hunk<CR>',
['v <leader>hs'] = ':Gitsigns stage_hunk<CR>',
['n <leader>hu'] = '<cmd>Gitsigns undo_stage_hunk<CR>',
['n <leader>hr'] = '<cmd>Gitsigns reset_hunk<CR>',
['v <leader>hr'] = ':Gitsigns reset_hunk<CR>',
['n <leader>hR'] = '<cmd>Gitsigns reset_buffer<CR>',
['n <leader>hp'] = '<cmd>Gitsigns preview_hunk<CR>',
['n <leader>hb'] = '<cmd>lua require"gitsigns".blame_line{full=true}<CR>',
['n <leader>hS'] = '<cmd>Gitsigns stage_buffer<CR>',
['n <leader>hU'] = '<cmd>Gitsigns reset_buffer_index<CR>',
-- Text objects
['o ih'] = ':<C-U>Gitsigns select_hunk<CR>',
['x ih'] = ':<C-U>Gitsigns select_hunk<CR>'
},
watch_gitdir = {
interval = 1000,
follow_files = true
},
attach_to_untracked = true,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
ignore_whitespace = false,
},
current_line_blame_formatter_opts = {
relative_time = false
},
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000,
preview_config = {
-- Options passed to nvim_open_win
border = 'single',
style = 'minimal',
relative = 'cursor',
row = 0,
col = 1
},
yadm = {
enable = false
},
}

5
lua/indent-blankline.lua Normal file
View file

@ -0,0 +1,5 @@
require("indent_blankline").setup {
-- for example, context is off by default, use this to turn it on
show_current_context = true,
show_current_context_start = true,
}

1
lua/lightbulb.lua Normal file
View file

@ -0,0 +1 @@
require('nvim-lightbulb').update_lightbulb()

View file

@ -19,163 +19,23 @@
-- v = vim.v -- variables
-- env = vim.env -- environment variables
-- dependent on https://github.com/neovim/nvim-lspconfig
local lspconfig = require 'lspconfig'
require("native-lsp/nvim-lsp-installer")
function lsp_init()
-- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md
local lsp_filetype = {
['ada'] = {'als'},
['aspnetcorerazor'] = {'tailwindcss'},
['astro'] = {'tailwindcss'},
['astro-markdown'] = {'tailwindcss'},
['beancount'] = {'beancount'},
['bib'] = {'texlab'},
['bicep'] = {'bicep'},
['blade'] = {'tailwindcss'},
['c'] = {'ccls','clangd','sourcekit'},
['clojure'] = {'clojure_lsp'},
['cmake'] = {'cmake'},
-- = {'config'},
['cpp'] = {'ccls','clangd','sourcekit'},
['crystal'] = {'crystalline','scry'},
['css'] = {'cssls','stylelint_lsp','tailwindcss'},
['d'] = {'serve_d'},
['dart'] = {'dartls'},
['dhall'] = {'dhall_lsp_server'},
['django-html'] = {'tailwindcss'},
['Dockerfile'] = {'dockerls'},
['dockerfile'] = {'dockerls'},
['dot'] = {'dotls'},
-- = {'diagnostics'},
['edge'] = {'tailwindcss'},
['edn'] = {'clojure_lsp'},
['eelixir'] = {'elixirls','tailwindcss'},
-- = {'efm'},
['elixir'] = {'elixirls'},
['elm'] = {'elmls'},
['ejs'] = {'tailwindcss'},
['erb'] = {'tailwindcss'},
['erlang'] = {'erlangls'},
['eruby'] = {'tailwindcss'},
['fortran'] = {'fortls'},
['fsharp'] = {'fsautocomplete'},
['gd'] = {'gdscript'},
['gdscript'] = {'gdscript'},
['gdscript3'] = {'gdscript'},
['genie'] = {'vala_ls'},
['go'] = {'gopls'},
['gohtml'] = {'tailwindcss'},
['gomod'] = {'gopls'},
['graphql'] = {'graphql'},
['groovy'] = {'groovyls'},
['haml'] = {'tailwindcss'},
['handlebars'] = {'ember','tailwindcss'},
['haskell'] = {'ghcide','hie','hls'},
['haxe'] = {'haxe_language_server'},
['hbs'] = {'tailwindcss'},
-- = {'health'},
['help'] = {},
['html'] = {'angular','html','tailwindcss'},
['html-eex'] = {'tailwindcss'},
['jade'] = {'tailwindcss'},
['java'] = {'java_language_server','jdtls'},
['javascript'] = {'denols','ember','flow','rome','stylelint_lsp','tsserver','tailwindcss'},
['javascriptreact'] = {'denols','flow','rome','stylelint_lsp','tsserver','tailwindcss'},
['javascript.jsx'] = {'denols','flow','tsserver'},
['json'] = {'jsonls','rome'},
['julia'] = {'julials'},
['kotlin'] = {'kotlin_language_server'},
['leaf'] = {'tailwindcss'},
['lean'] = {'leanls'},
['lean3'] = {'lean3ls'},
['less'] = {'cssls','stylelint_lsp','tailwindcss'},
['lhaskell'] = {'ghcide','hls'},
-- = {'lspinfo'},
['liquid'] = {'tailwindcss'},
['lua'] = {'sumneko_lua'},
['markdown'] = {'zeta_note','tailwindcss'},
['mdx'] = {'tailwindcss'},
['mint'] = {'mint'},
['mustache'] = {'tailwindcss'},
['mysql'] = {'sqlls','sqls'},
['nim'] = {'nimls'},
['nix'] = {'rnix'},
['njk'] = {'tailwindcss'},
['nunjucks'] = {'tailwindcss'},
['objc'] = {'ccls','clangd'},
['objcpp'] = {'ccls','clangd'},
['objective-c'] = {'sourcekit'},
['objective-cpp'] = {'sourcekit'},
['ocaml'] = {'ocamlls','ocamllsp'},
['ocaml.menhir'] = {'ocamllsp'},
['ocaml.interface'] = {'ocamllsp'},
['ocaml.ocamllex'] = {'ocamllsp'},
['perl'] = {'perlls','perlpls'},
['php'] = {'intelephense','phpactor','tailwindcss'},
['prisma'] = {'prismals'},
['ps1'] = {'powershell_es'},
['puppet'] = {'puppet'},
['purescript'] = {'purescriptls'},
['python'] = {'jedi_language_server','pylsp','pyright'},
['ql'] = {'codeqlls'},
['r'] = {'r_language_server'},
['racket'] = {'racket_langserver'},
['razor'] = {'tailwindcss'},
['reason'] = {'ocamlls','ocamllsp','tailwindcss'},
['rescript'] = {'rescript','tailwindcss'},
['rmd'] = {'r_language_server'},
['ruby'] = {'solargraph','sorbet'},
['rust'] = {'rls','rust_analyzer'},
['sass'] = {'tailwindcss'},
['scala'] = {'metals'},
['scheme'] = {'racket_langserver'},
['scss'] = {'cssls','stylelint_lsp','tailwindcss'},
['sh'] = {'bashls'},
['slim'] = {'tailwindcss'},
['stylus'] = {'tailwindcss'},
['sql'] = {'sqlls','sqls'},
['sugarss'] = {'stylelint_lsp','tailwindcss'},
['svelte'] = {'svelte','tailwindcss'},
['swift'] = {'source'},
['systemverilog'] = {'svls'},
['tex'] = {'texlab'},
['terraform'] = {'tflint','teraformls'},
['twig'] = {'tailwindcss'},
['typescript'] = {'angular', 'denols','ember','rome','stylelint_lsp','tsserver','tailwindcss'},
['typescriptreact'] = {'angular', 'denols','rome','stylelint_lsp','tsserver','tailwindcss'},
['typescript.tsx'] = {'angular', 'denols','rome','tsserver'},
-- = {'util'},
['vala'] = {'vala_ls'},
['verilog'] = {'svls'},
['vim'] = {'vimls'},
['vlang'] = {'vls'},
['vue'] = {'stylelint_lsp','vuels','tailwindcss'},
['wxss'] = {'stylelint_lsp'},
['yaml'] = {'ansiblels','yamlls'},
['zig'] = {'zls'},
['zir'] = {'zls'}
local lspconfig = require('lspconfig')
local on_attach = function(_, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
require('completion').on_attach()
end
local servers = {'zls'}
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
on_attach = on_attach,
}
for _,server in pairs(lsp_filetype[bo.filetype]) do
lspconfig[server].setup {}
end
end
function lsp_format()
local function format_file()
if bo.filetype == x then
vim.lsp.formatting_sync(nil, 100)
end
end
opt.completeopt = "menu,menuone,noselect"
g.completion_enable_auto_popup = 1
for _,file in pairs({'javascript', 'python'}) do
format_file(file)
end
end
cmd('autocmd BufRead * lua lsp_init()')
cmd('autocmd BufWritePre * lua lsp_format()')
require 'nvim-compe.lua'
require("native-lsp/nvim-cmp")

154
lua/native-lsp/nvim-cmp.lua Normal file
View file

@ -0,0 +1,154 @@
local cmp = require("cmp")
local luasnip = require("luasnip")
if not luasnip then
return
end
local lsp_symbols = {
Text = "  (Text) ",
Method = "  (Method)",
Function = "  (Function)",
Constructor = "  (Constructor)",
Field = " ﴲ (Field)",
Variable = "  (Variable)",
Class = "  (Class)",
Interface = "  (Interface)",
Module = "  (Module)",
Property = " 襁 (Property)",
Unit = "  (Unit)",
Value = "  (Value)",
Enum = " 練 (Enum)",
Keyword = "  (Keyword)",
Snippet = "  (Snippet)",
Color = "  (Color)",
File = "  (File)",
Reference = "  (Reference)",
Folder = "  (Folder)",
EnumMember = "  (EnumMember)",
Constant = "  (Constant)",
Struct = "  (Struct)",
Event = "  (Event)",
Operator = "  (Operator)",
TypeParameter = "  (TypeParameter)"
}
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = {
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<C-e>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
['<C-CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
},
formatting = {
format = function(entry, item)
item.kind = lsp_symbols[item.kind] .. " " .. item.kind
-- set a name for each source
item.menu = ({
spell = "[Spell]",
buffer = "[Buffer]",
calc = "[Calc]",
emoji = "[Emoji]",
nvim_lsp = "[LSP]",
path = "[Path]",
look = "[Look]",
treesitter = "[treesitter]",
luasnip = "[LuaSnip]",
nvim_lua = "[Lua]",
latex_symbols = "[Latex]",
cmp_tabnine = "[Tab9]"
})[entry.source.name]
return item
end
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'cmp_tabnine' },
{ name = 'luasnip' },
{ name = 'path' },
{ name = 'latex_symbols'},
{ name = 'treesitter' },
{ name = 'buffer' },
{
name = 'look',
keyword_length = 2,
option = {
convert_case = true,
loud = true
}
},
{ name = 'emoji' },
{ name = 'calc' }
},
cmp.setup.cmdline('-', {
sources = {
{ name = 'path' },
{ name = 'cmdline' },
{ name = 'nvim_lua' },
{ name = 'buffer' }
}
}),
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
}),
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
}),
})
local tabnine = require('cmp_tabnine.config')
tabnine:setup({
max_lines = 1000;
max_num_results = 20;
sort = true;
run_on_every_keystroke = true;
snippet_placeholder = '..';
ignored_file_types = { -- default is not to ignore
-- uncomment to ignore in lua:
-- lua = true
};
})

View file

@ -0,0 +1,75 @@
local lsp_installer = require("nvim-lsp-installer")
local lang_servers = {
"bashls",
"ccls",
"clangd",
"cmake",
"cssls",
"cssmodules_ls",
"diagnosticls",
"dockerls",
"dotls",
"efm",
--"eslint",
"emmet_ls",
--"grammarly",
"graphql",
"html",
--"hls",
"jsonls",
--"jdtls",
--"quick_lint_js",
"tsserver",
--"ltex",
"texlab",
"sumneko_lua",
"remark_ls",
--"zk",
"puppet",
--"jedi_language_server",
"pyright",
--"pylsp",
"sqlls",
--"sqls",
--"svelte",
"taplo",
--"tailwindcss",
--"tflint", -- going to use tsserver first
"lemminx",
"yamlls",
"zls",
}
for _, name in pairs(lang_servers) do
local server_is_found, server = lsp_installer.get_server(name)
if server_is_found then
if not server:is_installed() then
print("Installing " .. name)
server:install()
end
end
end
lsp_installer.on_server_ready(function(server)
local opts = {}
opts.on_attach = on_attach
opts.capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
server:setup(opts)
vim.cmd [[ do User LspAttachBuffers ]]
end)
lsp_installer.settings({
ui = {
icons = {
server_installed = "",
server_pending = "",
server_uninstalled = ""
}
}
})

View file

@ -1,8 +1,58 @@
require "paq" {
"savq/paq-nvim"; -- Let Paq manage itself
-- let paq manage itself
"savq/paq-nvim";
-- lsp
"neovim/nvim-lspconfig";
"hrsh7th/nvim-compe";
{"williamboman/nvim-lsp-installer", branch="dont-prepare-root-dir"};
-- cmp
"hrsh7th/nvim-cmp";
"hrsh7th/cmp-nvim-lsp";
"hrsh7th/cmp-buffer";
"hrsh7th/cmp-path";
"hrsh7th/cmp-cmdline";
"hrsh7th/cmp-nvim-lua";
"hrsh7th/cmp-calc";
"hrsh7th/cmp-emoji";
"hrsh7th/cmp-latex-symbols";
"octaltree/cmp-look";
{"tzachar/cmp-tabnine", run="./install.sh"};
-- lua snips
"L3MON4D3/LuaSnip";
"saadparwaiz1/cmp_luasnip";
-- diagnostics
"folke/trouble.nvim";
"kyazdani42/nvim-web-devicons";
-- pandoc
"vim-pandoc/vim-pandoc";
-- zig ls
"zigtools/zls";
-- theme
"rakr/vim-one";
"mattn/emmet-vim";
--{"lervag/vimtex", opt=true};
-- tree sitter
"nvim-treesitter/nvim-treesitter";
"nvim-treesitter/nvim-treesitter-textobjects";
"ray-x/cmp-treesitter";
"lukas-reineke/indent-blankline.nvim";
"kosayoda/nvim-lightbulb";
"turbio/bracey.vim";
-- git symbols
"lewis6991/gitsigns.nvim";
"nvim-lua/plenary.nvim";
}
cmd 'PaqSync'

26
lua/tree-sitter.lua Normal file
View file

@ -0,0 +1,26 @@
cmd [[
TSInstall bash
TSInstall bibtex
TSInstall c
TSInstall cmake
TSInstall cpp
TSInstall css
TSInstall dockerfile
TSInstall dot
TSInstall graphql
TSInstall html
TSInstall http
TSInstall javascript
TSInstall latex
TSInstall llvm
TSInstall lua
TSInstall make
TSInstall python
TSInstall regex
TSInstall verilog
TSInstall vim
TSInstall yaml
TSInstall zig
TSUpdate
]]

View file

@ -30,8 +30,8 @@ o.showmatch = true -- matching bracket
-- Completion Menu
o.wildmenu = true
o.wildmode = 'list:longest,full'
--o.wildmenu = true
--o.wildmode = 'list:longest,full'
-- Character Representation
@ -104,6 +104,9 @@ autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929
autocmd BufEnter * match OverLength /\%71v.*/
]]) --rewrite in lua
-- Theme
o.background = "light"
cmd('colorscheme one')
--WIP
-- Filetype: txt, md, tex

View file

@ -31,27 +31,30 @@ local function file_state()
return ""
end
local function diagnostics()
local buffer_number = vim.fn.bufnr('%')
local severity_levels = {
-- level,prefix
errors = {'Error', 'E:'},
warnings = {'Warning', 'W:'},
info = {'Information', 'I:'},
hints = {'Hint', 'H:'}
}
local out = ''
for _,v in pairs(severity_levels) do
local d = vim.lsp.diagnostic.get_count(
buffer_number,
v[1] -- level
)
if d > 0 then
out = out .. v[2] .. d .. ' '
end
end
return out
end
--local function diagnostics()
-- --local buffer_number = vim.fn.bufnr('%')
-- local severity_levels = {
-- -- level,prefix
-- errors = {'Error', 'E:'},
-- warnings = {'Warning', 'W:'},
-- info = {'Information', 'I:'},
-- hints = {'Hint', 'H:'}
-- }
-- local out = ''
-- for _,v in pairs(severity_levels) do
-- local d = vim.diagnostic.get(
-- 0,
-- )
-- --local d = vim.lsp.diagnostic.get_count(
-- -- buffer_number,
-- -- v[1] -- level
-- --)
-- if d > 0 then
-- out = out .. v[2] .. d .. ' '
-- end
-- end
-- return out
--end
local function highlight(group, color)
cmd('highlight ' .. group .. ' cterm='..color .. ' gui='..color)
@ -100,7 +103,7 @@ function status_bar()
return table.concat(sections({
-- Stage Left
{'%f', file_state()},
{diagnostics()},
--{diagnostics()},
'%=',
-- Stage Right
{

View file

@ -1,8 +0,0 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'npm'
if response == 'y' then
npm -i -g bash-language-server
fi

View file

@ -1,14 +0,0 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'CMake'
query_dep 'C++17'
query_dep '
if response == 'y' then
cd builds
git clone --depth=1 --recursive https://github.com/MaskRay/ccls
cd ccls
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/path/to/clang+llvm-xxx
cmake --build Release
fi

View file

@ -1,4 +0,0 @@
#!/bin/sh
printf 'Install from clang-tools or similar '
printf 'with your OS or from releases on LLVM site\n'

View file

@ -1,8 +0,0 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'pip'
if response == 'y' then
pip install python-lsp-server
fi

View file

@ -1,8 +0,0 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'npm'
if response == 'y' then
npm -i -g pyright
fi

View file

@ -1,17 +0,0 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep 'ninja'
query_dep 'C++17'
if $response == 'y' then
mkdir -p builds
cd builds
git clone https://github.com/sumneko/lua-language-server
cd lua-language-server
git submodule update --init --recursive
cd 3rd/luamake
compile/install.sh
cd ../..
./3rd/luamake/luamake rebuild
fi

View file

@ -1,10 +0,0 @@
#!/bin/sh
source scripts/query_dependencies.sh
query_dep "xz or xz-utils"
if response == 'y' then
mkdir -p builds/zls
cd builds/zls
curl -L https://github.com/zigtools/zls/releases/download/0.1.0/x86_64-linux.tar.xz | tar -xJ --strip-components=1 -C .
fi

View file

@ -1,7 +0,0 @@
function query_dep(){
printf 'Did you install '
printf $1
printf '?\n (y/N)'
response='n'
read response
}