#!/bin/sh -



# The following commands control vs code's extension manager: 
# Explanation 
# code --extensions-dir <dir>
#     Set the root path for extensions.
# code --list-extensions
#     List the installed extensions.
# code --show-versions
#     Show versions of installed extensions, when using --list-extension.
# code --install-extension (<extension-id> | <extension-vsix-path>)
#     Installs an extension.
# code --uninstall-extension (<extension-id> | <extension-vsix-path>)
#     Uninstalls an extension.
# code --enable-proposed-api (<extension-id>)
#     Enables proposed API features for extensions. 
#     Can receive one or more extension IDs to enable individually.
# The extension-id is always name of the provider dot name of the extension.
# I feel better solved with java: domain.
# to update the version just
# code --force --install-extension ms-vscode.cpptools


show_help()
{
    cat <<EOF
Install and update VS Code / VSCodium extensions for the invoking user.

Usage:
  $(basename "$0") [editor] [options]

Editor:
  code*       use a VS Code variant
  codium*     use a VSCodium variant

Options:
  --help
      show this help

  --node-options="OPTIONS"
      pass options to embedded Node.js runtime via NODE_OPTIONS as e. g. 
      "--trace-deprecation --trace-warnings --inspect"

Examples:
  $(basename "$0")
  $(basename "$0") codium
  $(basename "$0") codium --node-options="--trace-deprecation"
EOF
}

# default if not given explicitly as a parameter 
codeEditor="code"
node_options=""

while [ $# -gt 0 ]; do
  case "$1" in
    --help)
      show_help
      exit 0
      ;;

    --node-options=*)
      node_options="${1#*=}"
      ;;

    code*|codium*)
      codeEditor="$1"
      ;;

    -*)
      echo "Unknown option '$1'; try '$0 --help'."
      exit 1
      ;;

    *)
      echo "Unexpected argument '$1'; try '$0 --help'."
      exit 1
      ;;
    esac
    shift
done
# Here, codeEditor and node-options are set. 

# esac
echo "Installing/updating extensions for '$codeEditor'..."


# In the list 'extensions': 
# The label VSX means hat the according extension is also available on VSX 
# so without any problem can be installed by codium also. 



extensions=(
#echo "install from markdown to lisp" 
  # Textual: markdown and friends 
  "DavidAnson.vscode-markdownlint" # VSX
  "joffreykern.markdown-toc"
  "yzhang.markdown-all-in-one" # VSX
  "shd101wyy.markdown-preview-enhanced" # VSX
# "jrieken.md-navigate"
  "alanwalk.markdown-navigation"
  "tchayen.markdown-links" # VSX
  # ltex in the course of latex 
# plantuml 


# ltex in the course of latex 
# plantuml 
"myml.vscode-markdown-plantuml-preview"
#"well-ar.plantuml" # seems not to work 
"pomdtr.markdown-kroki" # VSX
#"yog.yog-plantuml-highlight" # seems not to work for me
#"jebbs.plantuml" # seems to do highlighting, preview, 
# but via server: security gap 
# Error: plantuml.jar file not found: ""
# Please download plantuml.jar from https://plantuml.com/download.  
# If you are using VSCode or coc.nvim, 
# then please set the setting "markdown-preview-enhanced.plantumlJarPath" 
# to the absolute path of plantuml.jar file.
# If you don't want to use plantuml.jar, 
# then you can use the online plantuml server 
# by setting the setting "markdown-preview-enhanced.plantumlServer" 
# to the URL of the online plantuml server, 
# for example: https://kroki.io/plantuml/svg/
# https://shd101wyy.github.io/markdown-preview-enhanced/#/vscode-installation
# uses a lot of server work. 
# This is an item in the backlog 
# https://plantuml.com/starting: how to run locally with docker 
# previewer must be set back 
#"yzane.markdown-pdf  converts to pdf but also to html (png and jpg irrelevant)

# Velocity Template Language (VTL)
"luqimin.velocity"

# antlr
"mike-lischke.vscode-antlr4" # VSX
"ncthbrt.antlr4"

# lex/yacc and flex/bison
"daohong-emilio.yash"

# xml
"redhat.vscode-xml" # VSX
"dotjoshjohnson.xml" # VSX


# json
"eriklynd.json-tools"



# git
"eamodio.gitlens" # VSX
# github
"github.vscode-github-actions" # VSX

# related with maven (mostly java) 
# vulnerabilities
#"redhat.fabric8-analytics"

# python and jupyter notebook 
#"Gimly81.matlab"
#"ms-python.python"
#"bmewburn.vscode-intelephense-client" # php
"ms-python.python" # VSX
"ms-pyright.pyright" # VSX
"ms-python.pylint" # VSX
"ms-python.debugpy" # VSX
"ms-toolsai.jupyter" # VSX


# to start vs code on the current directory just type
# code .
# this will start in the background automatically. 



# C and C++
#"ms-vscode.cpptools-extension-pack"

# makefile
# seem to set JAVA_HOME
#"ms-vscode.makefile-tools"
#"carlos-algms.make-task-provider"

# for docker 
#"ms-azuretools.vscode-docker"
"dunstontc.vscode-docker-syntax"
# hidden dependencies 
#"ms-vscode-remote.remote-containers"




# octave: IDE and run
"leafvmaple.octave"
"toasty-technologies.octave"
"lucasfa.octaveexecution" # VSX

# matlab: IDE and run (partially interactively)
"mathworks.language-matlab" # IDE
"bramvanbilsen.matlab-code-run"
"shinyypig.matlab-in-vscode"
"apommel.matlab-interactive-terminal"

# julia 
"julialang.language-julia" # VSX

# lisp
"mattn.lisp"

# no perl because this is in latex and friends 


#echo "install from java and groovy" 

# groovy
"mellowmarshmallow.groovy"
# during uninstall: FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal
"nicolasvuillamy.vscode-groovy-lint" # VSX
"argylewolflabs.vscode-groovy"
"marlon407.code-groovy"
"dontshavetheyak.groovy-guru" # VSX

# java

"redhat.java" # VSX
"vscjava.vscode-java-debug" # VSX
"vscjava.vscode-java-test" # VSX
"vscjava.vscode-maven" # VSX
"vscjava.vscode-java-dependency" # VSX
# installs the above with more than this, e.g. copilot. 
#"vscjava.vscode-java-pack"


"wmanth.jar-viewer" # VSX

#"cracrayol.java-pmd" # not found


# alternative test runner: 
# "javatest.java-test"


"shengchen.vscode-checkstyle"
"chuckjonas.apex-pmd"
# does not install: https://community.sonarsource.com/t/having-trouble-installing-with-vscode-taking-an-age/29605/4
#"sonarsource.sonarlint-vscode"

"tintinweb.vscode-decompiler" # VSX
"dgileadi.java-decompiler"


"ryanluker.vscode-coverage-gutters" # VSX

#"ithildir.java-properties" # not found


# Ada and Sparc 
"adacore.ada" # VSX
"maximreznik.jupyter-ada-kernel"



#echo "install misc" 

# Web development 
"ritwickdey.liveserver" # VSX
"ecmel.vscode-html-css" # VSX

# emails
"tomashubelbauer.email-viewer"

# misc
"trond-snekvik.simple-rst" # VSX
"maarti.jenkins-doc"
# causes [error] CodeExpectedError: Unable to write to User Settings because print.browser.useAlternate is not a registered configuration.
#"pdconsec.vscode-print"
"oliverkovacs.word-count"



# something like that i would like for tikz 
"corschenzi.mermaid-graphical-editor"

# javascript: VS code extensions 
"dbaeumer.vscode-eslint" # VSX
"ms-vscode.extension-test-runner"


# rust 
"rust-lang.rust-analyzer" # VSX
"fill-labs.dependi" # VSX
"tamasfe.even-better-toml" # VSX
"jscearcy.rust-doc-viewer" # VSX
"panicbit.cargo"
# avoid package which may contain more. 
#"zerotaskx.rust-extension-pack"


# not in rust-extension-pack
"dustypomerleau.rust-syntax"

#"rust-lang.rust-analyzer"

#"1yib.rust-bundle"
# contains: 
# - rust-analyzer
# - crates (outdated)
# - rust syntax 
# pack contains outdated crates. 
# Thus replaced pack by individual extensions 
#"swellaby.rust-pack
# contains 
# - rust-analyzer
# - crates (outdated)
# - even better toml 

#"tamasfe.even-better-toml"
#"rust-lang.rust-analyzer"
# dependi also for python, go and others 
#"fill-labs.dependi"


# VHDL
"rjyoung.vscode-modern-vhdl-support"
)

for ext in "${extensions[@]}"; do
  # --disable-gpu, to save load on X-Server 
  NODE_OPTIONS=$node_options "$codeEditor" --force --install-extension "$ext" --disable-gpu
done


source ./instVScode4tex.sh $@

echo "...Installed/update extensions for '$codeEditor'."


