Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add support for Terraform (HCL) #757

Open
antonysouthworth-halter opened this issue Apr 8, 2021 · 3 comments
Open

How to add support for Terraform (HCL) #757

antonysouthworth-halter opened this issue Apr 8, 2021 · 3 comments

Comments

@antonysouthworth-halter
Copy link

Putting this here for others to find; I don't know how to contribute to the project wiki.

Assuming you are using Universal Ctags, (and for reference I'm on macOS Catalina).

  1. Add the following to ~/.ctags.d/terraform.ctags
--langdef=tf
--langmap=tf:.tf.tfvars
--regex-tf=/^[[:space:]]*resource[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/r,Resource/
--regex-tf=/^[[:space:]]*data[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/d,Data/
--regex-tf=/^[[:space:]]*variable[[:space:]]*"([^"]*)"/\1/v,Variable/
--regex-tf=/^[[:space:]]*provider[[:space:]]*"([^"]*)"/\1/p,Provider/
--regex-tf=/^[[:space:]]*module[[:space:]]*"([^"]*)"/\1/m,Module/
--regex-tf=/^[[:space:]]*output[[:space:]]*"([^"]*)"/\1/o,Output/
--regex-tf=/^([a-z0-9_]+)[[:space:]]*=/\1/f,TFVar/

Basically this explains to ctags how to parse .tf files.

  1. Add the following to ~/.vimrc
let g:tagbar_type_tf = {
  \ 'ctagstype': 'tf',
  \ 'kinds': [
    \ 'r:Resource',
    \ 'R:Resource',
    \ 'd:Data',
    \ 'D:Data',
    \ 'v:Variable',
    \ 'V:Variable',
    \ 'p:Provider',
    \ 'P:Provider',
    \ 'm:Module',
    \ 'M:Module',
    \ 'o:Output',
    \ 'O:Output',
    \ 'f:TFVar',
    \ 'F:TFVar'
  \ ]
\ }

AFAIU this basically explains to tagbar how to read the tags generated by ctags.

Example usage:

Screen Shot 2021-04-09 at 9 45 52 AM

@alerque
Copy link
Member

alerque commented Apr 9, 2021

Thanks for the contribution. Adding things to the Wiki should be as easy as hitting "edit" on the page you think it could go on, but I have another suggestion. Why don't you just add the code to the plugin core so it is supported out of the box for everybody without needing to copy a config from the Wiki at all?

I think the file you'd want to edit is this one.

@alerque
Copy link
Member

alerque commented Apr 9, 2021

On further reading I see I missed the bit where this requires modifications to the Ctags config. In that case you are right this will need to go into the Wiki for now. We usually don't add tag maps to the plugin until at least one tag provider program supports them out of the box. Perhaps you could contribute the relevant part upstream to Universal Ctags?

@antonysouthworth-halter
Copy link
Author

@alerque thanks for reply 😄. Have added to wiki: https://github.com/preservim/tagbar/wiki#terraform-hcl

And PR open on universal ctags: universal-ctags/ctags#2952

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants