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

Add gotype comments in templates to map types between go template and go files #4155

Merged
merged 4 commits into from
Aug 15, 2023

Conversation

haywoodsh
Copy link
Contributor

@haywoodsh haywoodsh commented Jul 26, 2023

Proposed changes

Add gotype comments to specify mapping of types between Go templates (.tmpl) and go files (.go)
closes #4159

Testing

This is the screenshot of how it would look like in IntelliJ or GoLand. For example, $u.Servers links to the field Servers in []StreamUpstreamServer struct
image
Browse the definition on pkg.dev.go. Note the that information on the website is stuck on v1.12.5 until #3770 is resolved.
image
Autocomplete:
image

However, I tested this syntax for IntelliJ and GoLand only. For other unsupported IDE the comments still provide developer hints on which go file to look for the go struct definition.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@github-actions github-actions bot added the chore Pull requests for routine tasks label Jul 26, 2023
@github-actions
Copy link

github-actions bot commented Jul 26, 2023

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Manifest Files

@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Merging #4155 (ad4990d) into main (a820492) will increase coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #4155      +/-   ##
==========================================
+ Coverage   51.95%   51.97%   +0.02%     
==========================================
  Files          59       59              
  Lines       16762    16762              
==========================================
+ Hits         8708     8712       +4     
+ Misses       7755     7753       -2     
+ Partials      299      297       -2     

see 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@lucacome
Copy link
Member

Does this work only in IntelliJ?

@jjngx
Copy link
Contributor

jjngx commented Jul 27, 2023

A good idea 👍🏻 VSCode supports this feature too. Apart from IDE support, the comments help to understand the code.

@shaun-nx
Copy link
Contributor

Does this work only in IntelliJ?

You will only get the popups linking to the go structs in IntelliJ.
That being said, it would still help in general to have this in our templates.

For example, for the VirtualServer templates, you would have this block

{{- /*gotype: github.com/nginxinc/kubernetes-ingress/internal/configs/version2.VirtualServerConfig*/ -}}

This makes it very obvious which file in the project holds the go structs related to this template.

@haywoodsh haywoodsh marked this pull request as ready for review August 9, 2023 15:01
@haywoodsh haywoodsh requested a review from a team as a code owner August 9, 2023 15:01
Copy link
Contributor

@jjngx jjngx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@lucacome
Copy link
Member

A good idea 👍🏻 VSCode supports this feature too. Apart from IDE support, the comments help to understand the code.

@jjngx how do you use it in VS Code?

@jjngx
Copy link
Contributor

jjngx commented Aug 11, 2023

A good idea 👍🏻 VSCode supports this feature too. Apart from IDE support, the comments help to understand the code.

@jjngx how do you use it in VS Code?

I don't use it.

@vepatel
Copy link
Contributor

vepatel commented Aug 11, 2023

I don't think it's supported in vsCode (at least not directly or even with changes in settings.json ) but its nice info re struct definition regardless.

@haywoodsh haywoodsh enabled auto-merge (squash) August 15, 2023 13:38
@haywoodsh haywoodsh merged commit 0d01d8e into main Aug 15, 2023
20 checks passed
@haywoodsh haywoodsh deleted the chore/add-gotype-comments branch August 15, 2023 13:41
@haywoodsh haywoodsh self-assigned this Aug 15, 2023
@danielnginx danielnginx added this to the v3.3.0 milestone Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Pull requests for routine tasks
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Link structs between go templates and go files for easier development #4155
6 participants