initial working version with nvim

This commit is contained in:
Thies Lennart Alff 2023-08-24 12:45:47 +02:00
parent 8c8cc7750b
commit b2397c3a80
19 changed files with 344 additions and 108 deletions

View file

@ -1,5 +1,5 @@
FROM osrf/ros:humble-desktop-full
ARG ROS_DISTR=humble
FROM osrf/ros:iron-desktop-full
ARG ROS_DISTR=iron
ENV DEBIAN_FRONTEND=noninteractive
ENV NVIDIA_VISIBLE_DEVICES \
@ -11,12 +11,6 @@ ARG USER_UID=1000
ARG USER_GID=$USER_UID
ENV ROS_DISTR=$ROS_DISTR
RUN mkdir -p /ros2/src
RUN mkdir -p /ros2_underlay/src
ADD ros2/src /ros2/src
ADD ros2_underlay/src /ros2_underlay/src
RUN apt-get update \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
&& apt-get install -y \
@ -25,25 +19,35 @@ RUN apt-get update \
mesa-utils \
mesa-utils-extra \
python3-pip \
python3-venv \
avahi-daemon \
avahi-utils \
libnss-mdns \
iputils-ping \
sudo \
neovim \
ripgrep \
wget \
byobu \
ros-${ROS_DISTR}-rqt-tf-tree \
ros-${ROS_DISTR}-apriltag \
clang-format \
&& python3 -m pip install yapf \
rope \
flake8 \
pylint \
jedi \
&& rosdep install --from-paths /ros2_underlay/src -y --ignore-src \
xclip \
# neovim build depends \
ninja-build \
gettext \
cmake \
unzip \
curl \
# end neovim build depends \
# && rosdep install --from-paths /ros2_underlay/src -y --ignore-src \
# && rosdep install --from paths /ros2/src -y --ignore-src \
&& curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get remove nodejs \
&& apt-get install nodejs \
&& git clone https://github.com/neovim/neovim.git \
&& cd neovim && git checkout stable && make CMAKE_BUILD_TYPE=RelWithDebInfo \
&& sudo make install \
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
@ -79,14 +83,14 @@ USER root
RUN mkdir /zsh_history \
&& touch /zsh_history/.zsh_history \
&& chown -R $USERNAME /zsh_history
ADD ros2-vim/cpp.vim /home/$USERNAME/.vim/after/ftplugin/cpp.vim
ADD ros2-vim/nvim /home/$USERNAME/.config/nvim
RUN chown -R $USERNAME /home/$USERNAME/
ADD ros2-vim/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chown $USERNAME /entrypoint.sh
USER ${USERNAME}
RUN nvim --headless "+Lazy! sync" +qa
WORKDIR /home/$USERNAME
RUN wget https://raw.githubusercontent.com/llvm/llvm-project/main/clang/tools/clang-format/clang-format.py
# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
CMD [ "/usr/bin/zsh"]

View file

@ -20,7 +20,7 @@ services:
- default
stdin_open: true
tty: true
entrypoint: ["/entrypoint.sh", "byobu"]
entrypoint: ["/entrypoint.sh", "zsh"]
working_dir: /home/ros-user/uuv/ros2
devices:
- "/dev/dri:/dev/dri"
@ -47,6 +47,8 @@ services:
- SHELL=/usr/bin/zsh
- ROS_WORKSPACE=/home/ros-user/uuv/ros2
- SSH_AUTH_SOCK=/ssh-agent
- TERM=xterm-256color
- COLORTERM=24bit
volumes:
ros2_zsh_history:

View file

@ -1,15 +1,15 @@
#!/bin/bash
set -e
PX4_DIR="\$HOME/uuv/PX4-Autopilot"
WORKSPACE_DIR="\$HOME/uuv/ros2"
echo "source $PX4_DIR/Tools/setup_gazebo.bash $PX4_DIR $PX4_DIR/build/px4_sitl_default > /dev/null" >> ~/.zshrc
echo "export ROS_PACKAGE_PATH=\$ROS_PACKAGE_PATH:$PX4_DIR" >> ~/.zshrc
echo "export ROS_PACKAGE_PATH=\$ROS_PACKAGE_PATH:$PX4_DIR/Tools/sitl_gazebo" >> ~/.zshrc
UNDERLAY_DIR="\$HOME/uuv/ros2_underlay"
echo "alias build_ros=\"env -i HOME=\$HOME USER=\$USER TERM=xterm-256color bash -l -c 'source $UNDERLAY_DIR/install/setup.bash && cd $WORKSPACE_DIR && colcon build --symlink-install --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON'\"" >> ~/.zshrc
echo "alias build_underlay=\"env -i HOME=\$HOME USER=\$USER TERM=xterm-256color bash -l -c 'source /opt/ros/$ROS_DISTR/setup.bash && cd $UNDERLAY_DIR && colcon build'\"" >> ~/.zshrc
echo 'source $HOME/uuv/ros2_underlay/install/setup.zsh' >> ~/.zshrc
echo 'source $HOME/uuv/ros2/install/local_setup.zsh' >> ~/.zshrc
echo 'eval "$(register-python-argcomplete3 ros2)"' >> ~/.zshrc
echo 'eval "$(register-python-argcomplete3 colcon)"' >> ~/.zshrc
vim +PluginUpdate +qall
exec $@

View file

@ -0,0 +1,6 @@
function ColorMyPencils(color)
color = color or "rose-pine"
vim.cmd.colorscheme(color)
end
ColorMyPencils()

View file

@ -0,0 +1 @@
vim.keymap.set("n", "<leader>gs", vim.cmd.Git);

View file

@ -0,0 +1,9 @@
require('gitsigns').setup {
signs = {
add = {text='+'},
change = {text='~'},
delete = {text='_'},
topdelete = {text=''},
changedelete = {text='~'},
}
}

View file

@ -0,0 +1,10 @@
local mark = require('harpoon.mark')
local ui = require('harpoon.ui')
vim.keymap.set('n', '<leader>a', mark.add_file)
vim.keymap.set('n', '<C-e>', ui.toggle_quick_menu)
vim.keymap.set('n', '<C-h>', function() ui.nav_file(1) end)
vim.keymap.set('n', '<C-t>', function() ui.nav_file(2) end)
vim.keymap.set('n', '<C-n>', function() ui.nav_file(3) end)
vim.keymap.set('n', '<C-s>', function() ui.nav_file(4) end)

51
nvim/after/plugin/lsp.lua Normal file
View file

@ -0,0 +1,51 @@
require('mason').setup({
ui = {
border = 'rounded'
}
})
-- Install language servers
require('mason-lspconfig').setup {
ensure_installed = {
'lua_ls', 'clangd', 'pylsp', 'yamlls'
}
}
local lsp = require('lsp-zero').preset({})
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({ buffer = bufnr })
end)
-- (Optional) Configure lua language server for neovim
require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls())
lsp.setup()
local cmp = require('cmp')
local cmp_action = require('lsp-zero').cmp_action()
-- configure auto complete key
cmp.setup({
mapping = {
['<Tab>'] = cmp_action.tab_complete(),
['<S-Tab>'] = cmp_action.select_prev_or_fallback(),
['<C-e>'] = cmp.mapping.abort(),
['<C-space>'] = cmp.mapping.complete(),
['<C-j>'] = cmp.mapping.scroll_docs(1),
['<C-k>'] = cmp.mapping.scroll_docs(-1),
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
})
require('lspconfig').pylsp.setup {
settings = {
pylsp = {
plugins = {
autopep8 = { enabled = false },
yapf = { enabled = true, args = '--style={based_on_style: google column_limit: 80}' },
}
}
}
}

View file

@ -0,0 +1,6 @@
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>pf', builtin.find_files, {})
vim.keymap.set("n", "C-p", builtin.git_files, {})
vim.keymap.set("n", "<leader>ps", function()
builtin.grep_string({ search = vim.fn.input("Grep > ") });
end)

View file

@ -0,0 +1,35 @@
require('nvim-treesitter.configs').setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "cpp", "python", "yaml" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
-- List of parsers to ignore installing (for "all")
ignore_install = { "javascript" },
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
highlight = {
enable = true,
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}

17
nvim/init.lua Normal file
View file

@ -0,0 +1,17 @@
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = ' ' -- needs to be set before lazy im
require('lazy').setup('plugins')
require('lennartalff')

16
nvim/lazy-lock.json Normal file
View file

@ -0,0 +1,16 @@
{
"LuaSnip": { "branch": "master", "commit": "c4d6298347f7707e9757351b2ee03d0c00da5c20" },
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"gitsigns.nvim": { "branch": "main", "commit": "749267aaa863c30d721c9913699c5d94e0c07dd3" },
"harpoon": { "branch": "master", "commit": "21f4c47c6803d64ddb934a5b314dcb1b8e7365dc" },
"lazy.nvim": { "branch": "main", "commit": "dac844ed617dda4f9ec85eb88e9629ad2add5e05" },
"lsp-zero.nvim": { "branch": "v2.x", "commit": "f084f4a6a716f55bf9c4026e73027bb24a0325a3" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "2997f467881ac4faa6f8c5e7065e3a672297c8ad" },
"mason.nvim": { "branch": "main", "commit": "a51c2d063c5377ee9e58c5f9cda7c7436787be72" },
"nvim-cmp": { "branch": "main", "commit": "51f1e11a89ec701221877532ee1a23557d291dd5" },
"nvim-lspconfig": { "branch": "master", "commit": "f7922e59aeb9bc3e31a660ea4e7405ffa3fc2c3a" },
"nvim-treesitter": { "branch": "master", "commit": "99eef501a3d9128c15440296850b5bb178d6d560" },
"plenary.nvim": { "branch": "master", "commit": "267282a9ce242bbb0c5dc31445b6d353bed978bb" },
"rose-pine": { "branch": "main", "commit": "e29002cbee4854a9c8c4b148d8a52fae3176070f" },
"telescope.nvim": { "branch": "master", "commit": "2d92125620417fbea82ec30303823e3cd69e90e8" }
}

View file

@ -0,0 +1,3 @@
require('lennartalff.remap')
require('lennartalff.set')
vim.cmd('colorscheme rose-pine')

View file

@ -0,0 +1,65 @@
-- packer bootstrapping
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path })
vim.cmd [[packadd packer.nvim]]
return true
end
return false
end
local packer_bootstrap = ensure_packer()
return require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use 'lewis6991/gitsigns.nvim'
use {
'nvim-telescope/telescope.nvim', tag = '0.1.1',
-- or , branch = '0.1.x',
requires = { { 'nvim-lua/plenary.nvim' } }
}
use({ 'rose-pine/neovim', as = 'rose-pine' })
use {
'nvim-treesitter/nvim-treesitter',
run = function()
local ts_update = require('nvim-treesitter.install').update({ with_sync = true })
ts_update()
end,
}
use 'tpope/vim-fugitive'
use {
'VonHeikemen/lsp-zero.nvim',
branch = 'v2.x',
requires = {
-- LSP Support
{ 'neovim/nvim-lspconfig' }, -- Required
{ -- Optional
'williamboman/mason.nvim',
run = function()
pcall(vim.cmd, 'MasonUpdate')
end,
},
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional
-- Autocompletion
{ 'hrsh7th/nvim-cmp' }, -- Required
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required
{ 'L3MON4D3/LuaSnip' }, -- Required
{ 'mhartington/formatter.nvim' },
}
}
use {
"ThePrimeagen/refactoring.nvim",
requires = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter" }
}
}
if packer_bootstrap then
require('packer').sync()
end
end)

View file

@ -0,0 +1,34 @@
vim.g.mapleader = " "
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
-- move selected text
vim.keymap.set('v', 'J', ":m '>+1<CR>gv=gv")
vim.keymap.set('v', 'K', ":m '<-2<CR>gv=gv")
vim.keymap.set('n', 'J', 'mzJ`z')
vim.keymap.set('n', '<C-d>', '<C-d>zz')
vim.keymap.set('n', '<C-u>', '<C-u>zz')
-- yank to clipboard
vim.keymap.set('n', '<leader>y', '"+y')
vim.keymap.set('v', '<leader>y', '"+y')
-- delete to void
vim.keymap.set('n', '<leader>d', '"_d')
vim.keymap.set('v', '<leader>d', '"_d')
vim.keymap.set('i', '<C-c>', '<Esc>')
-- avoid accidentally closing everything!
vim.keymap.set('n', 'Q', '<nop>')
vim.keymap.set('n', '<leader>f', function()
vim.lsp.buf.format()
end)
-- quickfix navigation
vim.keymap.set('n', '<C-k>', '<cmd>cnext<CR>zz')
vim.keymap.set('n', '<C-j>', '<cmd>cprev<CR>zz')
vim.keymap.set('n', '<leader>k', '<cmd>lnext<CR>zz')
vim.keymap.set('n', '<leader>j', '<cmd>lprev<CR>zz')

View file

@ -0,0 +1,29 @@
-- vim.opt.guicursor = ''
-- line numbers
vim.opt.nu = true
vim.opt.relativenumber = true
-- default indentation
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.wrap = false
vim.api.nvim_create_autocmd("FileTYpe", {
pattern = "cpp",
callback = function()
vim.opt_local.shiftwidth = 2
vim.opt_local.tabstop = 2
end
})
vim.opt.scrolloff = 8
vim.opt.signcolumn = 'yes'
vim.opt.updatetime = 500
vim.opt.colorcolumn = '80'

33
nvim/lua/plugins/init.lua Normal file
View file

@ -0,0 +1,33 @@
return {
{ 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate' },
'lewis6991/gitsigns.nvim',
{
'nvim-telescope/telescope.nvim',
dependencies = {
{ 'nvim-lua/plenary.nvim' } }
},
{ 'rose-pine/neovim', name = 'rose-pine' },
-- 'tpope/fugitive',
{
'VonHeikemen/lsp-zero.nvim',
branch = 'v2.x',
dependencies = {
-- LSP Support
{ 'neovim/nvim-lspconfig' }, -- Required
{ 'williamboman/mason.nvim' }, -- Optional
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional
-- Autocompletion
{ 'hrsh7th/nvim-cmp' }, -- Required
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required
{ 'L3MON4D3/LuaSnip' }, -- Required
},
},
{
'ThePrimeagen/harpoon',
dependencies = {
{ 'nvim-lua/plenary.nvim' },
},
},
}

68
vimrc
View file

@ -1,68 +0,0 @@
set nocompatible
" required for vundle
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'preservim/nerdtree'
Plugin 'ycm-core/YouCompleteMe'
Plugin 'NLKNguyen/papercolor-theme'
Plugin 'tmsvg/pear-tree'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'aonemd/quietlight.vim'
Plugin 'octol/vim-cpp-enhanced-highlight'
call vundle#end()
filetype plugin indent on
syntax on
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
"disable soft wraps
set nowrap
augroup WrapLine
autocmd!
autocmd FileType txt setlocal wrap
autocmd FileType rst setlocal wrap
augroup End
" highlight current line
set cursorline
" enable line numbers
set number relativenumber
set nu rnu
set ruler
set visualbell
set encoding=utf-8
set ttyfast
let mapleader=","
" always show mode status line
set laststatus=2
" always show mode
set showmode
inoremap jj <ESC>
nnoremap <leader>t :NERDTreeToggle<CR>
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-f> :NERDTreeFind<CR>
set t_Co=256
set background=light
silent! colorscheme PaperColor
let g:airline_theme='papercolor'
:set colorcolumn=81,121
let g:clang_format_fallback_style="Google"
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_confirm_extra_conf=0
let g:ycm_always_populate_location_list=1
let g:ycm_clangd_args=['--header-insertion=never']
autocmd FileType c,cpp nnoremap <leader>f :py3f $HOME/clang-format.py<CR>
autocmd FileType c,cpp vnoremap <leader>f :py3f $HOME/clang-format.py<CR>
" autocmd FileType python nnoremap <leader><F> :0,$!yapf<CR><C-o>
autocmd FileType python nnoremap <leader>f :0,$!yapf<CR><C-o>

View file

@ -1,17 +0,0 @@
import os
import shlex
import subprocess
def find_ros_python_packages():
ros_ws = os.environ['ROS_WORKSPACE']
cmd = shlex.split(
f'bash -c "source {ros_ws}/install/setup.bash && echo $PYTHONPATH"')
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for line in p.stdout:
paths = line.rstrip().split(':')
p.communicate()
return paths
def Settings(**kwargs):
return {'sys_path': find_ros_python_packages()}