diff --git a/.local-history/8f0ad6901e5fa75b27703f8aee15c8cb b/.local-history/8f0ad6901e5fa75b27703f8aee15c8cb deleted file mode 100644 index 47280b5..0000000 Binary files a/.local-history/8f0ad6901e5fa75b27703f8aee15c8cb and /dev/null differ diff --git a/.local-history/96a4f251a2c446338e79b64d19526f45 b/.local-history/96a4f251a2c446338e79b64d19526f45 deleted file mode 100644 index 36fcc5b..0000000 Binary files a/.local-history/96a4f251a2c446338e79b64d19526f45 and /dev/null differ diff --git a/.local-history/9c841e3f41dcb8e5c8221d5044a35642 b/.local-history/9c841e3f41dcb8e5c8221d5044a35642 deleted file mode 100644 index 7208558..0000000 Binary files a/.local-history/9c841e3f41dcb8e5c8221d5044a35642 and /dev/null differ diff --git a/.local-history/d2580a4acf39743cb5e5b291f0f449a1 b/.local-history/d2580a4acf39743cb5e5b291f0f449a1 deleted file mode 100644 index 025a7f6..0000000 Binary files a/.local-history/d2580a4acf39743cb5e5b291f0f449a1 and /dev/null differ diff --git a/Base.dockerfile b/Base.dockerfile index a08693a..aa6c7e3 100644 --- a/Base.dockerfile +++ b/Base.dockerfile @@ -1,4 +1,5 @@ -FROM ubuntu:21.10 +ARG BASE_IMAGE=ubuntu:21.10 +FROM ${BASE_IMAGE} LABEL maintainer="githubzilla" ARG USER=devuser @@ -6,26 +7,11 @@ ARG PW=passwd01 ENV DEBIAN_FRONTEND=noninteractive -RUN apt-get update -RUN apt-get install -y sudo -RUN apt-get install -y iputils-ping -RUN apt-get install -y net-tools -RUN apt-get install -y wget -RUN apt-get install -y curl -RUN apt-get install -y telnet -RUN apt-get install -y git -RUN apt-get install -y zsh -RUN apt-get install -y fonts-powerline -RUN apt-get install -y llvm -RUN apt-get install -y llvm-dev -RUN apt-get install -y clang -RUN apt-get install -y clangd -RUN apt-get install -y build-essential -RUN apt-get install -y ranger -RUN apt-get install -y software-properties-common -RUN add-apt-repository ppa:neovim-ppa/unstable -RUN apt-get update -RUN apt-get install -y neovim +RUN apt-get update && apt-get install -y sudo iputils-ping net-tools wget curl telnet git zsh fonts-powerline llvm llvm-dev clang clangd gdb lldb build-essential ranger software-properties-common ripgrep fd-find pkg-config trash-cli tmux pandoc lynx python3-pip elfutils + +#install latest neovim +ADD files/nvim-0.6.1.tar.gz / +RUN ln -s /nvim/bin/nvim /usr/bin/nvim && pip install pynvim #require by vimspector #add developer user account RUN adduser --quiet --disabled-password --shell /bin/zsh --home /home/${USER} --gecos "User" ${USER} && \ @@ -37,20 +23,19 @@ WORKDIR /home/${USER} #Install rust RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /home/${USER}/rustup.sh -RUN chmod +x /home/${USER}/rustup.sh -RUN /home/${USER}/rustup.sh -y -RUN rm /home/${USER}/rustup.sh -RUN . /home/${USER}/.cargo/env && rustup toolchain install nightly -RUN . /home/${USER}/.cargo/env && rustup default nightly -RUN . /home/${USER}/.cargo/env && rustup component add rust-src -RUN . /home/${USER}/.cargo/env && rustup +nightly component add rust-analyzer-preview +RUN chmod +x /home/${USER}/rustup.sh && /home/${USER}/rustup.sh -y && rm /home/${USER}/rustup.sh +RUN . /home/${USER}/.cargo/env && \ + rustup toolchain install nightly && \ + rustup default nightly && \ + rustup component add rust-src && \ + rustup +nightly component add rust-analyzer-preview #setup oh-my-zsh -RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh -RUN git clone https://github.com/zsh-users/zsh-autosuggestions /home/${USER}/.oh-my-zsh/custom/plugins/zsh-autosuggestions -RUN git clone https://github.com/romkatv/powerlevel10k.git +RUN wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh && \ + git clone https://github.com/zsh-users/zsh-autosuggestions /home/${USER}/.oh-my-zsh/custom/plugins/zsh-autosuggestions && \ + git clone https://github.com/romkatv/powerlevel10k.git && \ + /home/${USER}/powerlevel10k/gitstatus/install # run gitstatusd install when docker build rather than postpone to the actuall run time -RUN /home/${USER}/powerlevel10k/gitstatus/install #add oh-my-zsh config files ADD --chown=${USER}:${USER} files/dotzshrc /home/${USER}/.zshrc @@ -58,8 +43,6 @@ ADD --chown=${USER}:${USER} files/dotp10k.zsh /home/${USER}/.p10k.zsh ADD --chown=${USER}:${USER} files/dotprofile /home/${USER}/.profile #Install vim-plug for neovim -#RUN sh -c 'curl -fLo "/home/${USER}/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ - #https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' RUN mkdir -p /home/${USER}/.local/share/nvim/site/autoload ADD --chown=${USER}:${USER} files/plug.vim /home/${USER}/.local/share/nvim/site/autoload/plug.vim @@ -69,9 +52,8 @@ USER root RUN chown -R ${USER}:${USER} /home/${USER}/.config USER ${USER} #run plug install -RUN nvim --headless +silent +PlugInstall +qall +RUN nvim --headless +silent +PlugInstall +qall && nvim --headless +silent +TSInstall rust c cpp javascript css html +qall #run treesitter Install -RUN nvim --headless +silent +TSInstall rust c cpp javascript css html +qall #install nvm USER root diff --git a/Pglogical.dockerfile b/Pglogical.dockerfile new file mode 100644 index 0000000..3a469c0 --- /dev/null +++ b/Pglogical.dockerfile @@ -0,0 +1,38 @@ +ARG BASE_IMAGE=xj4reg/postgresql-dev:latest +#ARG BASE_IMAGE=registry-vpc.cn-hongkong.aliyuncs.com/xj4reg/postgresql-dev:latest +FROM ${BASE_IMAGE} + +ARG USER=devuser + +USER root + +#install bear +RUN apt-get install -y bear +RUN apt-get install -y python3-pip +RUN pip install compdb + +#get source +WORKDIR /home/${USER} +ADD --chown=${USER}:${USER} files/pglogical-REL2_4_0.zip /home/${USER}/ +RUN apt-get update +RUN apt-get install unzip +RUN unzip pglogical-REL2_4_0.zip +RUN rm pglogical-REL2_4_0.zip +RUN mv /home/${USER}/pglogical-REL2_4_0 /home/${USER}/pglogical + +#make +ENV PATH="/usr/local/pgsql/bin:${PATH}" +WORKDIR /home/${USER}/pglogical +RUN bear -- make +RUN compdb -p ./ list > compile_commands.compdb.json +RUN mv compile_commands.compdb.json compile_commands.json +RUN make install +RUN make clean + +RUN chown -R ${USER}:${USER} /home/${USER}/pglogical + +USER ${USER} + +WORKDIR /home/${USER} +ENV TERM xterm-256color +CMD ["zsh"] diff --git a/Postgresql.dockerfile b/Postgresql.dockerfile index 5062bf1..d99df59 100644 --- a/Postgresql.dockerfile +++ b/Postgresql.dockerfile @@ -1,46 +1,41 @@ -FROM xj4reg/ubuntu-dev:latest +ARG BASE_IMAGE=xj4reg/ubuntu-dev:latest +#ARG BASE_IMAGE=registry-vpc.cn-hongkong.aliyuncs.com/xj4reg/ubuntu-dev:latest +FROM ${BASE_IMAGE} ARG USER=devuser USER root #install dependences -RUN sudo apt-get install -y libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc +RUN sudo apt-get install -y libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc bear python3-pip && pip install compdb #get source WORKDIR /home/${USER} ADD --chown=${USER}:${USER} files/postgresql-13.5.tar.gz /home/${USER}/ RUN mv /home/${USER}/postgresql-13.5 /home/${USER}/postgresql -#install bear -RUN apt-get install -y bear -RUN apt-get install -y python3-pip -RUN pip install compdb - #make WORKDIR /home/${USER}/postgresql -RUN ./configure -RUN bear -- make world -RUN make install-world -RUN compdb -p ./ list > compile_commands.compdb.json -RUN mv compile_commands.compdb.json compile_commands.json +RUN ./configure && bear -- make world && make install-world && compdb -p ./ list > compile_commands.compdb.json && mv compile_commands.compdb.json compile_commands.json && make clean #update profile ADD --chown=${USER}:${USER} files/dotprofile.postgresql /home/${USER}/.profile +#add .inputrc +ADD --chown=${USER}:${USER} files/dotinputrc /home/${USER}/.inputrc #clean up #RUN rm -rf /home/${USER}/postgresql-13.5.tar -RUN chown ${USER}:${USER} /home/${USER}/postgresql +RUN chown -R ${USER}:${USER} /home/${USER}/postgresql #create database USER ${USER} RUN mkdir /home/${USER}/pgdata -RUN . /home/${USER}/.profile && initdb -D /home/${USER}/pgdata --username ${USER} +RUN . /home/${USER}/.profile && initdb -D /home/${USER}/pgdata --username ${USER} --encoding=UTF-8 #add postgresql script ADD --chown=${USER}:${USER} --chmod=777 files/startdb.sh /home/${USER}/startdb.sh ADD --chown=${USER}:${USER} --chmod=777 files/stopdb.sh /home/${USER}/stopdb.sh ADD --chown=${USER}:${USER} --chmod=777 files/psql.sh /home/${USER}/psql.sh -ADD --chown=${USER}:${USER} files/clangd /home/${USER}/.config/clangd +ADD --chown=${USER}:${USER} files/clangd/config.yaml /home/${USER}/.config/clangd/config.yaml WORKDIR /home/${USER} ENV TERM xterm-256color diff --git a/README.md b/README.md index 2843526..5ec57fa 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,114 @@ -# ubuntu-dev-docker -Development environment on ubuntu +# Development environment setup for C/C++/Rust +- Base.dockerfile + * C/C++/Rust Development Environment on Ubuntu +- Postgresql.dockerfile + * Having postgresql source compiled and installed +- Pglogical.dockerfile + * Having pglogical source compiled and installed + +## Preindstalled packages - wget - zsh - font-powerline +- oh-my-zsh - zsh config - add devuser -- nvim +- nvim (0.6.0) - nvim config - llvm +- clangd - rust - rust-analyzer +- build-essential +- gdb +- lldb +- ripgrep +- tmux +- bear +- compdb +- nvm +- node + +## Neovim configuration + +- LSP settings + * clangd for C/C++ development + * rust-tools for Rust devlopment +- Vimspctor + * The debug setting is project orinted, place a .vimspector.json file under project folder + * .vimspector.json for c project + + ```json + { + "configurations": { + "lldb": { + "adapter": "CodeLLDB", + "configuration": { + "name": "Launch", + "type": "lldb", + "request": "launch", + "program": "${Executable}", + "args": ["*${Args}"], + "sourceLanguages": ["c"] + }, + "breakpoints": { + "exception": { + "cpp_throw": "Y", + "cpp_catch": "N" + } + } + } + } + } + ``` + * .vimspector.json for rust project + + ```json + { + "configurations": { + "lldb": { + "adapter": "CodeLLDB", + "configuration": { + "name": "Launch", + "type": "lldb", + "request": "launch", + "program": "${Executable}", + "args": ["*${Args}"], + "sourceLanguages": ["rust"] + }, + "breakpoints": { + "exception": { + "cpp_throw": "Y", + "cpp_catch": "N" + } + } + } + } + } + ``` + +- clangd setting + * Under each project folder, there should be a compile_commands.json which configure the compile parameters for each .c and .h file. + * Auto generate the compile_command.json by the following script + + ```bash + > bear -- make + > compdb -p ./ list > compile_commands.compdb.json + > mv compile_commands.compdb.json compile_commands.json + ``` + + * In case of some project header files are not self contained, that makes compile error from clangd, for purpose of removing the those errors, you can add the default header files to ~/.config/clangd/config.yaml + + ```yaml + If: # Apply this config conditionally + PathMatch: .*\.* # to all headers and c files... + CompileFlags: # Tweak the parse settings + Add: [-include postgres.h, -include c.h, -include relcache.h] + + ``` + + + + + diff --git a/files/clangd/config.yaml b/files/clangd/config.yaml index d996b33..e65bbd5 100644 --- a/files/clangd/config.yaml +++ b/files/clangd/config.yaml @@ -1,4 +1,4 @@ If: # Apply this config conditionally - PathMatch: .*\.h # to all headers... + PathMatch: .*\.* # to all headers and c files... CompileFlags: # Tweak the parse settings - Add: [-include postgres.h] + Add: [-include postgres.h, -include c.h, -include relcache.h] diff --git a/files/dotinputrc b/files/dotinputrc new file mode 100644 index 0000000..b2cc9d6 --- /dev/null +++ b/files/dotinputrc @@ -0,0 +1 @@ +set editing-mode vi diff --git a/files/dotprofile b/files/dotprofile index c34637b..b3f8a8d 100644 --- a/files/dotprofile +++ b/files/dotprofile @@ -24,3 +24,6 @@ alias rust-analyzer='rustup run nightly rust-analyzer' set -o vi . "$HOME/.cargo/env" + +#disable trash +alias rm="echo Use 'trash', or the full path i.e. '/bin/rm'" diff --git a/files/dotzshrc b/files/dotzshrc index f44e3a4..fb61bbf 100644 --- a/files/dotzshrc +++ b/files/dotzshrc @@ -77,7 +77,7 @@ ZSH_THEME="robbyrussell" # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. -plugins=(git zsh-autosuggestions) +plugins=(git zsh-autosuggestions docker docker-compose) source $ZSH/oh-my-zsh.sh diff --git a/files/nvim-0.6.1.tar.gz b/files/nvim-0.6.1.tar.gz new file mode 100644 index 0000000..c06ea49 Binary files /dev/null and b/files/nvim-0.6.1.tar.gz differ diff --git a/files/nvim/init.vim b/files/nvim/init.vim index 1eb868d..8aba2a4 100644 --- a/files/nvim/init.vim +++ b/files/nvim/init.vim @@ -55,6 +55,7 @@ Plug 'rizzatti/dash.vim' "== telescope Plug 'nvim-lua/plenary.nvim' Plug 'nvim-telescope/telescope.nvim' +Plug 'nvim-telescope/telescope-live-grep-raw.nvim' "== treesitter, disabled since it's not work under coc.vim Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update @@ -92,6 +93,15 @@ Plug 'hrsh7th/vim-vsnip' " Optional Plug 'nvim-lua/popup.nvim' Plug 'nvim-lua/plenary.nvim' +" Debug -- don't use dap, it's kind of premature +"Plug 'mfussenegger/nvim-dap' +"Plug 'rcarriga/nvim-dap-ui' +" navigator - conflict with other lsp plugins +"Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' } +"Plug 'ray-x/navigator.lua' + +" vimspector +Plug 'puremourning/vimspector' "== rust.vim Plug 'rust-lang/rust.vim' @@ -99,12 +109,20 @@ Plug 'rust-lang/rust.vim' "== which key Plug 'folke/which-key.nvim' +"== vista function/variable outline +Plug 'liuchengxu/vista.vim' + "== ctrlspace Plug 'vim-ctrlspace/vim-ctrlspace' "== unimpaired Plug 'tpope/vim-unimpaired' +"== vim-clap +" Build the extra binary if cargo exists on your system. +Plug 'liuchengxu/vim-clap', { 'do': ':Clap install-binary' } + + call plug#end() "== autosave.vim == @@ -152,6 +170,9 @@ silent! source ~/.config/nvim/lsp_signature.vim "== nvim-cmp.vim silent! source ~/.config/nvim/nvim-cmp.vim +"== navigator.vim +"silent! source ~/.config/nvim/navigator.vim + "== ccls.vim "source ~/.config/nvim/ccls.vim @@ -164,3 +185,10 @@ silent! source ~/.config/nvim/which_key.vim "== ctrlspace silent! source ~/.config/nvim/vim-ctrlspace.vim +"== vista +source ~/.config/nvim/vista.vim + +"== vim-dap-ui +"source ~/.config/nvim/dapui.vim +"== vimspector +source ~/.config/nvim/vimspector.vim diff --git a/files/nvim/lspconfig.vim b/files/nvim/lspconfig.vim index e1367d4..da9c135 100644 --- a/files/nvim/lspconfig.vim +++ b/files/nvim/lspconfig.vim @@ -36,13 +36,136 @@ local on_attach = function(client, bufnr) end -require'lspconfig'.rust_analyzer.setup{ - on_attach = on_attach, - flags = { - debounce_text_changes = 150, - } +-- rust-analyzer is delegated by rust-tool +-- require'lspconfig'.rust_analyzer.setup{ +-- on_attach = on_attach, +-- flags = { +-- debounce_text_changes = 150, +-- } +-- } + +-- local extension_path = '/Users/tianxj/.vscode/extensions/codelldb-aarch64-darwin.vsix/extension/' +-- local codelldb_path = extension_path .. 'adapter/codelldb' +-- local liblldb_path = extension_path .. 'lldb/lib/liblldb.dylib' + +local opts = { + tools = { -- rust-tools options + -- Automatically set inlay hints (type hints) + autoSetHints = true, + + -- Whether to show hover actions inside the hover window + -- This overrides the default hover handler + hover_with_actions = true, + + -- how to execute terminal commands + -- options right now: termopen / quickfix + executor = require("rust-tools/executors").termopen, + + runnables = { + -- whether to use telescope for selection menu or not + use_telescope = true + + -- rest of the opts are forwarded to telescope + }, + + debuggables = { + -- whether to use telescope for selection menu or not + use_telescope = true + + -- rest of the opts are forwarded to telescope + }, + + -- These apply to the default RustSetInlayHints command + inlay_hints = { + + -- Only show inlay hints for the current line + only_current_line = false, + + -- Event which triggers a refersh of the inlay hints. + -- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but + -- not that this may cause higher CPU usage. + -- This option is only respected when only_current_line and + -- autoSetHints both are true. + only_current_line_autocmd = "CursorHold", + + -- wheter to show parameter hints with the inlay hints or not + show_parameter_hints = true, + + -- prefix for parameter hints + parameter_hints_prefix = "<- ", + + -- prefix for all the other hints (type, chaining) + other_hints_prefix = "=> ", + + -- whether to align to the length of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7, + + -- The color of the hints + highlight = "Comment", + }, + + hover_actions = { + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + {"╭", "FloatBorder"}, {"─", "FloatBorder"}, + {"╮", "FloatBorder"}, {"│", "FloatBorder"}, + {"╯", "FloatBorder"}, {"─", "FloatBorder"}, + {"╰", "FloatBorder"}, {"│", "FloatBorder"} + }, + + -- whether the hover action window gets automatically focused + auto_focus = false + }, + + -- settings for showing the crate graph based on graphviz and the dot + -- command + crate_graph = { + -- Backend used for displaying the graph + -- see: https://graphviz.org/docs/outputs/ + -- default: x11 + backend = "x11", + -- where to store the output, nil for no output stored (relative + -- path from pwd) + -- default: nil + output = nil, + -- true for all crates.io and external crates, false only the local + -- crates + -- default: true + full = true, + } + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + on_attach = on_attach, + debounce_text_changes = 150, + }, -- rust-analyer options + + -- debugging stuff -- use vimspector instead + -- dap = { + -- -- adapter = require('rust-tools.dap').get_codelldb_adapter(codelldb_path, liblldb_path) + -- adapter = { + -- type = 'executable', + -- command = '/opt/homebrew/Cellar/llvm/13.0.0_1/Toolchains/LLVM13.0.0.xctoolchain/usr/bin/lldb-vscode', + -- name = "rt_lldb" + -- } + -- } } +require('rust-tools').setup(opts) + require'lspconfig'.clangd.setup{ cmd = {"clangd", "--background-index", "--compile-commands-dir="..working_dir, "--enable-config"}, on_attach = on_attach, diff --git a/files/nvim/navigator.vim b/files/nvim/navigator.vim new file mode 100644 index 0000000..25cfc78 --- /dev/null +++ b/files/nvim/navigator.vim @@ -0,0 +1,4 @@ +lua <ff Telescope find_files nnoremap fF ':Telescope find_files' . expand('') nnoremap fg Telescope live_grep +nnoremap fr Telescope live_grep_raw nnoremap fG ':Telescope live_grep' . expand('') nnoremap fb Telescope buffers nnoremap fh Telescope help_tags diff --git a/files/nvim/vista.vim b/files/nvim/vista.vim new file mode 100644 index 0000000..714c751 --- /dev/null +++ b/files/nvim/vista.vim @@ -0,0 +1,19 @@ +function! NearestMethodOrFunction() abort + return get(b:, 'vista_nearest_method_or_function', '') +endfunction + +set statusline+=%{NearestMethodOrFunction()} + +" By default vista.vim never run if you don't call it explicitly. +" +" If you want to show the nearest function in your statusline automatically, +" you can add the following line to your vimrc +"autocmd VimEnter * call vista#RunForNearestMethodOrFunction() + +" Executive used when opening vista sidebar without specifying it. +" See all the avaliable executives via `:echo g:vista#executives`. +let g:vista_default_executive = 'nvim_lsp' + +nnoremap v Vista +nnoremap vc Vista! +nnoremap vt Vista!! diff --git a/files/pglogical-REL2_4_0.zip b/files/pglogical-REL2_4_0.zip new file mode 100644 index 0000000..529be43 Binary files /dev/null and b/files/pglogical-REL2_4_0.zip differ diff --git a/files/postgresql-14.1.tar.gz b/files/postgresql-14.1.tar.gz new file mode 100644 index 0000000..adc60f2 Binary files /dev/null and b/files/postgresql-14.1.tar.gz differ