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

Generic bindings #3626

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Generic bindings #3626

wants to merge 3 commits into from

Conversation

ktsivkov
Copy link

@ktsivkov ktsivkov commented Jul 20, 2024

Description

Enable generic structs to be added as binds to the application. It also simplifies how the struct names are being broken, and removes the necessity of splitting the struct name multiple times. Before those changes we can see from the code that the struct name has already been broken into its components, but then it is glued together, later when adding the method into the binding we are doing the reverse, thus we are adding complexity that is not needed.

Fixes #3625

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

Test Configuration

Version | v2.9.1

# System
┌────────────────────────────────────────────────────────────────────────┐
| OS           | Windows 10 Pro                                          |
| Version      | 2009 (Build: 22631)                                     |
| ID           | 23H2                                                    |
| Go Version   | go1.22.4                                                |
| Platform     | windows                                                 |
| Architecture | amd64                                                   |
| CPU          | Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz                |
| GPU          | NVIDIA GeForce RTX 3070 (NVIDIA) - Driver: 32.0.15.5599 |
| Memory       | 32GB                                                    |
└────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status    | Version        |
| WebView2   | N/A          | Installed | 126.0.2592.113 |
| Nodejs     | N/A          | Installed | 20.15.0        |
| npm        | N/A          | Installed | 10.7.0         |
| *upx       | N/A          | Available |                |
| *nsis      | N/A          | Available |                |
└─────────────── * - Optional Dependency ────────────────┘

# Diagnosis
Optional package(s) installation details:
  - upx : Available at https://upx.github.io/
  - nsis : More info at https://wails.io/docs/guides/windows-installer/

Checklist:

  • I have updated website/src/pages/changelog.mdx with details of this PR
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

The ones I have skipped I deemed non-related as the changes made were quite minimal. Can do so if deemed necessary by maintainers.

Summary by CodeRabbit

  • New Features

    • Introduced a new structured representation for method paths, enhancing error reporting and clarity in method identification.
    • Added functionality to standardize struct naming for improved path construction.
  • Bug Fixes

    • Enhanced error messages to provide more informative outputs regarding method identification, improving debugging capabilities.
  • Refactor

    • Simplified the method for adding new methods by removing unnecessary complexity, resulting in improved code maintainability.

Copy link
Contributor

coderabbitai bot commented Jul 20, 2024

Walkthrough

The recent changes focus on improving the codebase's clarity and organization within the binding mechanism. Key updates include dependency upgrades for better security and performance, simplifications in the method binding logic, and the introduction of a structured approach to handle method paths. These modifications enhance maintainability and lay the groundwork for potential feature expansions, including support for binding generic structs.

Changes

Files Change Summary
v2/examples/customlayout/go.mod Updated several indirect dependencies to newer versions, enhancing security and performance.
v2/internal/binding/binding.go Simplified the Add method by removing unnecessary string manipulation, improving code clarity.
v2/internal/binding/boundMethod.go Introduced BoundedMethodPath struct to encapsulate method path details, enhancing error reporting.
v2/internal/binding/reflect.go Added normalizeStructName function for standardizing struct names, utilizing BoundedMethodPath for method paths.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Binding
    participant Database

    Client->>Binding: Add method
    Binding->>Database: AddMethod(DecodedMethod)
    Database-->>Binding: Success
    Binding-->>Client: Confirmation
Loading

Assessment against linked issues

Objective Addressed Explanation
Enable binding of generic structs (#3625) It's unclear if current changes enable generic binding as specified.

🐇 Hop, skip, and jump, oh what a delight,
Code's now clearer, shining so bright!
Methods neatly wrapped, like carrots in a patch,
Binding made simple, with a seamless match.
For every hop forward, we cheer with glee,
Thanks to our changes, we're as happy as can be! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7a40cc5 and d8fe35d.

Files ignored due to path filters (1)
  • v2/examples/customlayout/go.sum is excluded by !**/*.sum
Files selected for processing (4)
  • v2/examples/customlayout/go.mod (1 hunks)
  • v2/internal/binding/binding.go (2 hunks)
  • v2/internal/binding/boundMethod.go (3 hunks)
  • v2/internal/binding/reflect.go (3 hunks)
Additional comments not posted (13)
v2/examples/customlayout/go.mod (4)

32-32: Update: Dependency golang.org/x/crypto upgraded to v0.23.0.

The upgrade from v0.17.0 to v0.23.0 may include security patches and performance improvements. Ensure to test the application for compatibility.


34-34: Update: Dependency golang.org/x/net upgraded to v0.25.0.

The upgrade from v0.17.0 to v0.25.0 may include security patches and performance improvements. Ensure to test the application for compatibility.


35-35: Update: Dependency golang.org/x/sys upgraded to v0.20.0.

The upgrade from v0.15.0 to v0.20.0 may include security patches and performance improvements. Ensure to test the application for compatibility.


36-36: Update: Dependency golang.org/x/text upgraded to v0.15.0.

The upgrade from v0.14.0 to v0.15.0 may include security patches and performance improvements. Ensure to test the application for compatibility.

v2/internal/binding/boundMethod.go (5)

9-13: New Struct: BoundedMethodPath.

The new struct encapsulates the package, struct, and method names, providing a structured way to represent method paths. This improves the organization and readability of method-related data.


15-17: New Method: FullName for BoundedMethodPath.

The FullName method returns the full name of the method in the format Package.Struct.Name. This enhances error reporting by providing more informative output.


22-22: Integration: Path field in BoundMethod.

The Path field of type *BoundedMethodPath is added to the BoundMethod struct. This integration improves the organization and readability of method-related data.


43-43: Improvement: Enhanced error message in ParseArgs.

The error message now includes the full method name using b.Path.FullName(), providing more informative output regarding method identification.


67-67: Improvement: Enhanced error message in Call.

The error message now includes the full method name using b.Path.FullName(), providing more informative output regarding method identification.

v2/internal/binding/reflect.go (3)

27-45: New Helper Function: normalizeStructName.

The function standardizes the naming of struct types by replacing certain characters with more suitable alternatives. This helps in maintaining consistent naming conventions.


70-71: Modification: Use normalizeStructName in getMethods.

The structName is now normalized using normalizeStructName, ensuring consistent naming conventions for struct types.


87-91: Integration: Use BoundedMethodPath in getMethods.

The getMethods function now constructs method paths using BoundedMethodPath, improving the clarity and maintainability of the code.

v2/internal/binding/binding.go (1)

77-77: LGTM! The simplification enhances readability.

The changes reduce unnecessary complexity by directly using the method.Path structure. Ensure that the method.Path structure is correctly populated in all cases.

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

Successfully merging this pull request may close these issues.

Enable the binding of generic binds
1 participant