Allow installing a subset of language support

This commit is contained in:
ViViDboarder 2023-05-22 12:13:45 -07:00
parent 37714095b4
commit c56293489b
3 changed files with 126 additions and 57 deletions

View File

@ -3,8 +3,41 @@
# Clear explicit PYTHONPATH since this gets confused between py2 and py3 # Clear explicit PYTHONPATH since this gets confused between py2 and py3
export PYTHONPATH="" export PYTHONPATH=""
# Languages to install helpers for
declare -a VIM_LANGS
# Read flag for ignore missing and args for languages
while [[ $# -gt 0 ]]; do
case "$1" in
--ignore-missing)
VIM_IGNORE_MISSING=true
;;
*)
VIM_LANGS+=("$1")
echo "Read arg $1"
;;
esac
shift
done
echo "Langs! ${VIM_LANGS[*]}"
function want_lang() {
if [ "${#VIM_LANGS[@]}" -eq 0 ]; then
return 0
fi
for l in "${VIM_LANGS[@]}"; do
if [ "$l" == "$1" ]; then
return 0
fi
done
return 1
}
# Ignore failed installs # Ignore failed installs
if [ -z "$IGNORE_MISSING" ]; then if [ -z "$VIM_IGNORE_MISSING" ]; then
set -e set -e
else else
set +e set +e
@ -31,23 +64,31 @@ function install_language_servers() {
echo "### Installing language servers..." echo "### Installing language servers..."
# bash # bash
maybe_run npm install -g bash-language-server if want_lang bash ;then
maybe_run npm install -g bash-language-server
fi
# Kotlin # Kotlin
# https://github.com/fwcd/kotlin-language-server/blob/master/BUILDING.md # https://github.com/fwcd/kotlin-language-server/blob/master/BUILDING.md
# Python # Python
maybe_run pip install --user --upgrade python-language-server if want_lang python ;then
maybe_run pip3 install --user --upgrade python-language-server maybe_run pip install --user --upgrade python-language-server
maybe_run pip install --user "python-lsp-server[all]" || echo "WARNING: python-lsp-server is py3 only" maybe_run pip3 install --user --upgrade python-language-server
maybe_run pip3 install --user "python-lsp-server[all]" maybe_run pip install --user "python-lsp-server[all]" || echo "WARNING: python-lsp-server is py3 only"
maybe_run npm install -g pyright maybe_run pip3 install --user "python-lsp-server[all]"
maybe_run npm install -g pyright
fi
# Rust # Rust
maybe_run rustup component add rls rustfmt rust-analysis rust-src clippy rustfmt if want_lang rust ;then
maybe_run rustup component add rls rustfmt rust-analysis rust-src clippy rustfmt
fi
# Go # Go
maybe_run env GO111MODULE=on go install golang.org/x/tools/gopls@latest if want_lang go ;then
maybe_run env GO111MODULE=on go install golang.org/x/tools/gopls@latest
fi
echo "" echo ""
} }
@ -57,61 +98,79 @@ function install_linters() {
echo "### Installing linters..." echo "### Installing linters..."
# Python # Python
maybe_run pip install --user --upgrade flake8 if want_lang python ;then
maybe_run pip install --user --upgrade mypy || echo "WARNING: mypy is py3 only" maybe_run pip install --user --upgrade flake8
maybe_run pip3 install --user --upgrade flake8 mypy maybe_run pip install --user --upgrade mypy || echo "WARNING: mypy is py3 only"
maybe_run pip3 install --user --upgrade flake8 mypy
fi
# CSS # CSS
maybe_run npm install -g csslint if want_lang css || want_lang web ;then
maybe_run npm install -g csslint
fi
# Vim # Vim
maybe_run pip install --user --upgrade vim-vint if want_lang vim || want_lang neovim ;then
maybe_run pip3 install --user --upgrade vim-vint maybe_run pip install --user --upgrade vim-vint
maybe_run pip3 install --user --upgrade vim-vint
fi
# YAML # YAML
maybe_run pip install --user --upgrade yamllint if want_lang yaml ;then
maybe_run pip3 install --user --upgrade yamllint maybe_run pip install --user --upgrade yamllint
maybe_run pip3 install --user --upgrade yamllint
fi
# Text / Markdown # Text / Markdown
maybe_run npm install -g alex write-good if want_lang text || want_lang prose ;then
maybe_run pip install --user --upgrade proselint maybe_run npm install -g alex write-good
maybe_run pip3 install --user --upgrade proselint maybe_run pip install --user --upgrade proselint
maybe_run pip3 install --user --upgrade proselint
fi
# Makefile # Makefile
# maybe_run go install github.com/mrtazz/checkmake@latest # maybe_run go install github.com/mrtazz/checkmake@latest
# Go # Go
maybe_run release-gitter --git-url "https://github.com/golangci/golangci-lint" \ if want_lang go ;then
--map-system Windows=windows --map-system Linux=linux --map-system Darwin=darwin \ maybe_run release-gitter --git-url "https://github.com/golangci/golangci-lint" \
--map-arch x86_64=amd64 --map-arch armv7l=armv7 --map-arch aarch64=arm64 \ --map-system Windows=windows --map-system Linux=linux --map-system Darwin=darwin \
--extract-files golangci-lint \ --map-arch x86_64=amd64 --map-arch armv7l=armv7 --map-arch aarch64=arm64 \
--exec "'chmod +x ~/bin/golangci-lint'" \ --extract-files golangci-lint \
"golangci-lint-{version}-{system}-{arch}.tar.gz" ~/bin --exec "'chmod +x ~/bin/golangci-lint'" \
"golangci-lint-{version}-{system}-{arch}.tar.gz" ~/bin
fi
# Lua # Lua
maybe_run luarocks --local install luacheck if want_lang lua || want_lang neovim ;then
maybe_run luarocks --local install luacheck
fi
# Docker # Docker
hadolint_arm64=arm64 if want_lang docker ;then
if [ "$(uname -s)" == "Darwin" ]; then hadolint_arm64=arm64
hadolint_arm64=x86_64 if [ "$(uname -s)" == "Darwin" ]; then
hadolint_arm64=x86_64
fi
maybe_run release-gitter --git-url "https://github.com/hadolint/hadolint" \
--map-arch arm64=$hadolint_arm64 \
--exec "'mv ~/bin/{} ~/bin/hadolint && chmod +x ~/bin/hadolint'" \
"hadolint-{system}-{arch}" ~/bin
fi fi
maybe_run release-gitter --git-url "https://github.com/hadolint/hadolint" \
--map-arch arm64=$hadolint_arm64 \
--exec "'mv ~/bin/{} ~/bin/hadolint && chmod +x ~/bin/hadolint'" \
"hadolint-{system}-{arch}" ~/bin
# Terraform # Terraform
maybe_run release-gitter --git-url "https://github.com/aquasecurity/tfsec" \ if want_lang terraform ;then
--map-arch x86_64=amd64 \ maybe_run release-gitter --git-url "https://github.com/aquasecurity/tfsec" \
--map-system Linux=linux --map-system Darwin=darwin \ --map-arch x86_64=amd64 \
--exec "'mv ~/bin/{} ~/bin/tfsec && chmod +x ~/bin/tfsec'" \ --map-system Linux=linux --map-system Darwin=darwin \
"tfsec-{system}-{arch}" ~/bin --exec "'mv ~/bin/{} ~/bin/tfsec && chmod +x ~/bin/tfsec'" \
maybe_run release-gitter --git-url "https://github.com/terraform-linters/tflint" \ "tfsec-{system}-{arch}" ~/bin
--map-arch x86_64=amd64 \ maybe_run release-gitter --git-url "https://github.com/terraform-linters/tflint" \
--map-system Linux=linux --map-system Darwin=darwin \ --map-arch x86_64=amd64 \
--extract-all --exec "'chmod +x ~/bin/tflint'" \ --map-system Linux=linux --map-system Darwin=darwin \
"tflint_{system}_{arch}.zip" ~/bin --extract-all --exec "'chmod +x ~/bin/tflint'" \
"tflint_{system}_{arch}.zip" ~/bin
fi
echo "" echo ""
} }
@ -119,24 +178,33 @@ function install_linters() {
## Fixers ## Fixers
function install_fixers() { function install_fixers() {
echo "### Installing fixers..." echo "### Installing fixers..."
# CSS/JS/HTML/JSON/YAML/Markdown/and more! # CSS/JS/HTML/JSON/YAML/Markdown/and more!
maybe_run npm install -g prettier if want_lang javascript || want_lang html || want_lang css || want_lang web || want_lang json ;then
maybe_run npm install -g prettier
fi
# Python # Python
maybe_run pip install --user --upgrade "'autopep8<1.7.0'" reorder-python-imports if want_lang python ;then
maybe_run pip install --user --upgrade autopep8 reorder-python-imports black pyls-black python-lsp-black pyls-isort pyls-mypy || echo "WARNING: black is py3 only" maybe_run pip install --user --upgrade "'autopep8<1.7.0'" reorder-python-imports
maybe_run pip3 install --user --upgrade black pyls-black python-lsp-black pyls-isort pyls-mypy autopep8 reorder-python-imports maybe_run pip install --user --upgrade autopep8 reorder-python-imports black pyls-black python-lsp-black pyls-isort pyls-mypy || echo "WARNING: black is py3 only"
maybe_run pip3 install --user --upgrade black pyls-black python-lsp-black pyls-isort pyls-mypy autopep8 reorder-python-imports
fi
# Rust # Rust
maybe_run rustup component add rustfmt if want_lang rust ;then
maybe_run rustup component add rustfmt
fi
# Lua # Lua
if ! release-gitter --git-url "https://github.com/JohnnyMorganz/StyLua" \ if want_lang lua || want_lang neovim ;then
--map-arch arm64=aarch64 \ if ! release-gitter --git-url "https://github.com/JohnnyMorganz/StyLua" \
--map-system Windows=windows --map-system Linux=linux --map-system Darwin=macos \ --map-arch arm64=aarch64 \
--extract-all --exec "chmod +x ~/bin/stylua" \ --map-system Windows=windows --map-system Linux=linux --map-system Darwin=macos \
"stylua-{system}-{arch}.zip" ~/bin ; then --extract-all --exec "chmod +x ~/bin/stylua" \
maybe_run cargo install stylua "stylua-{system}-{arch}.zip" ~/bin ; then
maybe_run cargo install stylua
fi
fi fi
echo "" echo ""

View File

@ -293,7 +293,7 @@ use({
[">=0.5.0"] = "a189323454d1215c682c7ad7db3e6739d26339c4", [">=0.5.0"] = "a189323454d1215c682c7ad7db3e6739d26339c4",
}), }),
config = function() config = function()
require("plugins.treesitter").setup() utils.require_with_local("plugins.treesitter").setup()
end, end,
}) })
use({ use({

View File

@ -80,11 +80,12 @@ end
-- Require a package and a "_local" suffixed one -- Require a package and a "_local" suffixed one
function M.require_with_local(name) function M.require_with_local(name)
-- TODO: Decide if local should completely override the versioned module -- Local should completely override the versioned module
-- In that case, the local file would probably start with a `require` for the -- In that case, the local file would probably start with a `require` for the
-- non-local version. This would allow more control but at the cost of a bit -- non-local version. This would allow more control but at the cost of a bit
-- of boiler plate -- of boiler plate
local rmod = require(name) local rmod = require(name)
local lmod = M.maybe_require(name .. "_local") local lmod = M.maybe_require(name .. "_local")
if lmod ~= nil then if lmod ~= nil then
return lmod return lmod