-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
WalkthroughThe changes involve significant updates to the option handling system, enhancing type definitions and refining the scope of various options. New types such as Changes
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Blocked by #269.
|
7b070ad
to
75e7696
Compare
@coderabbitai review |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
Actions performedReview triggered.
|
There was a problem hiding this 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 forBufferLocalOption
.The
BufferLocalOption
interface extendsWindowLocalOption
, which might not be appropriate as buffer options should not inherit window-specific behaviors. Consider changing the inheritance to directly extendLocalOption
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 aTypeError
if thescope
is "local" andlocalscope
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
andlocalscope
for future maintainability.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
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
, andOPTION_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
andisOptionScope
from functions to constant exports usingisLiteralOneOf
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
andisOptionScope
:Also applies to: 24-26
.scripts/gen-option/format.ts (2)
3-6
: Enhancements approved: Introduction ofContext
type for better option management.The introduction of the
Context
type and its usage in theformat
function improve the maintainability and flexibility of the option formatting process. Verify that theContext
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 ascmd
andeval
, 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
, andgetOptionConstructor
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: ExpandedOptionImpl
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 theOptionImpl
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 forWindowLocalOption
.The
WindowLocalOption
interface is well-designed, extendingLocalOption
and including methods specific to window options, such asgetWindow
andsetWindow
.
132-134
: LGTM forGlobalOrBufferLocalOption
.The type
GlobalOrBufferLocalOption
is correctly defined, combiningGlobalOption
andBufferLocalOption
to handle options that can be either global or buffer-local.
140-142
: LGTM forGlobalOrTabPageLocalOption
.The type
GlobalOrTabPageLocalOption
is correctly defined, combiningGlobalOption
andTabPageLocalOption
to handle options that can be either global or tab-page-local.
148-150
: LGTM forGlobalOrWindowLocalOption
.The type
GlobalOrWindowLocalOption
is correctly defined, combiningGlobalOption
andWindowLocalOption
to handle options that can be either global or window-local.option/vim/_generated.ts (10)
190-190
: Refinement ofballoonexpr
option type.The change from
GlobalOrLocalOption
toGlobalOrBufferLocalOption
forballoonexpr
aligns with the PR's goal to restrict the scope of options to more appropriate contexts. This change ensures thatballoonexpr
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 ofcryptmethod
option type.Updating
cryptmethod
fromGlobalOrLocalOption
toGlobalOrBufferLocalOption
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 ofkey
option type.The change from
LocalOption
toBufferLocalOption
for thekey
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 ofosfiletype
option type.The update from
LocalOption
toBufferLocalOption
forosfiletype
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 ofshortname
option type.Changing
shortname
fromLocalOption
toBufferLocalOption
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 oftermwinkey
option type.The update from
LocalOption
toWindowLocalOption
fortermwinkey
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 oftermwinscroll
option type.The change from
LocalOption
toBufferLocalOption
fortermwinscroll
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 oftermwinsize
option type.Updating
termwinsize
fromLocalOption
toWindowLocalOption
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 oftextmode
option type.The change from
LocalOption
toBufferLocalOption
fortextmode
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 ofwincolor
option type.The update from
LocalOption
toWindowLocalOption
forwincolor
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>
toBufferLocalOption<number>
clarifies that thechannel
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>
toBufferLocalOption<number>
for thescrollback
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>
toWindowLocalOption<string>
for thestatuscolumn
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>
toGlobalOrWindowLocalOption<string>
for thewinbar
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 fromLocalOption<number>
toWindowLocalOption<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>
toWindowLocalOption<string>
for thewinhighlight
option is crucial for ensuring that the option is correctly categorized as window-specific. This enhances type safety and clarity in the codebase.
There was a problem hiding this 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
Fixes #267
Fixes some #268
getTabPage()
orsetTabPage()
is not implemented.See #268 (comment)
Summary by CodeRabbit
New Features
Context
type for better management of option types and constructors.Bug Fixes
Documentation
Refactor