aboutsummaryrefslogtreecommitdiff
path: root/nvim
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2021-08-21 16:05:16 +0300
committereug-vs <eugene@eug-vs.xyz>2021-08-21 16:05:16 +0300
commit7c1626abd12fddbb2a98ab52190615deef787bab (patch)
treedaeb45ba7b1956c086be16d53256a5df7d73dfbe /nvim
parent1a9194b6bc7708f631353ea733e14ccd189b4b57 (diff)
downloaddotfiles-7c1626abd12fddbb2a98ab52190615deef787bab.tar.gz
feat(nvim)!: switch to built-in LSP
Diffstat (limited to 'nvim')
-rw-r--r--nvim/.config/nvim/init.vim3
-rw-r--r--nvim/.config/nvim/lua/completion.lua61
-rw-r--r--nvim/.config/nvim/lua/lsp-config.lua68
-rw-r--r--nvim/.config/nvim/vim-plug/plugins.vim4
4 files changed, 134 insertions, 2 deletions
diff --git a/nvim/.config/nvim/init.vim b/nvim/.config/nvim/init.vim
index 55fb6d2..8ae7f26 100644
--- a/nvim/.config/nvim/init.vim
+++ b/nvim/.config/nvim/init.vim
@@ -63,6 +63,7 @@ nnoremap <leader>sv :source $MYVIMRC<CR>
source ~/.config/nvim/startify.vim
source ~/.config/nvim/defx.vim
source ~/.config/nvim/vimwiki.vim
-source ~/.config/nvim/coc.vim
source ~/.config/nvim/fzf.vim
+lua require('lsp-config')
+lua require('completion')
diff --git a/nvim/.config/nvim/lua/completion.lua b/nvim/.config/nvim/lua/completion.lua
new file mode 100644
index 0000000..3bca660
--- /dev/null
+++ b/nvim/.config/nvim/lua/completion.lua
@@ -0,0 +1,61 @@
+-- Compe setup
+require'compe'.setup {
+ enabled = true;
+ autocomplete = true;
+ debug = false;
+ min_length = 1;
+ preselect = 'enable';
+ 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;
+ };
+}
+
+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.opt.completeopt = { "menuone", "noselect" }
+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', '<c-space>', 'compe#complete()', { expr = true })
+vim.api.nvim_set_keymap('i', '<cr>', 'compe#confirm({ "keys": "\\<Plug>delimitMateCR", "mode": "" })', { expr = true })
diff --git a/nvim/.config/nvim/lua/lsp-config.lua b/nvim/.config/nvim/lua/lsp-config.lua
new file mode 100644
index 0000000..ac486dc
--- /dev/null
+++ b/nvim/.config/nvim/lua/lsp-config.lua
@@ -0,0 +1,68 @@
+local nvim_lsp = require('lspconfig')
+
+-- Use an on_attach function to only map the following keys
+-- after the language server attaches to the current buffer
+local on_attach = function(client, bufnr)
+ local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
+ local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
+
+ --Enable completion triggered by <c-x><c-o>
+ buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
+
+ -- Mappings.
+ local opts = { noremap=true, silent=true }
+
+ -- See `:help vim.lsp.*` for documentation on any of the below functions
+ buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
+ buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
+ buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
+ buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
+ buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
+ buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
+ buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
+ buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
+end
+
+local flags = {
+ debounce_text_changes = 150,
+}
+
+-- Typescript
+nvim_lsp.tsserver.setup {
+ on_attach = on_attach,
+ flags = flags,
+}
+
+-- Lua
+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,
+ flags = flags,
+ cmd = { '/usr/bin/lua-language-server' }, -- Install from yay
+ 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,
+ },
+ },
+ },
+}
+
diff --git a/nvim/.config/nvim/vim-plug/plugins.vim b/nvim/.config/nvim/vim-plug/plugins.vim
index c892b6a..e0c7b93 100644
--- a/nvim/.config/nvim/vim-plug/plugins.vim
+++ b/nvim/.config/nvim/vim-plug/plugins.vim
@@ -17,7 +17,6 @@ call plug#begin('~/.config/nvim/autoload/plugged')
" Editorconfig
Plug 'editorconfig/editorconfig-vim'
" Languages
- Plug 'neoclide/coc.nvim', {'branch': 'release'} "LSP
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim' "typescript syntax
Plug 'peitalin/vim-jsx-typescript' "react jsx typescript syntax
@@ -26,4 +25,7 @@ call plug#begin('~/.config/nvim/autoload/plugged')
Plug 'airblade/vim-gitgutter'
" Matching brackets
Plug 'Raimondi/delimitMate'
+ " Built-in LSP
+ Plug 'neovim/nvim-lspconfig'
+ Plug 'hrsh7th/nvim-compe'
call plug#end()