From 159fadd35b66b77672f9d5c82c130e1029ea04c9 Mon Sep 17 00:00:00 2001 From: Thies Lennart Alff Date: Thu, 12 Oct 2023 14:34:01 +0200 Subject: [PATCH] many updates :-) --- Dockerfile | 83 ++++++++++++++++++------------- README.md | 2 +- cpp.vim | 4 -- docker-compose.yml | 5 ++ nvim/after/plugin/lsp.lua | 61 ----------------------- nvim/init.lua | 1 + nvim/lua/lennartalff/remap.lua | 3 -- nvim/lua/lennartalff/set.lua | 16 +++++- nvim/lua/plugins/cmp.lua | 45 +++++++++++++++++ nvim/lua/plugins/init.lua | 35 +++++++------ nvim/lua/plugins/lsp/init.lua | 88 +++++++++++++++++++++++++++++++++ nvim/lua/plugins/lsp/python.lua | 34 +++++++++++++ 12 files changed, 255 insertions(+), 122 deletions(-) delete mode 100644 cpp.vim delete mode 100644 nvim/after/plugin/lsp.lua create mode 100644 nvim/lua/plugins/cmp.lua create mode 100644 nvim/lua/plugins/lsp/init.lua create mode 100644 nvim/lua/plugins/lsp/python.lua diff --git a/Dockerfile b/Dockerfile index 821b56d..7d5c686 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,38 @@ -FROM osrf/ros:humble-desktop-full -ARG ROS_DISTR=humble - +FROM osrf/ros:iron-desktop-full AS base-ros-nvim ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ + && apt-get install -y \ + ripgrep \ + ninja-build \ + gettext \ + cmake \ + unzip \ + curl \ + clang-format \ + xclip \ + wl-clipboard \ + && mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ + && NODE_MAJOR=20 \ + && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \ + && apt update \ + && 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 \ + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + + +FROM base-ros-nvim AS base-ros-nvim-graphics +ARG ROS_DISTR=iron ENV NVIDIA_VISIBLE_DEVICES \ ${NVIDIA_VISIBLE_DEVICES:-all} ENV NVIDIA_DRIVER_CAPABILITIES \ ${NVIDIA_DRIVER_CAPABILITIES:+$NVIDIA_DRIVER_CAPABILITIES,}graphics -ARG USERNAME=ros-user -ARG USER_UID=1000 -ARG USER_GID=$USER_UID ENV ROS_DISTR=$ROS_DISTR RUN apt-get update \ @@ -25,40 +49,26 @@ RUN apt-get update \ libnss-mdns \ iputils-ping \ sudo \ - ripgrep \ wget \ - byobu \ ros-${ROS_DISTR}-rqt-tf-tree \ ros-${ROS_DISTR}-apriltag \ ros-${ROS_DISTR}-plotjuggler-ros \ - clang-format \ - 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 \ - && mkdir -p /etc/apt/keyrings \ - && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ - && NODE_MAJOR=20 \ - && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \ - && apt update \ - && 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\ - && chmod 0440 /etc/sudoers.d/$USERNAME \ && apt-get autoremove -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* + +FROM base-ros-nvim-graphics AS individual +ARG USERNAME=ros-user +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN 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\ + && chmod 0440 /etc/sudoers.d/$USERNAME + USER ${USERNAME} ENV TERM xterm-256color RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \ @@ -80,8 +90,13 @@ RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/ -a 'export COLORTERM=truecolor' \ && mkdir -p "$HOME/.zsh" \ && git clone https://github.com/sindresorhus/pure.git "$HOME/.zsh/pure" \ - && echo "source /opt/ros/$ROS_DISTR/setup.zsh" >> /home/$USERNAME/.zshrc - + && echo "source /opt/ros/$ROS_DISTR/setup.zsh" >> /home/$USERNAME/.zshrc \ + && pip3 install yapf pre-commit ruff \ + && sudo wget https://hippocampusrobotics.github.io/docs/_downloads/6055b3168d4f0a8cd764ebc481280219/ros-iron-px4-msgs_2.0.1-0jammy_amd64.deb \ + && sudo apt-get install ./ros-iron-px4-msgs_2.0.1-0jammy_amd64.deb \ + && sudo apt-get autoremove -y \ + && sudo apt-get clean -y \ + && sudo rm -rf /var/lib/apt/lists/* USER root RUN mkdir /zsh_history \ @@ -91,7 +106,7 @@ ADD ros2-vim/nvim /home/$USERNAME/.config/nvim RUN chown -R $USERNAME /home/$USERNAME/ USER ${USERNAME} RUN nvim --headless "+Lazy! sync" +qa -RUN nvim --headless +"MasonInstall lua-language-server clangd python-lsp-server yaml-language-server" +q +RUN nvim --headless +"MasonInstall lua-language-server clangd python-lsp-server yaml-language-server yapf" +q WORKDIR /home/$USERNAME USER root diff --git a/README.md b/README.md index 3a35b0c..7355225 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Update The Base Image ~~~ bash -docker pull osrf/ros:humble-desktop-full +docker pull osrf/ros:iron-desktop-full ~~~ # Rebuild The Image from Dockerfile diff --git a/cpp.vim b/cpp.vim deleted file mode 100644 index f06a24a..0000000 --- a/cpp.vim +++ /dev/null @@ -1,4 +0,0 @@ -setlocal cindent -setlocal shiftwidth=2 -setlocal expandtab -setlocal tabstop=2 diff --git a/docker-compose.yml b/docker-compose.yml index ea52b14..7ca796a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,6 +40,9 @@ services: - type: bind source: ${HOME}/Documents/ros2-vim/nvim target: /home/ros-user/.config/nvim + - type: bind + source: $XDG_RUNTIME_DIR/${WAYLAND_DISPLAY} + target: /tmp/${WAYLAND_DISPLAY} - "ros2_zsh_history:/zsh_history" - nvim_data:/home/ros-user/.local/share/nvim - $SSH_AUTH_SOCK:/ssh-agent @@ -47,6 +50,8 @@ services: environment: - DISPLAY=${DISPLAY} + - XDG_RUNTIME_DIR=/tmp + - WAYLAND_DISPLAY=${WAYLAND_DISPLAY} - QT_X11_NO_MITSHM=1 - SHELL=/usr/bin/zsh - ROS_WORKSPACE=/home/ros-user/uuv/ros2 diff --git a/nvim/after/plugin/lsp.lua b/nvim/after/plugin/lsp.lua deleted file mode 100644 index 83ccf0e..0000000 --- a/nvim/after/plugin/lsp.lua +++ /dev/null @@ -1,61 +0,0 @@ -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({ - manage_nvim_cmp = { - set_sources = 'lsp', - set_basic_mappings = true, - set_extra_mappings = false, - use_luasnip = true, - set_format = true, - documentation_window = true, - } -}) - -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 = { - [''] = cmp_action.tab_complete(), - [''] = cmp_action.select_prev_or_fallback(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.scroll_docs(1), - [''] = cmp.mapping.scroll_docs(-1), - [''] = cmp.mapping.confirm({ select = false }), - }, - 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}' }, - } - } - } -} diff --git a/nvim/init.lua b/nvim/init.lua index f6b1390..ac3820e 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -15,3 +15,4 @@ vim.g.mapleader = ' ' -- needs to be set before lazy im require('lazy').setup('plugins') require('lennartalff') +require('plugins.lsp') diff --git a/nvim/lua/lennartalff/remap.lua b/nvim/lua/lennartalff/remap.lua index 596ab06..dffd4b9 100644 --- a/nvim/lua/lennartalff/remap.lua +++ b/nvim/lua/lennartalff/remap.lua @@ -33,9 +33,6 @@ vim.keymap.set('n', '', 'cprevzz') vim.keymap.set('n', 'j', 'lnextzz') vim.keymap.set('n', 'k', 'lprevzz') -vim.keymap.set('n', 'i', vim.lsp.buf.hover) -vim.keymap.set('n', 'r', vim.lsp.buf.rename) - vim.keymap.set('n', 'dq', vim.diagnostic.setqflist) local function quickfix() vim.lsp.buf.code_action({ diff --git a/nvim/lua/lennartalff/set.lua b/nvim/lua/lennartalff/set.lua index 0a97f37..ca9047a 100644 --- a/nvim/lua/lennartalff/set.lua +++ b/nvim/lua/lennartalff/set.lua @@ -4,6 +4,8 @@ vim.opt.nu = true vim.opt.relativenumber = true +vim.opt.breakindent = true + -- default indentation vim.opt.tabstop = 4 vim.opt.softtabstop = 4 @@ -14,7 +16,7 @@ vim.opt.smartindent = true vim.opt.wrap = false -vim.api.nvim_create_autocmd("FileTYpe", { +vim.api.nvim_create_autocmd("FileType", { pattern = "cpp", callback = function() vim.opt_local.shiftwidth = 2 @@ -27,3 +29,15 @@ vim.opt.signcolumn = 'yes' vim.opt.updatetime = 500 vim.opt.colorcolumn = '80' +vim.api.nvim_create_autocmd('FileType', { + pattern = 'rst', + callback = function() + vim.opt.wrap = true -- softwrap the text + vim.opt.linebreak = true -- do not break in the middle of words + -- rst uses 3 space indents + vim.opt.tabstop = 3 + vim.opt.softtabstop = 3 + vim.opt.shiftwidth = 3 + vim.opt.expandtab = true + end +}) diff --git a/nvim/lua/plugins/cmp.lua b/nvim/lua/plugins/cmp.lua new file mode 100644 index 0000000..1b1a55c --- /dev/null +++ b/nvim/lua/plugins/cmp.lua @@ -0,0 +1,45 @@ +return { + 'hrsh7th/nvim-cmp', + dependencies = { + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/cmp-nvim-lua'}, + {'L3MON4D3/LuaSnip'}, + }, + config = function() + local cmp = require('cmp') + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'nvim_lua' }, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm({ select = false }), + }), + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + }) + end +} diff --git a/nvim/lua/plugins/init.lua b/nvim/lua/plugins/init.lua index 30306e1..1a13eb4 100644 --- a/nvim/lua/plugins/init.lua +++ b/nvim/lua/plugins/init.lua @@ -1,5 +1,10 @@ return { { 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate' }, + { + 'L3MON4D3/LuaSnip', + tag = 'v2.*', + build = 'make install_jsregexp', + }, 'lewis6991/gitsigns.nvim', { 'nvim-telescope/telescope.nvim', @@ -9,28 +14,22 @@ return { { 'rose-pine/neovim', name = 'rose-pine' }, { 'catppuccin/nvim', name = 'catppuccin', priority = 1000 }, { 'tpope/vim-fugitive', name = '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' }, }, }, - { 'ray-x/lsp_signature.nvim', event = 'VeryLazy', opts = {}, - config = function(_, opts) require('lsp_signature').setup(opts) end }, - + { + 'ray-x/lsp_signature.nvim', + event = 'VeryLazy', + opts = {}, + config = function(_, opts) require('lsp_signature').setup(opts) end + }, + 'rcarriga/nvim-notify', + { + 'danymat/neogen', + dependencies = 'nvim-treesitter/nvim-treesitter', + config = true, + }, } diff --git a/nvim/lua/plugins/lsp/init.lua b/nvim/lua/plugins/lsp/init.lua new file mode 100644 index 0000000..721a826 --- /dev/null +++ b/nvim/lua/plugins/lsp/init.lua @@ -0,0 +1,88 @@ +--local lspconfig = require('lspconfig') +--local lsp_defaults = lspconfig.util.default_config +-- +--lsp_defaults.capabilities = vim.tbl_deep_extend( +-- 'force', +-- lsp_defaults.capabilities, +-- require('cmp_nvim_lsp').default_capabilities() +--) + +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = { buffer = event.buf } + vim.keymap.set('n', 'i', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', 'r', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set('n', 'f', 'lua vim.lsp.buf.format({async=true})', opts) + vim.keymap.set('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + vim.keymap.set('n', 'gl', 'lua vim.diagnostic.open_float()', opts) + vim.keymap.set('n', '[d', 'lua vim.diagnostic.goto_prev({float = {border = "rounded"}})', opts) + vim.keymap.set('n', ']d', 'lua vim.diagnostic.goto_next({float = {border = "rounded"}})', opts) + vim.keymap.set('n', 'vd', 'lua vim.diagnostic.open_float({border = "rounded"})', opts) + end +}) + + +local handlers = { + function(server) + require('lspconfig')[server].setup({}) + end, + pylsp = function() + require('lspconfig').pylsp.setup({ + settings = { + pylsp = { + plugins = { + pyflakes = { enabled = false }, + mccabe = { enabled = false }, + pycodestyle = { enabled = false }, + flake8 = { enabled = false }, + pylint = { enabled = false }, + autopep8 = { enabled = false }, + yapf = { enabled = true }, + }, + }, + }, + }) + end, + ruff_lsp = function() + require('lspconfig').ruff_lsp.setup({ + on_attach = function(client, bufnr) + client.server_capabilities.hoverProvider = false + client.server_capabilities.documentFormattingProver = false + end, + }) + end, +} + +return { + { + 'williamboman/mason.nvim', + config = function() + require('mason').setup({ + ui = { + border = 'rounded' + } + }) + require('mason-registry'):on('package:install:success', require('plugins.lsp.python').mason_post_install) + end + }, + { + 'williamboman/mason-lspconfig.nvim', + dependencies = { + 'rcarriga/nvim-notify', + }, + opts = { + handlers = handlers, + ensure_installed = { + 'lua_ls', 'clangd', 'pylsp', 'yamlls', 'esbonio', 'ruff_lsp', + }, + }, + }, + { 'neovim/nvim-lspconfig' }, +} diff --git a/nvim/lua/plugins/lsp/python.lua b/nvim/lua/plugins/lsp/python.lua new file mode 100644 index 0000000..bf2086e --- /dev/null +++ b/nvim/lua/plugins/lsp/python.lua @@ -0,0 +1,34 @@ +local M = {} +local notify = require('notify') + +M.mason_post_install = function(pkg) + --if pkg.name ~= 'python-lsp-server' then + -- return + --end + --local venv = vim.fn.stdpath('data') .. '/mason/packages/python-lsp-server/venv' + --local job = require('plenary.job') + --job:new({ + -- command = venv .. '/bin/pip', + -- args = { + -- 'install', + -- '-U', + -- '--disable-pip-version-check', + -- 'pylsp-mypy', + -- }, + -- cwd = venv, + -- env = { VIRTUAL_ENV = venv }, + -- on_exit = function() + -- notify('Finished installing pylsp modules.') + -- end, + -- on_start = function() + -- notify('Installing pylsp modules...') + -- end, + --}):start() +end + +M.ruff = function() + local config = {} + return config +end + +return M