feat(nvim): switch to coc, start config of lsps

This commit is contained in:
matt1432 2023-09-18 23:21:45 -04:00
parent e9555789be
commit 73ed0ba6de
6 changed files with 81 additions and 123 deletions

31
config/nvim/base.vim Normal file
View file

@ -0,0 +1,31 @@
" make tabs only 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
set smartindent
set number
set relativenumber
set undofile
set undodir=/home/matt/.cache/nvim/
" set dot icon in place of trailing whitespaces
set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨
" use vscode keybinds for snippets completion
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ CheckBackspace() ? "\<TAB>" :
\ coc#refresh()
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
" support scss @
autocmd FileType scss setl iskeyword+=@-@

9
config/nvim/config.lua Normal file
View file

@ -0,0 +1,9 @@
vim.opt.fillchars = {eob = " "}
vim.cmd[[colorscheme dracula]]
-- https://github.com/AstroNvim/AstroNvim/issues/648#issuecomment-1511728897
vim.g.loaded_netrw = 0
vim.g.loaded_netrwPlugin = 0
-- https://github.com/nvim-neo-tree/neo-tree.nvim/issues/983#issuecomment-1637372234

View file

@ -1,41 +1,3 @@
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require('lspconfig')
lspconfig.bashls.setup { capabilities = capabilities }
lspconfig.nixd.setup { capabilities = capabilities }
lspconfig.html.setup { capabilities = capabilities }
lspconfig.cssls.setup { capabilities = capabilities }
lspconfig.lua_ls.setup {
settings = {
capabilities = capabilities,
Lua = {
runtime = {
version = 'LuaJIT',
},
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),
},
telemetry = {
enable = false,
},
},
},
}
require("formatter").setup {
filetype = {
["*"] = {
-- "formatter.filetypes.any" defines default configurations for any
-- filetype
require("formatter.filetypes.any").remove_trailing_whitespace
}
}
}
require'nvim-treesitter.configs'.setup { require'nvim-treesitter.configs'.setup {
highlight = { highlight = {
enable = true, enable = true,
@ -76,6 +38,5 @@ require("neo-tree").setup({
leave_dirs_open = true, leave_dirs_open = true,
} }
}) })
require('nvim-autopairs').setup()
require('todo-comments').setup() require('todo-comments').setup()
require("scrollbar").setup() require("scrollbar").setup()

View file

@ -1,13 +0,0 @@
" make tabs only 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
set smartindent
set number
set relativenumber
set undofile
set undodir=/home/matt/.cache/nvim/
set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨

View file

@ -1,46 +0,0 @@
vim.opt.fillchars = {eob = " "}
vim.cmd[[colorscheme dracula]]
-- Set up nvim-cmp.
local cmp = require'cmp'
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
-- https://github.com/AstroNvim/AstroNvim/issues/648#issuecomment-1511728897
vim.g.loaded_netrw = 0
vim.g.loaded_netrwPlugin = 0
-- https://github.com/nvim-neo-tree/neo-tree.nvim/issues/983#issuecomment-1637372234

View file

@ -1,6 +1,8 @@
# https://breuer.dev/blog/nixos-home-manager-neovim # https://breuer.dev/blog/nixos-home-manager-neovim
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
configDir = "/home/matt/.nix/config";
# installs a vim plugin from git with a given tag / branch # installs a vim plugin from git with a given tag / branch
pluginGit = ref: repo: pkgs.vimUtils.buildVimPluginFrom2Nix { pluginGit = ref: repo: pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "${lib.strings.sanitizeDerivationName repo}"; pname = "${lib.strings.sanitizeDerivationName repo}";
@ -14,6 +16,22 @@ let
# always installs latest version # always installs latest version
plugin = pluginGit "HEAD"; plugin = pluginGit "HEAD";
in { in {
xdg.configFile = {
"nvim/coc-settings.json".source = pkgs.writeText "coc-settings.json" ''
{
"java.jdt.ls.java.home": "${pkgs.temurin-bin-18}",
"colors.enable": true,
"Lua.misc.parameters": [
"--metapath",
"~/.cache/sumneko_lua/meta",
"--logpath",
"~/.cache/sumneko_lua/log"
],
"sumneko-lua.serverDir": "${pkgs.lua-language-server}/share/lua-language-server"
}
'';
};
programs.neovim = { programs.neovim = {
enable = true; enable = true;
package = pkgs.neovim-nightly; package = pkgs.neovim-nightly;
@ -21,51 +39,51 @@ in {
# read in the vim config from filesystem # read in the vim config from filesystem
# this enables syntaxhighlighting when editing those # this enables syntaxhighlighting when editing those
extraConfig = builtins.concatStringsSep "\n" [ extraConfig = builtins.concatStringsSep "\n" [
(lib.strings.fileContents ./.nvim/base.vim) (lib.strings.fileContents "${configDir}/nvim/base.vim")
# (lib.strings.fileContents ./.nvim/plugins.vim) # (lib.strings.fileContents ./.nvim/plugins.vim)
# (lib.strings.fileContents ./.nvim/lsp.vim) # (lib.strings.fileContents ./.nvim/lsp.vim)
'' ''
lua << EOF lua << EOF
${lib.strings.fileContents ./.nvim/config.lua} ${lib.strings.fileContents "${configDir}/nvim/config.lua"}
${lib.strings.fileContents ./.nvim/lsp.lua} ${lib.strings.fileContents "${configDir}/nvim/lsp.lua"}
EOF EOF
'' ''
]; ];
extraPackages = with pkgs; [ extraPackages = with pkgs; [
tree-sitter tree-sitter
nodejs_latest
# https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md bat
nodePackages.bash-language-server
shellcheck
nixd
sumneko-lua-language-server
vscode-langservers-extracted
]; ];
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
vim-which-key vim-which-key
coc-nvim # done
coc-java # done
coc-css # done
coc-sumneko-lua # done
coc-highlight # done
coc-json
coc-pairs
coc-python
coc-sh
coc-snippets
coc-vimlsp
coc-yaml
coc-toml
coc-fzf
(plugin "junegunn/fzf.vim")
(plugin "junegunn/fzf")
nvim-treesitter.withAllGrammars nvim-treesitter.withAllGrammars
nvim-treesitter nvim-treesitter
#telescope-nvim
#telescope-fzf-native-nvim
(plugin "Mofiqul/dracula.nvim") (plugin "Mofiqul/dracula.nvim")
(plugin "neovim/nvim-lspconfig")
(plugin "lukas-reineke/indent-blankline.nvim") (plugin "lukas-reineke/indent-blankline.nvim")
(plugin "lewis6991/gitsigns.nvim") (plugin "lewis6991/gitsigns.nvim")
(plugin "nvim-lualine/lualine.nvim") (plugin "nvim-lualine/lualine.nvim")
# plugins for completion
(plugin "hrsh7th/nvim-cmp")
(plugin "hrsh7th/cmp-nvim-lsp")
(plugin "hrsh7th/cmp-buffer")
(plugin "hrsh7th/cmp-path")
(plugin "hrsh7th/cmp-cmdline")
(plugin "hrsh7th/cmp-vsnip")
(plugin "hrsh7th/vim-vsnip")
# neo-tree and deps # neo-tree and deps
(plugin "nvim-neo-tree/neo-tree.nvim") (plugin "nvim-neo-tree/neo-tree.nvim")
(plugin "nvim-lua/plenary.nvim") (plugin "nvim-lua/plenary.nvim")
@ -75,8 +93,6 @@ in {
# to explore more # to explore more
(plugin "iamcco/markdown-preview.nvim") (plugin "iamcco/markdown-preview.nvim")
(plugin "sindrets/diffview.nvim") (plugin "sindrets/diffview.nvim")
(plugin "windwp/nvim-autopairs")
(plugin "mhartington/formatter.nvim")
(plugin "folke/todo-comments.nvim") (plugin "folke/todo-comments.nvim")
(plugin "petertriho/nvim-scrollbar") (plugin "petertriho/nvim-scrollbar")
]; ];