vim: Replace CoC with Treesitter and LSP

This commit is contained in:
Oliver Davies 2021-07-28 23:13:09 +01:00
parent 51d091f066
commit f6c7a0152a
8 changed files with 140 additions and 51 deletions

View file

@ -1 +0,0 @@
{}

View file

@ -1,23 +0,0 @@
{
"dependencies": {
"coc-angular": ">=11.2.9",
"coc-css": ">=1.2.6",
"coc-emmet": ">=1.1.6",
"coc-esbonio": ">=0.4.0",
"coc-go": ">=0.13.3",
"coc-html": ">=1.4.1",
"coc-json": ">=1.3.4",
"coc-markdownlint": ">=1.11.1",
"coc-php-cs-fixer": ">=0.2.1",
"coc-phpactor": ">=1.0.3",
"coc-phpls": ">=2.2.0",
"coc-sh": ">=0.6.0",
"coc-svg": ">=0.0.13",
"coc-tailwindcss": ">=0.7.0",
"coc-tsserver": ">=1.7.0",
"coc-vetur": ">=1.2.4",
"coc-vimlsp": ">=0.12.2",
"coc-yaml": ">=1.3.1",
"coc-yank": ">=1.2.0"
}
}

View file

@ -1 +0,0 @@
{}

View file

@ -1,15 +0,0 @@
{
"diagnostic.messageTarget": "echo",
"diagnostic.virtualText": true,
"intelephense.files.associations": [
"*.inc",
"*.module",
"*.php",
"*.profile",
"*.test",
"*.theme"
],
"intelephense.progress.enable": false,
"intelephense.telemetry.enabled": false
}

View file

@ -57,3 +57,5 @@ autocmd FileType gitcommit setlocal spell
" Display extra whitespace
set list listchars=tab:»·,trail
lua require("opdavies")

View file

@ -0,0 +1,133 @@
-- TreeSitter
local configs = require'nvim-treesitter.configs'
configs.setup {
ensure_installed = "maintained",
highlight = {
enable = true,
}
}
-- LSP
local lspconfig = require'lspconfig'
local completion = require'completion'
local function custom_on_attach(client)
print('Attaching to ' .. client.name)
completion.on_attach(client)
end
local default_config = {
on_attach = custom_on_attach,
}
lspconfig.intelephense.setup{
filetypes = { "install", "inc", "module", "php", "test", "theme" },
on_attach = custom_on_attach,
}
lspconfig.tsserver.setup(default_config)
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
underline = true,
virtual_text = false,
signs = true,
update_in_insert = true,
}
)
local key_mapper = function(mode, key, result)
vim.api.nvim_set_keymap(
mode,
key,
result,
{noremap = true, silent = true}
)
end
key_mapper('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<CR>')
key_mapper('n', '<leader>af', ':lua vim.lsp.buf.code_action()<CR>')
key_mapper('n', '<leader>rn', ':lua vim.lsp.buf.rename()<CR>')
key_mapper('n', 'K', ':lua vim.lsp.buf.hover()<CR>')
key_mapper('n', 'gD', ':lua vim.lsp.buf.declaration()<CR>')
key_mapper('n', 'gW', ':lua vim.lsp.buf.workspace_symbol()<CR>')
key_mapper('n', 'gd', ':lua vim.lsp.buf.definition()<CR>')
key_mapper('n', 'gi', ':lua vim.lsp.buf.implementation()<CR>')
key_mapper('n', 'gr', ':lua vim.lsp.buf.references()<CR>')
key_mapper('n', 'gt', ':lua vim.lsp.buf.type_definition()<CR>')
key_mapper('n', 'gw', ':lua vim.lsp.buf.document_symbol()<CR>')
key_mapper('n', '<leader>dn', ':lua vim.lsp.diagnostic.goto_next()<CR>')
key_mapper('n', '<leader>dp', ':lua vim.lsp.diagnostic.goto_prev()<CR>')
key_mapper('n', '<leader>ds', ':lua vim.lsp.diagnostic.show_line_diagnostics()<CR>')
key_mapper('n', '<C-p>', ':lua require"telescope.builtin".find_files()<CR>')
key_mapper('n', '<leader>fb', ':lua require"telescope.builtin".buffers()<CR>')
key_mapper('n', '<leader>fh', ':lua require"telescope.builtin".help_tags()<CR>')
key_mapper('n', '<leader>fs', ':lua require"telescope.builtin".live_grep()<CR>')
-- Compe
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.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})
--This line is important for auto-import
vim.api.nvim_set_keymap('i', '<cr>', 'compe#confirm("<cr>")', { expr = true })
vim.api.nvim_set_keymap('i', '<c-space>', 'compe#complete()', { expr = true })

View file

@ -5,14 +5,16 @@ Plug 'arcticicestudio/nord-vim'
Plug 'christoomey/vim-sort-motion'
Plug 'christoomey/vim-tmux-navigator'
Plug 'editorconfig/editorconfig-vim'
Plug 'hrsh7th/nvim-compe'
Plug 'jiangmiao/auto-pairs'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'machakann/vim-highlightedyank'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'preservim/nerdcommenter'
Plug 'preservim/nerdtree'
Plug 'sheerun/vim-polyglot'

View file

@ -1,8 +0,0 @@
nmap <Leader>a <Plug>(coc-codeaction)
nmap <Leader>gd <Plug>(coc-definition)
nmap <Leader>gr <Plug>(coc-references)
nmap <Leader>gi <Plug>(coc-implementation)
nmap <Leader>gt <Plug>(coc-type-definition)
nmap <Leader>sr <Plug>(coc-rename)
nmap <Leader>rf <Plug>(coc-refactor)
nnoremap <silent> K :call <SID>show_documentation()<CR>