gen-erlang-ls-config.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. set -eou pipefail
  3. shopt -s nullglob
  4. # Our fork of rebar3 copies those directories from apps to
  5. # _build/default/lib rather than just making a symlink. Now erlang_ls
  6. # sees the same module twice and if you're just navigating through the
  7. # call stack you accidentally end up editing files in
  8. # _build/default/lib rather than apps
  9. usage() {
  10. cat <<EOF
  11. Generate configuration for erlang_ls
  12. USAGE:
  13. $(basename "${0}") [-t TEMPLATE_FILE]
  14. OPTIONS:
  15. -h Get this help
  16. -t Path to the YAML file containing additional options for erlang ls
  17. that will be added to the generated file
  18. EOF
  19. exit 1
  20. }
  21. default_template()
  22. {
  23. cat <<EOF
  24. diagnostics:
  25. enabled:
  26. - bound_var_in_pattern
  27. - elvis
  28. - unused_includes
  29. - unused_macros
  30. - crossref
  31. # - dialyzer
  32. - compiler
  33. disabled:
  34. - dialyzer
  35. # - crossref
  36. # - compiler
  37. lenses:
  38. disabled:
  39. # - show-behaviour-usages
  40. # - ct-run-test
  41. - server-info
  42. enable:
  43. - show-behaviour-usages
  44. - ct-run-test
  45. macros:
  46. - name: EMQX_RELEASE_EDITION
  47. value: ee
  48. code_reload:
  49. node: emqx@127.0.0.1
  50. formatting:
  51. formatter: erlfmt
  52. EOF
  53. }
  54. template="$(default_template)"
  55. while getopts "ht:" opt; do
  56. case "${opt}" in
  57. h) usage ;;
  58. t) template=$(cat "${OPTARG}") ;;
  59. *) ;;
  60. esac
  61. done
  62. deps_dirs()
  63. {
  64. local app
  65. for dir in _build/default/lib/*; do
  66. app=$(basename "${dir}")
  67. ## Only add applications that are not part of EMQX umbrella project:
  68. [ -d "apps/${app}" ] ||
  69. echo " - \"${dir}\""
  70. done
  71. }
  72. find_plt() {
  73. for plt in emqx_dialyzer_*_plt; do
  74. cat <<EOF
  75. plt_path:
  76. - "${plt}"
  77. EOF
  78. break
  79. done
  80. }
  81. cat <<EOF
  82. apps_dirs:
  83. - "apps/*"
  84. deps_dirs:
  85. $(deps_dirs)
  86. - "_build/test/lib/bbmustache"
  87. - "_build/test/lib/meck"
  88. - "_build/test/lib/proper"
  89. - "_build/test/lib/erl_csv"
  90. include_dirs:
  91. - "apps/"
  92. - "apps/*/include"
  93. - "_build/default/lib/typerefl/include"
  94. - "_build/default/lib/"
  95. - "_build/default/lib/*/include"
  96. - "_build/test/lib/bbmustache"
  97. - "_build/test/lib/meck"
  98. - "_build/test/lib/proper"
  99. exclude_unused_includes:
  100. - "typerefl/include/types.hrl"
  101. - "logger.hrl"
  102. $(find_plt)
  103. ${template}
  104. EOF