feat(lang): enable terraform-ls language server support in terraform-mode

This commit is contained in:
2020-11-09 10:46:54 +00:00
parent b784fccb40
commit 3adfd0c0eb

View File

@@ -8,6 +8,7 @@
(require 'siren-company)
(require 'siren-reformatter)
(require 'siren-lsp)
(use-package terraform-mode
:hook
@@ -18,21 +19,33 @@
:init
(defun siren-terraform-mode-setup ()
(setq tab-width 2)
(setq-local tab-width 2)
(terraform-format-on-save-mode 1))
:config
;; This does a better job of injecting formatted content than the default
;; formatting commands included with terraform-mode.
(reformatter-define terraform-format
:program "terraform"
:args '("fmt" "-no-color" "-")
:lighter " TF"))
:lighter " TF")
(use-package company-terraform
:init
(with-eval-after-load 'terraform-mode
(company-terraform-init)))
;; When terraform-ls CLI tool is available, setup lsp-mode to use it
(when (executable-find "terraform-ls")
(with-eval-after-load 'lsp-mode
;; Disable terraform client included with lsp-mode, because it uses
;; terraform-lsp which I have not managed to get working.
(add-to-list 'lsp-disabled-clients 'tfls)
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection '("terraform-ls" "serve"))
:major-modes '(terraform-mode)
:priority 1
:server-id 'terraform-ls))
(add-hook 'terraform-mode-hook #'lsp-deferred))))
(use-package terraform-doc
:defer t)