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

👍 generate sub local scope option types #270

Merged
merged 2 commits into from
Sep 26, 2024
Merged

👍 generate sub local scope option types #270

merged 2 commits into from
Sep 26, 2024

Conversation

Milly
Copy link
Contributor

@Milly Milly commented Aug 29, 2024

Fixes #267
Fixes some #268

getTabPage() or setTabPage() is not implemented.
See #268 (comment)

Summary by CodeRabbit

  • New Features

    • Enhanced option processing and exporting with a new Context type for better management of option types and constructors.
    • Improved error handling in the parsing functions for more informative logging.
    • Introduced new interfaces for local options, allowing for more specific option management across different contexts (buffer, tab page, window).
  • Bug Fixes

    • Updated return types in parsing functions to ensure more predictable outputs and prevent runtime errors.
  • Documentation

    • Updated comments to clarify new requirements and expectations for option handling.
  • Refactor

    • Streamlined type checks and option declarations for improved readability and maintainability.

Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes involve significant updates to the option handling system, enhancing type definitions and refining the scope of various options. New types such as BufferLocalOption, WindowLocalOption, and others have been introduced, while existing options have been updated to reflect their specific contexts. Improvements in error handling, option processing, and the overall structure of the code have also been implemented to ensure better management and clarity.

Changes

Files Change Summary
.scripts/gen-option/format.ts Updated formatOption to use a new Context type, refactored option type determination logic.
.scripts/gen-option/parse.ts Enhanced error handling in parse, modified parseBlock to always return an Option object.
.scripts/gen-option/types.ts Introduced new types and constants for option handling, replaced function declarations with constants.
option/_generated.ts Updated various option types for specificity, changing from LocalOption to more specific types.
option/_utils.ts Expanded OptionImpl class to implement multiple option interfaces, enhancing flexibility.
option/nvim/_generated.ts Changed option types to reflect buffer and window specificity, improving clarity.
option/types.ts Added new interfaces for local options and refined existing type definitions for better control.
option/vim/_generated.ts Updated option declarations to improve specificity and control over option scopes.

Assessment against linked issues

Objective Addressed Explanation
Users may access options in an unintended way (#267) The issue regarding getBuffer() method remains unaddressed.

🐇 Hop, hop, hooray for changes bright,
New options sprout, taking flight!
Buffer and window, all in their place,
Clarity shines, a joyful embrace!
With types so neat, we dance and play,
In the land of code, it's a splendid day! 🌼


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@Milly Milly marked this pull request as draft August 29, 2024 02:37
@Milly
Copy link
Contributor Author

Milly commented Aug 29, 2024

Blocked by #269.

error: TS2339 [ERROR]: Property 'getBuffer' does not exist on type 'WindowLocalOption<string>'.
      op.foldmethod.getBuffer(denops, bufnr),
                    ~~~~~~~~~
    at file:///deno-denops-std/buffer/buffer.ts:526:21

Base automatically changed from option-class to main August 29, 2024 23:17
@Milly Milly marked this pull request as ready for review September 6, 2024 14:48
@Milly
Copy link
Contributor Author

Milly commented Sep 6, 2024

@coderabbitai review

Copy link

codecov bot commented Sep 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.60%. Comparing base (afa88b7) to head (75e7696).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #270   +/-   ##
=======================================
  Coverage   84.60%   84.60%           
=======================================
  Files          63       63           
  Lines        3372     3372           
  Branches      291      291           
=======================================
  Hits         2853     2853           
  Misses        517      517           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

coderabbitai bot commented Sep 6, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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: 2

Outside diff range, codebase verification and nitpick comments (2)
option/types.ts (1)

Line range hint 82-97: Reconsider inheritance for BufferLocalOption.

The BufferLocalOption interface extends WindowLocalOption, which might not be appropriate as buffer options should not inherit window-specific behaviors. Consider changing the inheritance to directly extend LocalOption or another more suitable base interface.

.scripts/gen-option/parse.ts (1)

Line range hint 121-152: Improved type safety and validation in parseBlock function.

The changes in the parseBlock function significantly improve type safety and validation. The function now throws a TypeError if the scope is "local" and localscope is undefined, which enforces the correct usage of scope definitions. This is a critical improvement for maintaining the integrity of option scopes.

Consider adding more detailed comments or examples in the documentation to explain the relationship between scope and localscope for future maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between afa88b7 and 75e7696.

Files selected for processing (8)
  • .scripts/gen-option/format.ts (3 hunks)
  • .scripts/gen-option/parse.ts (7 hunks)
  • .scripts/gen-option/types.ts (1 hunks)
  • option/_generated.ts (129 hunks)
  • option/_utils.ts (1 hunks)
  • option/nvim/_generated.ts (7 hunks)
  • option/types.ts (3 hunks)
  • option/vim/_generated.ts (11 hunks)
Additional comments not posted (30)
.scripts/gen-option/types.ts (2)

28-34: Enhancements approved: New constants and types for option handling.

The introduction of OPTION_LOCAL_SCOPES, OPTION_EXPORT_TYPES, and OPTION_CONSTRUCTORS, along with their corresponding types, enhances the flexibility and expressiveness of the option handling system. Verify that these new types and constants are correctly used and integrated into the codebase.

Run the following script to verify the usage of new constants and types:

Also applies to: 38-46, 50-54


16-18: Refactor approved: Simplified type checks using constants.

The transformation of isOptionType and isOptionScope from functions to constant exports using isLiteralOneOf simplifies the code and enhances type safety. Ensure that these constants are correctly used across the codebase.

Run the following script to verify the usage of isOptionType and isOptionScope:

Also applies to: 24-26

.scripts/gen-option/format.ts (2)

3-6: Enhancements approved: Introduction of Context type for better option management.

The introduction of the Context type and its usage in the format function improve the maintainability and flexibility of the option formatting process. Verify that the Context type is correctly used and integrated into the option formatting process.

Run the following script to verify the usage of the Context type:

Also applies to: 80-94

Verification successful

Verification successful: Context type is correctly used and integrated.

The Context type is consistently used across multiple files and functions, such as cmd and eval, to manage options and configurations. This confirms its correct integration into the option formatting process, aligning with the intended improvements in maintainability and flexibility.

  • Files where Context is used:
    • helper/expr_string.ts
    • helper/execute.ts
    • eval/use_eval.ts
    • batch/collect.ts
    • batch/batch.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `Context` type in the option formatting process.

# Test: Search for the usage of the `Context` type in option formatting. Expect: Correct usage and integration.
rg --type typescript -A 5 $'Context'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the usage of the `Context` type in the option formatting process.

# Test: Search for the usage of the `Context` type in option formatting. Expect: Correct usage and integration.
rg --type ts -A 5 $'Context'

Length of output: 4567


21-30: Refactor approved: Enhanced option processing with new context and logic.

The updates to formatOption, getOptionExportType, and getOptionConstructor enhance the granularity and flexibility of option processing. Verify that these functions are correctly integrated and do not introduce regressions in option formatting.

Run the following script to verify the integration of these functions:

Also applies to: 36-60, 64-71

option/_utils.ts (1)

4-20: Refactor approved: Expanded OptionImpl class for comprehensive option management.

The expansion of the OptionImpl class to implement multiple interfaces for different types of options, along with the expanded import statement, suggests a more comprehensive design that enhances option management. Verify that the OptionImpl class is correctly integrated and does not introduce regressions in option management.

Run the following script to verify the integration of the OptionImpl class:

option/types.ts (4)

Line range hint 111-126: LGTM for WindowLocalOption.

The WindowLocalOption interface is well-designed, extending LocalOption and including methods specific to window options, such as getWindow and setWindow.


132-134: LGTM for GlobalOrBufferLocalOption.

The type GlobalOrBufferLocalOption is correctly defined, combining GlobalOption and BufferLocalOption to handle options that can be either global or buffer-local.


140-142: LGTM for GlobalOrTabPageLocalOption.

The type GlobalOrTabPageLocalOption is correctly defined, combining GlobalOption and TabPageLocalOption to handle options that can be either global or tab-page-local.


148-150: LGTM for GlobalOrWindowLocalOption.

The type GlobalOrWindowLocalOption is correctly defined, combining GlobalOption and WindowLocalOption to handle options that can be either global or window-local.

option/vim/_generated.ts (10)

190-190: Refinement of balloonexpr option type.

The change from GlobalOrLocalOption to GlobalOrBufferLocalOption for balloonexpr aligns with the PR's goal to restrict the scope of options to more appropriate contexts. This change ensures that balloonexpr can be set globally or at the buffer level, but not at the window level, which is suitable given its usage context.


420-420: Refinement of cryptmethod option type.

Updating cryptmethod from GlobalOrLocalOption to GlobalOrBufferLocalOption is consistent with the intent to limit the scope where encryption methods are applicable. This change is crucial for security, ensuring that encryption settings can be tailored to specific buffers rather than being universally applied, which could lead to unintended security implications.


900-900: Refinement of key option type.

The change from LocalOption to BufferLocalOption for the key option is appropriate. This option pertains to encryption keys, which should logically be restricted to the buffer scope for security reasons, ensuring that keys are not inadvertently shared across different buffers or windows.


1090-1092: Refinement of osfiletype option type.

The update from LocalOption to BufferLocalOption for osfiletype is a sensible change, reflecting the nature of this option which should be configurable at a buffer level, allowing different file types to be associated with different buffers without affecting global or window settings.


1565-1567: Refinement of shortname option type.

Changing shortname from LocalOption to BufferLocalOption is logical, as file naming conventions might need to be different across various buffers, especially when working with files from different systems or environments within the same session.


1665-1667: Refinement of termwinkey option type.

The update from LocalOption to WindowLocalOption for termwinkey correctly reflects its usage, which is specific to window contexts. This change ensures that key bindings can be customized per window, which is particularly useful in a multi-window environment.


1681-1681: Refinement of termwinscroll option type.

The change from LocalOption to BufferLocalOption for termwinscroll aligns with the need to have scroll settings adjustable per buffer, which can be crucial for user preferences in environments with multiple buffers displaying different content.


1711-1713: Refinement of termwinsize option type.

Updating termwinsize from LocalOption to WindowLocalOption is appropriate, as window size preferences may vary between different windows in the same session, allowing for more granular control over the user interface.


1769-1771: Refinement of textmode option type.

The change from LocalOption to BufferLocalOption for textmode is well-justified. Given that text mode (such as line endings) can vary from one buffer to another, especially when editing files originating from different operating systems, this change enhances flexibility and correctness.


2119-2119: Refinement of wincolor option type.

The update from LocalOption to WindowLocalOption for wincolor is a crucial improvement, ensuring that window-specific color settings are applied correctly, enhancing the visual distinction and customization capabilities of different windows within the editor.

option/_generated.ts (1)

3-4: LGTM!

The code changes are approved.

.scripts/gen-option/parse.ts (4)

39-44: Enhanced error handling in parse function.

The addition of a structured error object in the errors array is a significant improvement. It allows for more detailed error reporting and debugging. This change aligns with best practices for error handling by capturing and logging detailed error information.


54-60: Refined error handling in parse function.

The use of a try-catch block around the parseBlock function call is a good practice. It ensures that parsing errors do not terminate the entire parsing process and that they are handled gracefully.


65-69: Detailed error logging in parse function.

The detailed logging of parsing errors, including the specific block and line number, is an excellent addition. It enhances the ability to diagnose issues quickly and accurately.


165-165: Return statement in parseBlock function.

The structured return of the Option object with all necessary fields is clear and concise. This ensures that all relevant data is encapsulated within a single return object, enhancing the function's usability and integration with other parts of the system.

option/nvim/_generated.ts (6)

17-17: Updated type declaration for channel option.

Changing the type from LocalOption<number> to BufferLocalOption<number> clarifies that the channel option is specific to buffer-level settings. This change enhances type safety and aligns with the PR's objectives to improve option handling.


129-131: Updated type declaration for scrollback option.

The update from LocalOption<number> to BufferLocalOption<number> for the scrollback option is appropriate, as it specifies that this option is relevant only to buffer contexts. This change is consistent with the PR's goal of refining option scope specificity.


326-326: Updated type declaration for statuscolumn option.

The change from LocalOption<string> to WindowLocalOption<string> for the statuscolumn option correctly reflects its applicability to window-level settings. This adjustment improves clarity and ensures that the option's scope is accurately represented.


383-385: Updated type declaration for winbar option.

The transition from GlobalOrLocalOption<string> to GlobalOrWindowLocalOption<string> for the winbar option is a significant improvement. It clarifies that the option can be global or specific to windows, enhancing the understanding and management of this option's scope.


396-396: Updated type declaration for winblend option.

Updating the winblend option from LocalOption<number> to WindowLocalOption<number> is a precise change that aligns with the PR's objectives. It ensures that the option's scope is limited to windows, which is essential for correct settings management.


419-419: Updated type declaration for winhighlight option.

The change from LocalOption<string> to WindowLocalOption<string> for the winhighlight option is crucial for ensuring that the option is correctly categorized as window-specific. This enhances type safety and clarity in the codebase.

option/types.ts Show resolved Hide resolved
option/_generated.ts Show resolved Hide resolved
@Milly Milly added bug Something isn't working enhancement New feature or request labels Sep 6, 2024
Copy link
Member

@lambdalisue lambdalisue left a comment

Choose a reason for hiding this comment

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

LGTM. Can we merge this (if so, plz merge it)? @Milly

option/types.ts Show resolved Hide resolved
@Milly Milly merged commit 402dedb into main Sep 26, 2024
10 checks passed
@Milly Milly deleted the option-local-scope branch September 26, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

option: "local to window" options has getBuffer() method
2 participants