Fix terraform browse documentation command

This commit is contained in:
Jeremy Dormitzer 2024-05-10 16:06:45 -04:00
parent da98498fd4
commit e72ae38079

View File

@ -44,6 +44,24 @@
(defun terraform-setup-eldoc ()
(add-hook 'eldoc-documentation-functions #'terraform-devdocs-eldoc-function nil t))
(add-hook 'terraform-mode-hook #'terraform-setup-eldoc))
(add-hook 'terraform-mode-hook #'terraform-setup-eldoc)
(defun find-terraform-root ()
"Returns the highest-level parent directory containing a .tf file."
(let ((current-dir default-directory)
(root nil))
(while (and (not (string-match locate-dominating-stop-dir-regexp current-dir))
(f-glob "*.tf" current-dir))
(setq root current-dir)
(setq current-dir (f-parent current-dir)))
(when root (file-name-as-directory root))))
;; Use root terraform module to resolve providers
(defun terraform-provider-ns-advice (oldfn &rest args)
(let ((dir (or (find-terraform-root) default-directory)))
(let ((default-directory dir))
(apply oldfn args))))
(advice-add 'terraform--get-resource-provider-namespace :around #'terraform-provider-ns-advice))
(provide 'init-terraform)