-
Notifications
You must be signed in to change notification settings - Fork 628
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
Terraform (HCL) (*.tf): new parser #2952
Terraform (HCL) (*.tf): new parser #2952
Conversation
Have opened this as a quick thing, please advise if there are other things I need to do before merging (I read through https://docs.ctags.io/en/latest/optlib.html but may have missed some things). |
main/parsers_p.h
Outdated
@@ -149,6 +149,7 @@ | |||
SystemTapParser, \ | |||
TclParser, \ | |||
TclOOParser, \ | |||
TfParser, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TerraformParser or TerraFormParser is better.
# GNU General Public License version 2 or (at your option) any later version. | ||
# | ||
# Derived from `vim-terraform-completion`: | ||
# - https://github.com/juliosueiras/vim-terraform-completion/blob/master/ctags/terraform.ctags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you reuse the regex patterns of @juliosueiras's work, ask @juliosueiras to allow to use one's .ctags in GPLv2 or later. Copy & paste the evidence of alowing to use here as comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would I need to paste?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you fill and paste it at the head of your .ctags?
#
# Copyright (c) 2021, <YOUR NAME HERE>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
# - https://github.com/juliosueiras/vim-terraform-completion/blob/master/ctags/terraform.ctags | ||
# | ||
# Changed the name from `terraform` to `tf` so vim will recognise it properly based | ||
# on file extension (*.tf). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the name of the parser must be "tf"?
optlib/terraform.ctags
Outdated
# - https://www.terraform.io/docs/language/values/locals.html | ||
|
||
--langdef=tf | ||
--map-tf=+tf:.tf.tfvars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be
--map-tf=+.tf
--map-tf=+.tfvars
See https://docs.ctags.io/en/latest/man/ctags.1.html#options for more details.
optlib/terraform.ctags
Outdated
|
||
--langdef=tf | ||
--map-tf=+tf:.tf.tfvars | ||
--regex-tf=/^[[:space:]]*resource[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/r,Resource/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use --kinddef-=... option before using kinds.
https://docs.ctags.io/en/latest/man/ctags-optlib.7.html#options
win32/ctags_vs2013.vcxproj
Outdated
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't put a newline at the end of file.
win32/ctags_vs2013.vcxproj.filters
Outdated
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't put a newline at the end of file.
# A notable abscence is `local`, because `locals` are defined inside a block and | ||
# it's way harder to write a good regex for that. | ||
# - https://www.terraform.io/docs/language/values/locals.html | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put a URL for the language reference?
@masatake thank you for fast and thorough review 😄, I will address comments as/when I can. @juliosueiras apologies, perhaps I should have talked to you first? 😅 |
@antonysouthworth-halter no, thats fine |
5247cf8
to
ca9d8fe
Compare
optlib/terraform.ctags
Outdated
# it's way harder to write a good regex for that. | ||
# - https://www.terraform.io/docs/language/values/locals.html | ||
|
||
--langdef=tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terraform or TerraformHCL is better. I'm not sure which one is better.
If you are not sure, too, use longer name as I did in "PupppetManifest".
win32/ctags_vs2013.vcxproj
Outdated
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About this file, no newline at the of file
win32/ctags_vs2013.vcxproj.filters
Outdated
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About this file, no newline at the end of file.
--kinddef-terraform=o,Output,Terraform Output | ||
--regex-terraform=/^[[:space:]]*resource[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/r,Resource/ | ||
--regex-terraform=/^[[:space:]]*data[[:space:]]*"([^"]*)"[[:space:]]*"([^"]*)"/\2/d,Data/ | ||
--regex-terraform=/^[[:space:]]*variable[[:space:]]*"([^"]*)"/\1/v,Variable/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v is already defined with --kinddef-...
. So you don't have to specify v,Variable
. Just v
is enough:
--regex-Terraform=/^[[:space:]]*variable[[:space:]]*"([^"]*)"/\1/v/
I don't know well about the syntax of Terraforms. However, I guess a whitespace may be needed after variable
keyword. We don't record a variable having an empty string as name. So +
is better than *
.
--regex-Terraform=/^[[:space:]]*variable[[:space:]]+"([^"]+)"/\1/v/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is applicable to other lines of --regex-...
.
--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/ | ||
--langdef=terraform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I forgot writing one thing. A parser that is part of ctags should have Capitalized name.
Please, do s/terraform/Terraform/g
.
I was able to add |
@tonglil, feel free to make a new pull request that includes the changes of this pull request. |
The biggest reason I didn't merge this is there is no test case. |
Sorry, I will not be able to contribute to this PR. |
@masatake I'd like to take over and finish this PR |
@Haggus You are welcome. optlib/terraform.c is automatically generated by misc/optlib2c. |
I will close this via #3684. |
@antonysouthworth-halter, thank you. |
Add support for Terraform (HCL) files.
Related:
TODO