From 7f4b5a9d2ab2cbcf06320893ae6e0afd7c84de6e Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Fri, 20 Jan 2023 11:31:39 +0800 Subject: [PATCH] Upgrade versions, add pyenv --- .config/nvim/init.vim | 132 +++++++++++++++++++++---------------- .config/nvim/lua/lsp.lua | 86 ++++++++++++++++++++++++ .docker/alpine | 2 +- .docker/alpine-desktop | 2 +- .docker/alpine-desktopbase | 2 +- .docker/alpine-go | 2 +- .docker/alpine-node | 2 +- .docker/alpine-pwn | 2 +- .docker/alpine-rust | 2 +- .docker/alpine-slim | 2 +- .docker/fedora | 2 +- .docker/fedora-desktop | 2 +- .docker/fedora-desktopbase | 2 +- .docker/fedora-go | 2 +- .docker/fedora-pwn | 2 +- .docker/fedora-rust | 2 +- .docker/ubuntu | 2 +- .docker/ubuntu-desktop | 2 +- .docker/ubuntu-desktopbase | 2 +- .docker/ubuntu-pwn | 2 +- .gitignore | 1 + .zshrc | 17 +++-- 22 files changed, 192 insertions(+), 80 deletions(-) create mode 100644 .config/nvim/lua/lsp.lua diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 8eea52a..25634f8 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -17,82 +17,94 @@ call plug#begin() " language server protocol -Plug 'prabirshrestha/vim-lsp' -Plug 'mattn/vim-lsp-settings' -Plug 'prabirshrestha/asyncomplete.vim' -Plug 'prabirshrestha/asyncomplete-lsp.vim' -"Plug 'neovim/nvim-lspconfig' +"Plug 'prabirshrestha/vim-lsp' +"Plug 'mattn/vim-lsp-settings' +"Plug 'prabirshrestha/asyncomplete.vim' +"Plug 'prabirshrestha/asyncomplete-lsp.vim' +Plug 'williamboman/mason.nvim' +Plug 'williamboman/mason-lspconfig.nvim' +Plug 'neovim/nvim-lspconfig' +Plug 'hrsh7th/cmp-nvim-lsp' +Plug 'hrsh7th/cmp-buffer' +Plug 'hrsh7th/cmp-path' +Plug 'hrsh7th/cmp-cmdline' +Plug 'hrsh7th/nvim-cmp' -autocmd FileType * nmap gD (lsp-definition) -autocmd FileType * nmap gd (lsp-peek-definition) -autocmd FileType * nmap gY (lsp-type-definition) -autocmd FileType * nmap gy (lsp-peek-type-definition) -autocmd FileType * nmap gr (lsp-references) -autocmd FileType * nmap gf (lsp-document-symbol-search) -autocmd FileType * nmap gF (lsp-workspace-symbol-search) -autocmd FileType * nmap gk (lsp-next-diagnostic) +" snippets -autocmd FileType * nmap f (lsp-document-format) -autocmd FileType * nmap k (lsp-code-action) -autocmd FileType * nmap x (lsp-code-lens) -autocmd FileType * nmap n (lsp-rename) +Plug 'hrsh7th/cmp-vsnip' +Plug 'hrsh7th/vim-vsnip' -function! SplitTerm(height, cmd) - split - exe "resize " . a:height - exe "terminal " . a:cmd -endfunction +"autocmd FileType * nmap gD (lsp-definition) +"autocmd FileType * nmap gd (lsp-peek-definition) +"autocmd FileType * nmap gY (lsp-type-definition) +"autocmd FileType * nmap gy (lsp-peek-type-definition) +"autocmd FileType * nmap gr (lsp-references) +"autocmd FileType * nmap gf (lsp-document-symbol-search) +"autocmd FileType * nmap gF (lsp-workspace-symbol-search) +"autocmd FileType * nmap gk (lsp-next-diagnostic) +" +"autocmd FileType * nmap f (lsp-document-format) +"autocmd FileType * nmap k (lsp-code-action) +"autocmd FileType * nmap x (lsp-code-lens) +"autocmd FileType * nmap n (lsp-rename) +" +"function! SplitTerm(height, cmd) +" split +" exe "resize " . a:height +" exe "terminal " . a:cmd +"endfunction " rust -autocmd FileType rust nmap t :call SplitTerm(16, "cargo test") -autocmd FileType rust nmap b :call SplitTerm(16, "cargo build") -autocmd FileType rust nmap r :call SplitTerm(16, "cargo run") -autocmd FileType rust nmap K (lsp-hover) +"autocmd FileType rust nmap t :call SplitTerm(16, "cargo test") +"autocmd FileType rust nmap b :call SplitTerm(16, "cargo build") +"autocmd FileType rust nmap r :call SplitTerm(16, "cargo run") +"autocmd FileType rust nmap K (lsp-hover) " go -Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } -let g:go_highlight_types = 1 -let g:go_highlight_fields = 1 -let g:go_highlight_functions = 1 -let g:go_highlight_function_calls = 1 -let g:go_highlight_operators = 1 -let g:go_highlight_extra_types = 1 -let g:go_highlight_build_constraints = 1 -let g:go_highlight_generate_tags = 1 -let g:go_metalinter_autosave = 1 -let g:go_fmt_command = "goimports" -let g:go_list_type_commands = {"GoMetaLinterAutoSave": "quickfix"} -let g:go_def_mapping_enabled = 0 -autocmd FileType go nmap gD (go-def) -autocmd FileType go nmap gd (go-def-split) -autocmd FileType go nmap gY (go-def-type) -autocmd FileType go nmap gy (go-def-type-split) -autocmd FileType go nmap a (go-alternate-edit) -autocmd FileType go nmap t (go-test) -autocmd FileType go nmap c (go-coverage-toggle) -autocmd FileType go nmap b (go-build) -autocmd FileType go nmap r (go-run) -autocmd FileType go nmap K (go-doc) +"Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' } +"let g:go_highlight_types = 1 +"let g:go_highlight_fields = 1 +"let g:go_highlight_functions = 1 +"let g:go_highlight_function_calls = 1 +"let g:go_highlight_operators = 1 +"let g:go_highlight_extra_types = 1 +"let g:go_highlight_build_constraints = 1 +"let g:go_highlight_generate_tags = 1 +"let g:go_metalinter_autosave = 1 +"let g:go_fmt_command = "goimports" +"let g:go_list_type_commands = {"GoMetaLinterAutoSave": "quickfix"} +"let g:go_def_mapping_enabled = 0 +"autocmd FileType go nmap gD (go-def) +"autocmd FileType go nmap gd (go-def-split) +"autocmd FileType go nmap gY (go-def-type) +"autocmd FileType go nmap gy (go-def-type-split) +"autocmd FileType go nmap a (go-alternate-edit) +"autocmd FileType go nmap t (go-test) +"autocmd FileType go nmap c (go-coverage-toggle) +"autocmd FileType go nmap b (go-build) +"autocmd FileType go nmap r (go-run) +"autocmd FileType go nmap K (go-doc) " javascript & typescript -autocmd FileType javascript,typescript nmap t :call SplitTerm(16, "npm test") -autocmd FileType javascript,typescript nmap b :call SplitTerm(16, "npm run build") -autocmd FileType javascript,typescript nmap r :call SplitTerm(16, "npm start") -autocmd FileType javascript,typescript nmap K (lsp-hover) +"autocmd FileType javascript,typescript nmap t :call SplitTerm(16, "npm test") +"autocmd FileType javascript,typescript nmap b :call SplitTerm(16, "npm run build") +"autocmd FileType javascript,typescript nmap r :call SplitTerm(16, "npm start") +"autocmd FileType javascript,typescript nmap K (lsp-hover) " vue -Plug 'posva/vim-vue' +"Plug 'posva/vim-vue' " more language servers -if executable('astro-ls') - " npm install --global @astrojs/language-server - au User lsp_setup call lsp#register_server({'name': 'astro-ls', 'cmd': {server_info->['astro-ls']}, 'allowlist': ['astro']}) -endif +"if executable('astro-ls') +" " npm install --global @astrojs/language-server +" au User lsp_setup call lsp#register_server({'name': 'astro-ls', 'cmd': {server_info->['astro-ls']}, 'allowlist': ['astro']}) +"endif " git @@ -241,3 +253,7 @@ let g:netrw_winsize=25 " spellcheck set spell spelllang=en_gb + +" code completion using language server protocol + +lua require("lsp") diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..3e4348a --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,86 @@ +-- Mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +local opts = { noremap=true, silent=true } +vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) +vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + +-- 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) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, bufopts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'x', vim.lsp.codelens.run, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', 'f', function() vim.lsp.buf.format { async = true } end, bufopts) +end + +-- Add additional capabilities supported by nvim-cmp +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +-- Configure LSP servers +local lspconfig = require('lspconfig') +require('mason').setup() +require('mason-lspconfig').setup() +require('mason-lspconfig').setup_handlers { + function (server_name) + lspconfig[server_name].setup { + on_attach = on_attach, + capabilities = capabilities, + } + end +} + +-- Configure nvim-cmp +local cmp = require('cmp') +cmp.setup { + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + }, +} diff --git a/.docker/alpine b/.docker/alpine index 361d285..7131177 100644 --- a/.docker/alpine +++ b/.docker/alpine @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-desktop b/.docker/alpine-desktop index 2d63a6a..b9170f1 100644 --- a/.docker/alpine-desktop +++ b/.docker/alpine-desktop @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-desktopbase b/.docker/alpine-desktopbase index 4757ef2..0ef12c9 100644 --- a/.docker/alpine-desktopbase +++ b/.docker/alpine-desktopbase @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-go b/.docker/alpine-go index 6a5cd3a..e2823d9 100644 --- a/.docker/alpine-go +++ b/.docker/alpine-go @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-node b/.docker/alpine-node index 54a966c..b3cdebf 100644 --- a/.docker/alpine-node +++ b/.docker/alpine-node @@ -1,4 +1,4 @@ -FROM node:current-alpine3.14 +FROM node:current-alpine3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-pwn b/.docker/alpine-pwn index 9676786..f68d6bf 100644 --- a/.docker/alpine-pwn +++ b/.docker/alpine-pwn @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-rust b/.docker/alpine-rust index 64a9296..8698dc4 100644 --- a/.docker/alpine-rust +++ b/.docker/alpine-rust @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/alpine-slim b/.docker/alpine-slim index 06e4e6a..fc2962b 100644 --- a/.docker/alpine-slim +++ b/.docker/alpine-slim @@ -1,4 +1,4 @@ -FROM alpine:3.14 +FROM alpine:3.17 RUN echo hosts: dns files > /etc/nsswitch.conf RUN apk add --no-cache --update \ diff --git a/.docker/fedora b/.docker/fedora index 83e7f3e..89e0445 100644 --- a/.docker/fedora +++ b/.docker/fedora @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf install -y \ zsh \ diff --git a/.docker/fedora-desktop b/.docker/fedora-desktop index be94b43..0249f4e 100644 --- a/.docker/fedora-desktop +++ b/.docker/fedora-desktop @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf install -y \ zsh \ diff --git a/.docker/fedora-desktopbase b/.docker/fedora-desktopbase index 45ac1d6..9de0ff9 100644 --- a/.docker/fedora-desktopbase +++ b/.docker/fedora-desktopbase @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf install -y \ zsh \ diff --git a/.docker/fedora-go b/.docker/fedora-go index e9f266d..909eac7 100644 --- a/.docker/fedora-go +++ b/.docker/fedora-go @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf install -y \ zsh \ diff --git a/.docker/fedora-pwn b/.docker/fedora-pwn index 0ce5cc6..41e16a7 100644 --- a/.docker/fedora-pwn +++ b/.docker/fedora-pwn @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf install -y \ zsh \ diff --git a/.docker/fedora-rust b/.docker/fedora-rust index f3e9619..19b7bab 100644 --- a/.docker/fedora-rust +++ b/.docker/fedora-rust @@ -1,4 +1,4 @@ -FROM fedora:34 +FROM fedora:37 RUN dnf install -y \ zsh \ diff --git a/.docker/ubuntu b/.docker/ubuntu index 444e7a7..9ae9790 100644 --- a/.docker/ubuntu +++ b/.docker/ubuntu @@ -1,4 +1,4 @@ -FROM ubuntu:21.04 +FROM ubuntu:22.04 RUN apt-get update \ && apt-get install -y \ diff --git a/.docker/ubuntu-desktop b/.docker/ubuntu-desktop index 886280c..64dd4ed 100644 --- a/.docker/ubuntu-desktop +++ b/.docker/ubuntu-desktop @@ -1,4 +1,4 @@ -FROM ubuntu:21.04 +FROM ubuntu:22.04 RUN apt-get update \ && apt-get install -y \ diff --git a/.docker/ubuntu-desktopbase b/.docker/ubuntu-desktopbase index 63b18d1..b32577e 100644 --- a/.docker/ubuntu-desktopbase +++ b/.docker/ubuntu-desktopbase @@ -1,4 +1,4 @@ -FROM ubuntu:21.04 +FROM ubuntu:22.04 RUN apt-get update \ && apt-get install -y \ diff --git a/.docker/ubuntu-pwn b/.docker/ubuntu-pwn index deb5592..72296b1 100644 --- a/.docker/ubuntu-pwn +++ b/.docker/ubuntu-pwn @@ -1,4 +1,4 @@ -FROM ubuntu:21.04 +FROM ubuntu:22.04 RUN apt-get update \ && apt-get install -y \ diff --git a/.gitignore b/.gitignore index 22a1822..d01f7f3 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ !.config/nvim/colors !.config/nvim/skel !.config/nvim/init.vim +!.config/nvim/lua !.config/skhd !.config/sway .config/sway/enabled/* diff --git a/.zshrc b/.zshrc index 4174161..1b2ee72 100644 --- a/.zshrc +++ b/.zshrc @@ -64,10 +64,16 @@ if [[ -d "$HOME/.deno" ]]; then export DENO_INSTALL="$HOME/.deno" export PATH="$DENO_INSTALL/bin:$PATH" fi -if [[ -d "$HOME/.nvm" ]]; then - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm - [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +export PYENV_ROOT="$HOME/.pyenv" +if [[ -d "$PYENV_ROOT" ]]; then + command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init -)" + eval "$(pyenv virtualenv-init -)" +fi +export NVM_DIR="$HOME/.nvm" +if [[ -d "$NVM_DIR" ]]; then + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" fi if [[ -f "$(which ruby 2>/dev/null)" ]]; then export PATH="$(ruby -e 'puts Gem.user_dir')/bin:$PATH" @@ -502,3 +508,6 @@ if [[ -f "$(which gpgconf 2>/dev/null)" ]]; then echo UPDATESTARTUPTTY | gpg-connect-agent >/dev/null 2>&1 } fi + +# add Pulumi to the PATH +export PATH=$PATH:$HOME/.pulumi/bin