Home

Awesome

pre-commit pre-commit.ci status Commitizen friendly

telescope-terraform-doc.nvim

telescope-terraform-doc.nvim is an extension for telescope.nvim that provides its users with ability to search and browse terraform providers docs.

Demo

Installation

vim-plug

Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'ANGkeith/telescope-terraform-doc.nvim'

Packer

use {
    "nvim-telescope/telescope.nvim",
    requires = {
        { "nvim-lua/plenary.nvim" },
        { "ANGkeith/telescope-terraform-doc.nvim" },
    },
}

Setup

Add the following to your init.vim:

require('telescope').load_extension('terraform_doc')

Usage

Browse the official hashicorp providers:

:Telescope terraform_doc

Browse resources from the latest hashicorp/aws provider:

:Telescope terraform_doc full_name=hashicorp/aws

Browse resources from the v3.74.0 hashicorp/aws provider:

:Telescope terraform_doc full_name=hashicorp/aws version=3.74.0

Browse all terraform modules:

:Telescope terraform_doc modules

Keymap ideas

nnoremap <space>ott :Telescope terraform_doc<cr>
nnoremap <space>otm :Telescope terraform_doc modules<cr>
nnoremap <space>ota :Telescope terraform_doc full_name=hashicorp/aws<cr>
nnoremap <space>otg :Telescope terraform_doc full_name=hashicorp/google<cr>
nnoremap <space>otk :Telescope terraform_doc full_name=hashicorp/kubernetes<cr>

Configurable settings

KeysDescriptionOptions
url_open_handlerThe handler for opening urlfunction
latest_provider_symbolThe symbol for indicating that the current version is the lateststring (default: *)
wincmdCommand to open documentation in a split windowstring (default: botright vnew)
wrapWrap lines in a documentation in a split windowstring (default: nowrap)
search_attach_mappingsThe attach_mapping handler to pass to the search pickerfunction
local function customOpen(url)
    vim.fn.system('open -a Safari "' .. url .. '"')
end
require("telescope").setup({
  extensions = {
    terraform_doc = {
      url_open_handler = customOpen,
      latest_provider_symbol = "  ",
      wincmd = "botright vnew",
      wrap = "nowrap",
    }
  }
})

Telescope key mappings

keyUsage
<cr>Open documentation with url_open_handler
<c-d>Open documentation in a split window
Quirks

Due to how the search picker is written, attach_mapping cannot be used directly to override the mappings.

This is how you can customize the search picker mappings.

local telescope_actions = require("telescope.actions")
local terraform_doc_actions = require("telescope._extensions.terraform_doc.actions")
local terraform_doc_opts = require("telescope._extensions.terraform_doc.config").opts
local function search_attach_mappings()
    telescope_actions.select_default:replace(terraform_doc_actions.doc_view(terraform_doc_opts()))
    return true
end

require("telescope").setup({
  extensions = {
    terraform_doc = {
      search_attach_mappings = search_attach_mappings,
    }
  }
})
require("telescope").load_extension("terraform_doc")