-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[v3] Binding generator using go/types
#3397
Conversation
Additionally: * fixes generation of tuple return type * improves imports and namespacing in JS mode * general cleanup of generated code
Improves support for unknown types (encoded as any) and maps (using Typescript index signatures)
* Makes call by ID the default
Rename `.Models()` to `.FindModels()`
I managed to improve the performance a bit. The previously mentioned test project now takes about 115ms (before: 243ms) to process. The main performance gain comes from calling During benchmarking, I noticed that Running tool: /usr/bin/go test -benchmem -run=^$ -bench ^BenchmarkParser$ github.com/wailsapp/wails/v3/internal/parser
goos: linux
goarch: amd64
pkg: github.com/wailsapp/wails/v3/internal/parser
cpu: AMD Ryzen 5 3600 6-Core Processor
BenchmarkParser/struct_literal_single/ParseProject-12 9 122664394 ns/op 6680450 B/op 59841 allocs/op
BenchmarkParser/struct_literal_single/ParsePackages-12 7963 244462 ns/op 79549 B/op 1532 allocs/op
BenchmarkParser/struct_literal_single/GenerateBindings-12 751 1475458 ns/op 191068 B/op 5965 allocs/op
BenchmarkParser/struct_literal_single/GenerateModels-12 5888 220428 ns/op 32871 B/op 792 allocs/op
BenchmarkParser/complex_json/ParseProject-12 9 121939557 ns/op 6273351 B/op 56070 allocs/op
BenchmarkParser/complex_json/ParsePackages-12 10000 122095 ns/op 34350 B/op 723 allocs/op
BenchmarkParser/complex_json/GenerateBindings-12 18594 65682 ns/op 8942 B/op 241 allocs/op
BenchmarkParser/complex_json/GenerateModels-12 1755 614594 ns/op 85877 B/op 2502 allocs/op
BenchmarkParser/multiple_packages/ParseProject-12 9 117322676 ns/op 8458869 B/op 69577 allocs/op
BenchmarkParser/multiple_packages/ParsePackages-12 98 12656978 ns/op 831900 B/op 18418 allocs/op
BenchmarkParser/multiple_packages/GenerateBindings-12 3052 516789 ns/op 86948 B/op 2411 allocs/op
BenchmarkParser/multiple_packages/GenerateModels-12 1986 523006 ns/op 80129 B/op 1954 allocs/op
PASS
ok github.com/wailsapp/wails/v3/internal/parser 20.733s
|
and remove dead code
Hey, just want to give some feedback, I have quite complicated models and this is first version of parser that managed to parse it and generate TS models correctly. Only I have also fixed parse so call to |
@overlordtm - It would be great if you could contribute to this PR 🙏 |
Thank you for testing!
@overlordtm could you provide an example? |
@abichinger - do you have a feature list for this enhancement? I'm thinking this will help with the integration of @fbbdev 's work. |
I spoke to @fbbdev earlier and he suggested closing the other PR and concentrating efforts on this, so that's what I'll do. |
I would appreciate some feedback on the generated package directories. The current behaviour is as follows.
Let's asume our project directory has the package path
The current solution could still cause collisions. For example, a package Do you consider the current solution to be okay? Update 2024-04-21With 3be3606 the generated package directories are somewhat configurable. The -base string
The base package path (default ".")
-n Place the base package bindings inside a directory with the base package name Here are some examples: Results for executing
Results for executing
Results for executing
|
- Add `BasePath`: The base package path - Add `UseBaseName`: Place the base package bindings inside a folder with the base package name - Add more tests
ae10e75
to
3be3606
Compare
Awesome work 😎 I've created a post on discord to discuss the ains/strategy of the parser which I think would be a better forum than GH. |
If the dist directory is empty the task `generate:bindings` will fail with the following error message: pattern frontend/dist: cannot embed directory frontend/dist: contains no embeddable files
@abichinger - Can we close this in favour of #3468 now? |
Closing in favour of #3468 |
Description
This PR continues the work done by @fbbdev in #3347. I used this commit 241c578 as a starting point and modified the binding and model generator code to work with the
go/types
package. Usinggo/types
instead ofgo/ast
fixes the problems with object resolution.#3347 (comment)
golang/go#48141 (comment)
Breaking changes
packagePath.structName.methodName
instead ofpackageName.structName.methodName
to avoid collisions (a702897)GenerateBindingsOptions.UseIDs
got replaced byGenerateBindingsOptions.UseNames
makingCallByID
the new default (aa098b7)parser
packageNew features
wails/v3/internal/parser/testdata/multiple_packages
. You can run this example withgo run .
encoding.TextMarshaler
interface. The resulting Typescript type isstring
. https://github.com/abichinger/wails/blob/1660a12ba2d0f20e2ab5698b4156432c999b043f/v3/internal/parser/testdata/multiple_packages/frontend/bindings/github.com-google-uuid/models.ts#L9Fixes
<type>
parameterLimitations
json.Marshaler
Downsides
Type of change
How Has This Been Tested?
All tests have passed. Some expected results of tests inside
v3/internal/parser/testdata
have been corrected.The binding example has been tested and updated.
The bindings of a test project have been generated.
Test Configuration
Checklist:
website/src/pages/changelog.mdx
with details of this PR