PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/assets/emacs/emacs.d/elpa/lsp-mode-20220702.1309/lsp-ansible.el

https://github.com/ereslibre/dotfiles
Emacs Lisp | 215 lines | 162 code | 33 blank | 20 comment | 10 complexity | ea18560e79c99c890d9a130dfbfad883 MD5 | raw file
  1. ;;; lsp-ansible.el --- lsp-mode ansible integration -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2022 emacs-lsp maintainers
  3. ;; Author: lsp-mode maintainers
  4. ;; Keywords: lsp, yaml, ansible
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; LSP Client for the Ansible Language
  17. ;;; Code:
  18. (require 'lsp-mode)
  19. ;;; Ansible
  20. (defgroup lsp-ansible nil
  21. "Settings for the Ansible Language Server."
  22. :group 'lsp-mode
  23. :link '(url-link "https://github.com/ansible/ansible-language-server")
  24. :package-version '(lsp-mode . "8.0.1"))
  25. (defcustom lsp-ansible-language-server-command
  26. '("ansible-language-server" "--stdio")
  27. "The command that starts the ansible language server."
  28. :type '(repeat :tag "List of string values" string)
  29. :group 'lsp-ansible
  30. :package-version '(lsp-mode . "8.0.1"))
  31. (defcustom lsp-ansible-ansible-path "ansible"
  32. "Path to the ansible executable.
  33. $PATH is searched for the executable."
  34. :type 'string
  35. :group 'lsp-ansible
  36. :package-version '(lsp-mode . "8.0.1"))
  37. (defcustom lsp-ansible-use-fully-qualified-collection-names t
  38. "Toggles use of fully qualified collection names when inserting a module name.
  39. Disabling it will only use FQCNs when necessary, that is when the collection is
  40. not configured for the task."
  41. :type 'boolean
  42. :group 'lsp-ansible
  43. :package-version '(lsp-mode . "8.0.1"))
  44. (defcustom lsp-ansible-ansible-lint-arguments ""
  45. "Optional command line arguments to be appended to ansible-lint invocation.
  46. See ansible-lint documentation."
  47. :type 'string
  48. :group 'lsp-ansible
  49. :package-version '(lsp-mode . "8.0.1"))
  50. (defcustom lsp-ansible-ansible-lint-enabled t
  51. "Enables/disables use of ansible-lint."
  52. :type 'boolean
  53. :group 'lsp-ansible
  54. :package-version '(lsp-mode . "8.0.1"))
  55. (defcustom lsp-ansible-ansible-lint-path "ansible-lint"
  56. "Path to the ansible-lint executable.
  57. $PATH is searched for the executable."
  58. :type 'string
  59. :group 'lsp-ansible
  60. :package-version '(lsp-mode . "8.0.1"))
  61. (defcustom lsp-ansible-completion-provide-redirect-modules t
  62. "Toggle redirected module provider when completing modules."
  63. :type 'boolean
  64. :group 'lsp-ansible
  65. :package-version '(lsp-mode . "8.0.1"))
  66. (defcustom lsp-ansible-completion-provide-module-option-aliases t
  67. "Toggle alias provider when completing module options."
  68. :type 'boolean
  69. :group 'lsp-ansible
  70. :package-version '(lsp-mode . "8.0.1"))
  71. (defcustom lsp-ansible-execution-environment-container-engine "auto"
  72. "The container engine to be used while running with execution environment.
  73. Valid values are auto, podman and docker. For auto it will look for podman then
  74. docker."
  75. :type '(choice (const "auto")
  76. (const "podman")
  77. (const "docker"))
  78. :group 'lsp-ansible
  79. :package-version '(lsp-mode . "8.0.1"))
  80. (defcustom lsp-ansible-execution-environment-enabled nil
  81. "Enable or disable the use of an execution environment."
  82. :type 'boolean
  83. :group 'lsp-ansible
  84. :package-version '(lsp-mode . "8.0.1"))
  85. (defcustom lsp-ansible-execution-environment-image "quay.io/ansible/creator-ee:latest"
  86. "Specify the name of the execution environment image."
  87. :type 'string
  88. :group 'lsp-ansible
  89. :package-version '(lsp-mode . "8.0.1"))
  90. (defcustom lsp-ansible-execution-environment-pull-policy "missing"
  91. "Specify the image pull policy.
  92. Valid values are always, missing, never and tag. Setting always will always
  93. pull the image when extension is activated or reloaded. Setting missing will
  94. pull if not locally available. Setting never will never pull the image and
  95. setting tag will always pull if the image tag is latest, otherwise pull
  96. if not locally available."
  97. :type '(choice (const "always")
  98. (const "missing")
  99. (const "never")
  100. (const "tag"))
  101. :group 'lsp-ansible
  102. :package-version '(lsp-mode . "8.0.1"))
  103. (defcustom lsp-ansible-execution-environment-pull-arguments ""
  104. "Specify any additional parameters for the pull command.
  105. Example: --tls-verify=false"
  106. :type 'string
  107. :group 'lsp-ansible
  108. :package-version '(lsp-mode . "8.0.1"))
  109. (defcustom lsp-ansible-execution-environment-container-options ""
  110. "Extra parameters passed to the container engine command.
  111. Example: -net=host"
  112. :type 'string
  113. :group 'lsp-ansible
  114. :package-version '(lsp-mode . "8.0.1"))
  115. (defcustom lsp-ansible-execution-environment-volume-mounts []
  116. "Additonnal volumes to mount in container.
  117. The value is a vector of plists. Expected properties are:
  118. - src: the name of the local volume or path to be mounted within execution
  119. environment
  120. - dest: the path where the file or directory are mounted in the container
  121. - options: the property is optional, and is a comma-separated list of options.
  122. Example: ro,Z"
  123. :type '(lsp-repeatable-vector plist)
  124. :group 'lsp-ansible
  125. :package-version '(lsp-mode . "8.0.1"))
  126. (defcustom lsp-ansible-python-interpreter-path ""
  127. "Path to the python/python3 executable.
  128. This setting may be used to make the extension work with ansible and
  129. ansible-lint installations in a Python virtual environment."
  130. :type 'string
  131. :group 'lsp-ansible
  132. :package-version '(lsp-mode . "8.0.1"))
  133. (defcustom lsp-ansible-python-activation-script ""
  134. "Path to a custom activate script.
  135. It will be used instead of `lsp-ansible-python-interpreter-path' to run in a
  136. Python virtual environment."
  137. :type 'string
  138. :group 'lsp-ansible
  139. :package-version '(lsp-mode . "8.0.1"))
  140. (lsp-dependency 'ansible-language-server
  141. '(:system "ansible-language-server")
  142. '(:npm :package "@ansible/ansible-language-server"
  143. :path "ansible-language-server"))
  144. (lsp-register-custom-settings
  145. '(("ansible.ansible.path" lsp-ansible-ansible-path)
  146. ("ansible.ansible.useFullyQualifiedCollectionNames" lsp-ansible-use-fully-qualified-collection-names t)
  147. ("ansible.ansibleLint.arguments" lsp-ansible-ansible-lint-arguments)
  148. ("ansible.ansibleLint.enabled" lsp-ansible-ansible-lint-enabled t)
  149. ("ansible.ansibleLint.path" lsp-ansible-ansible-lint-path)
  150. ("ansible.completion.provideRedirectModules" lsp-ansible-completion-provide-redirect-modules t)
  151. ("ansible.completion.provideModuleOptionAliases" lsp-ansible-completion-provide-module-option-aliases t)
  152. ("ansible.executionEnvironment.containerEngine" lsp-ansible-execution-environment-container-engine)
  153. ("ansible.executionEnvironment.enabled" lsp-ansible-execution-environment-enabled t)
  154. ("ansible.executionEnvironment.image" lsp-ansible-execution-environment-image)
  155. ("ansible.executionEnvironment.pull.policy" lsp-ansible-execution-environment-pull-policy)
  156. ("ansible.executionEnvironment.pull.arguments" lsp-ansible-execution-environment-pull-arguments)
  157. ("ansible.executionEnvironment.containerOptions" lsp-ansible-execution-environment-container-options)
  158. ("ansible.executionEnvironment.volumeMounts" lsp-ansible-execution-environment-volume-mounts)
  159. ("ansible.python.interpreterPath" lsp-ansible-python-interpreter-path)
  160. ("ansible.python.activationScript" lsp-ansible-python-activation-script)))
  161. (defun lsp-ansible-check-ansible-minor-mode (&rest _)
  162. "Check whether ansible minor mode is active.
  163. This prevents the Ansible server from being turned on in all yaml files."
  164. (and (eq major-mode 'yaml-mode)
  165. ;; emacs-ansible provides ansible, not ansible-mode
  166. (with-no-warnings (bound-and-true-p ansible))))
  167. (lsp-register-client
  168. (make-lsp-client
  169. :new-connection (lsp-stdio-connection
  170. (lambda ()
  171. `(,(or (executable-find
  172. (cl-first lsp-ansible-language-server-command))
  173. (lsp-package-path 'ansible-language-server))
  174. ,@(cl-rest lsp-ansible-language-server-command))))
  175. :priority 1
  176. :activation-fn #'lsp-ansible-check-ansible-minor-mode
  177. :server-id 'ansible-ls
  178. :download-server-fn (lambda (_client callback error-callback _update?)
  179. (lsp-package-ensure 'ansible-language-server callback error-callback))))
  180. (lsp-consistency-check lsp-ansible)
  181. (provide 'lsp-ansible)
  182. ;;; lsp-ansible.el ends here