From c56293489bd39dd48ace21aeccebbbc8223e77be Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Mon, 22 May 2023 12:13:45 -0700 Subject: [PATCH] Allow installing a subset of language support --- install-language-servers.sh | 178 +++++++++++++++++++++++++----------- neovim/lua/plugins.lua | 2 +- neovim/lua/utils.lua | 3 +- 3 files changed, 126 insertions(+), 57 deletions(-) diff --git a/install-language-servers.sh b/install-language-servers.sh index 9e27c24..a575c92 100755 --- a/install-language-servers.sh +++ b/install-language-servers.sh @@ -3,8 +3,41 @@ # Clear explicit PYTHONPATH since this gets confused between py2 and py3 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 -if [ -z "$IGNORE_MISSING" ]; then +if [ -z "$VIM_IGNORE_MISSING" ]; then set -e else set +e @@ -31,23 +64,31 @@ function install_language_servers() { echo "### Installing language servers..." # bash - maybe_run npm install -g bash-language-server + if want_lang bash ;then + maybe_run npm install -g bash-language-server + fi # Kotlin # https://github.com/fwcd/kotlin-language-server/blob/master/BUILDING.md # Python - maybe_run pip install --user --upgrade python-language-server - maybe_run pip3 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 "python-lsp-server[all]" - maybe_run npm install -g pyright + if want_lang python ;then + maybe_run pip install --user --upgrade python-language-server + maybe_run pip3 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 "python-lsp-server[all]" + maybe_run npm install -g pyright + fi # 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 - 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 "" } @@ -57,61 +98,79 @@ function install_linters() { echo "### Installing linters..." # Python - maybe_run pip install --user --upgrade flake8 - maybe_run pip install --user --upgrade mypy || echo "WARNING: mypy is py3 only" - maybe_run pip3 install --user --upgrade flake8 mypy + if want_lang python ;then + maybe_run pip install --user --upgrade flake8 + maybe_run pip install --user --upgrade mypy || echo "WARNING: mypy is py3 only" + maybe_run pip3 install --user --upgrade flake8 mypy + fi # CSS - maybe_run npm install -g csslint + if want_lang css || want_lang web ;then + maybe_run npm install -g csslint + fi # Vim - maybe_run pip install --user --upgrade vim-vint - maybe_run pip3 install --user --upgrade vim-vint + if want_lang vim || want_lang neovim ;then + maybe_run pip install --user --upgrade vim-vint + maybe_run pip3 install --user --upgrade vim-vint + fi # YAML - maybe_run pip install --user --upgrade yamllint - maybe_run pip3 install --user --upgrade yamllint + if want_lang yaml ;then + maybe_run pip install --user --upgrade yamllint + maybe_run pip3 install --user --upgrade yamllint + fi # Text / Markdown - maybe_run npm install -g alex write-good - maybe_run pip install --user --upgrade proselint - maybe_run pip3 install --user --upgrade proselint + if want_lang text || want_lang prose ;then + maybe_run npm install -g alex write-good + maybe_run pip install --user --upgrade proselint + maybe_run pip3 install --user --upgrade proselint + fi # Makefile # maybe_run go install github.com/mrtazz/checkmake@latest # Go - maybe_run release-gitter --git-url "https://github.com/golangci/golangci-lint" \ - --map-system Windows=windows --map-system Linux=linux --map-system Darwin=darwin \ - --map-arch x86_64=amd64 --map-arch armv7l=armv7 --map-arch aarch64=arm64 \ - --extract-files golangci-lint \ - --exec "'chmod +x ~/bin/golangci-lint'" \ - "golangci-lint-{version}-{system}-{arch}.tar.gz" ~/bin + if want_lang go ;then + maybe_run release-gitter --git-url "https://github.com/golangci/golangci-lint" \ + --map-system Windows=windows --map-system Linux=linux --map-system Darwin=darwin \ + --map-arch x86_64=amd64 --map-arch armv7l=armv7 --map-arch aarch64=arm64 \ + --extract-files golangci-lint \ + --exec "'chmod +x ~/bin/golangci-lint'" \ + "golangci-lint-{version}-{system}-{arch}.tar.gz" ~/bin + fi # Lua - maybe_run luarocks --local install luacheck + if want_lang lua || want_lang neovim ;then + maybe_run luarocks --local install luacheck + fi # Docker - hadolint_arm64=arm64 - if [ "$(uname -s)" == "Darwin" ]; then - hadolint_arm64=x86_64 + if want_lang docker ;then + hadolint_arm64=arm64 + 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 - 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 - maybe_run release-gitter --git-url "https://github.com/aquasecurity/tfsec" \ - --map-arch x86_64=amd64 \ - --map-system Linux=linux --map-system Darwin=darwin \ - --exec "'mv ~/bin/{} ~/bin/tfsec && chmod +x ~/bin/tfsec'" \ - "tfsec-{system}-{arch}" ~/bin - maybe_run release-gitter --git-url "https://github.com/terraform-linters/tflint" \ - --map-arch x86_64=amd64 \ - --map-system Linux=linux --map-system Darwin=darwin \ - --extract-all --exec "'chmod +x ~/bin/tflint'" \ - "tflint_{system}_{arch}.zip" ~/bin + if want_lang terraform ;then + maybe_run release-gitter --git-url "https://github.com/aquasecurity/tfsec" \ + --map-arch x86_64=amd64 \ + --map-system Linux=linux --map-system Darwin=darwin \ + --exec "'mv ~/bin/{} ~/bin/tfsec && chmod +x ~/bin/tfsec'" \ + "tfsec-{system}-{arch}" ~/bin + maybe_run release-gitter --git-url "https://github.com/terraform-linters/tflint" \ + --map-arch x86_64=amd64 \ + --map-system Linux=linux --map-system Darwin=darwin \ + --extract-all --exec "'chmod +x ~/bin/tflint'" \ + "tflint_{system}_{arch}.zip" ~/bin + fi echo "" } @@ -119,24 +178,33 @@ function install_linters() { ## Fixers function install_fixers() { echo "### Installing fixers..." + # 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 - maybe_run pip install --user --upgrade "'autopep8<1.7.0'" 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 + if want_lang python ;then + maybe_run pip install --user --upgrade "'autopep8<1.7.0'" 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 - maybe_run rustup component add rustfmt + if want_lang rust ;then + maybe_run rustup component add rustfmt + fi # Lua - if ! release-gitter --git-url "https://github.com/JohnnyMorganz/StyLua" \ - --map-arch arm64=aarch64 \ - --map-system Windows=windows --map-system Linux=linux --map-system Darwin=macos \ - --extract-all --exec "chmod +x ~/bin/stylua" \ - "stylua-{system}-{arch}.zip" ~/bin ; then - maybe_run cargo install stylua + if want_lang lua || want_lang neovim ;then + if ! release-gitter --git-url "https://github.com/JohnnyMorganz/StyLua" \ + --map-arch arm64=aarch64 \ + --map-system Windows=windows --map-system Linux=linux --map-system Darwin=macos \ + --extract-all --exec "chmod +x ~/bin/stylua" \ + "stylua-{system}-{arch}.zip" ~/bin ; then + maybe_run cargo install stylua + fi fi echo "" diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua index 474999a..f41f0a9 100644 --- a/neovim/lua/plugins.lua +++ b/neovim/lua/plugins.lua @@ -293,7 +293,7 @@ use({ [">=0.5.0"] = "a189323454d1215c682c7ad7db3e6739d26339c4", }), config = function() - require("plugins.treesitter").setup() + utils.require_with_local("plugins.treesitter").setup() end, }) use({ diff --git a/neovim/lua/utils.lua b/neovim/lua/utils.lua index 21de75b..69ca566 100644 --- a/neovim/lua/utils.lua +++ b/neovim/lua/utils.lua @@ -80,11 +80,12 @@ end -- Require a package and a "_local" suffixed one 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 -- non-local version. This would allow more control but at the cost of a bit -- of boiler plate local rmod = require(name) + local lmod = M.maybe_require(name .. "_local") if lmod ~= nil then return lmod