From 23195e00be12891570de17675b110d70c9acfbe1 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Wed, 10 Aug 2022 14:27:05 +0200 Subject: [PATCH] Lsp support for bash, python, c and puppet --- .local/bin/puppet-fix | 16 ++++++++++++ .local/bin/puppet-languageserver | 3 +++ dotfiles/.config/nvim/init.vim | 44 ++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 16 deletions(-) create mode 100755 .local/bin/puppet-fix create mode 100755 .local/bin/puppet-languageserver diff --git a/.local/bin/puppet-fix b/.local/bin/puppet-fix new file mode 100755 index 0000000..bae1925 --- /dev/null +++ b/.local/bin/puppet-fix @@ -0,0 +1,16 @@ +#!/bin/bash + +input=${1} +if [[ ${input} == "" ]]; then + input="-" +elif ! [[ -f ${input} ]]; then + echo "Usage: ${0} [puppet file]" + exit 1 +fi + +tempfile=$(mktemp) +cat "${input}" > "${tempfile}" +puppet-lint --fix "${tempfile}" > /dev/null 2>&1 +#puppet-lint --log-format "%{filename}:%{line}:%{column}: %{kind}: %{message}. [%{check}]" ${tempfile} | grep -v warning: +cat "${tempfile}" +rm "${tempfile}" diff --git a/.local/bin/puppet-languageserver b/.local/bin/puppet-languageserver new file mode 100755 index 0000000..676feb6 --- /dev/null +++ b/.local/bin/puppet-languageserver @@ -0,0 +1,3 @@ +#!/bin/bash +cd /home/micke/sources/puppet-editor-services/ +ruby puppet-languageserver ${@} diff --git a/dotfiles/.config/nvim/init.vim b/dotfiles/.config/nvim/init.vim index 3eaf782..bd019c7 100644 --- a/dotfiles/.config/nvim/init.vim +++ b/dotfiles/.config/nvim/init.vim @@ -13,6 +13,9 @@ Plug 'nvim-lua/plenary.nvim' " Dependecy for telescope Plug 'nvim-lua/telescope.nvim' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " Dependecy for telescope Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' } +Plug 'rodjek/vim-puppet' +Plug 'mrk21/yaml-vim' " For hieradata +Plug 'vim-ruby/vim-ruby' " For Facts, Ruby functions, and custom providers Plug 'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim' call plug#end() @@ -135,7 +138,6 @@ local on_attach = function(client, bufnr) local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end - end -- set up completion @@ -194,7 +196,7 @@ local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protoco -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches -local servers = { 'pyright', 'pylsp', 'bashls', 'clangd'} +local servers = { 'pylsp', 'clangd', 'puppet', 'bashls'} for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup { capabilities = capabilities, @@ -205,18 +207,28 @@ for _, lsp in ipairs(servers) do } end - --- set up formatting --- require "lspconfig".efm.setup { --- init_options = {documentFormatting = true}, --- settings = { --- rootMarkers = {".git/"}, --- languages = { --- python = { --- {formatCommand = "yapf --quiet", formatStdin = true}, --- {formatCommand = "isort -d -", formatStdin = true} --- } --- } --- } --- } +nvim_lsp["efm"].setup { + capabilities = capabilities, + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + }, + init_options = {documentFormatting = true}, + filetypes = { 'sh', 'puppet'}, + settings = { + rootMarkers = {".git/"}, + languages = { + puppet = { + { + formatCommand = 'puppet-fix', formatStdin = true, lintCommand = 'puppet-lint --log-format "%{filename}:%{line}:%{column}: %{kind}: %{message}. [%{check}]"', lintSource = 'puppet-lint', lintFormats= {'%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m'} + } + }, + sh = { + { + formatCommand = "shfmt -i 2", formatStdin = true, lintCommand = 'shellcheck -f gcc -x', lintSource = 'shellcheck', lintFormats= {'%f:%l:%c: %trror: %m', '%f:%l:%c: %tarning: %m', '%f:%l:%c: %tote: %m'} + } + } + } + } +} EOF