aws / aws/jsii

go: can we make generated go code more self-contained?

Open
#2,847 3 comments 0 reactions 0 assignees View on GitHub
effort/medium feature-request language/go p2
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

## :rocket: Feature Request

### Affected Languages

- [ ] `TypeScript` or `Javascript`
- [ ] `Python`
- [ ] `Java`
- [ ] .NET (`C#`, `F#`, ...)
- [x] `Go`

### General Information
* **JSII Version:** 1.29.0
* **Platform:** all

* [ ] I may be able to implement this feature request

* [ ] This feature might incur a breaking change

### Description

Currently, the go code generator puts the embedded jsii tarball under a subdirectory called `jsii`. This means that in order to be able to import this file, other `.go` files need to know the name of the Go module in which the generated code resides.

For example, the `mypackage` directory [here](https://github.com/eladb/jsii-srcmak-go-proposal/tree/main/mypackage) includes the generated Go code under `mypackage.go` and this file imports `com.example/mymodule/mypackage/jsii` ([line](https://github.com/eladb/jsii-srcmak-go-proposal/blob/70a4554051db06718eb0fd1ce526d605e8de2b33/mypackage/mypackage.go#L5)).

This is okay for jsii-pacmak because it knows the name of the Go module, so it can render this import.

As we are looking into adding support for Go to `jsii-srcmak` (see [PR](https://github.com/cdklabs/jsii-srcmak/pull/476)), it means users of srcmak will need to pass the name of the _parent_ go module into which we are generating source code, and this is quite a burden.

### Proposed Solution

We were wondering if it might be possible to avoid the `jsii` directory altogether and just embed the tarball in the main `.go` file? Perhaps we can special-case the situation where there is a single `.go` file? Alternatively, why does this have to be in a subdirectory? Maybe we can just put this in another .go file next to the main file (same as `mypackage.init.go`) and then it will be possible to simply reference it without needing an `import` statement.

Contributor guide

Open the contributing guide

Research direction

Compare the generated mypackage/mypackage.go example with the embedded jsii tarball under the jsii subdirectory, then review how jsii-pacmak renders the Go module import. Define completion as generated Go code that can reference the embedded tarball without requiring srcmak users to provide the parent Go module name.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.