Skip to content

Исправления и добавления в СписокЗначений#1710

Open
Mr-Rm wants to merge 10 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-valuelist
Open

Исправления и добавления в СписокЗначений#1710
Mr-Rm wants to merge 10 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-valuelist

Conversation

@Mr-Rm

@Mr-Rm Mr-Rm commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Value lists can now normalize stored values by type and (optionally) restrict them to an allowed set.
    • Type descriptions render as a readable comma-separated list.
  • Bug Fixes

    • Added stricter bounds and destination validation for value list operations (including retrieval).
    • Indexed write attempts in readonly scenarios now raise a dedicated, clearer error.
    • Improved errors when a list item doesn’t belong to the current list.
    • Value list item string conversion now returns a consistent empty-value representation.
  • Tests

    • Expanded coverage for invalid indexes, type/allowed-values properties, sorting behavior, and updated string conversion expectations.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ValueListImpl now normalizes values using configured types and available values, validates indices and item ownership, and uses a comparator for sorting. ValueListItem, TypeDescription, and value-list tests are updated for revised string conversion and property behavior.

Changes

ValueList behavior

Layer / File(s) Summary
Value normalization and public type support
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs, src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs, src/OneScript.StandardLibrary/TypeDescriptions/TypeDescription.cs
Created items are adjusted through ListValueType and AvailableValues; ValueListItem construction is assembly-restricted, null and undefined values have dedicated string output, and TypeDescription.ToString() renders contained types.
Index validation, sorting, and error coverage
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs, tests/value-list.os
Retrieval, insertion, lookup, and move operations use explicit bounds and ownership checks; sorting uses GenericIValueComparer, and script tests cover invalid indices and mixed or unordered types.
Value-list conversion and property tests
tests/value-list.os
Script tests verify null and undefined conversion, ТипЗначения, and ДоступныеЗначения behavior with and without a configured type.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ValueListImpl
  participant TypeDescription
  participant AvailableValues
  participant ValueListItem
  Caller->>ValueListImpl: Insert(value)
  ValueListImpl->>TypeDescription: AdjustValue(value)
  ValueListImpl->>AvailableValues: FindByValue(adjusted value)
  ValueListImpl->>ValueListItem: store normalized value
  ValueListImpl-->>Caller: updated list
Loading

Possibly related PRs

Suggested reviewers: evilbeaver

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main changes: fixes and new behavior/tests for СписокЗначений.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs (1)

87-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add defensive null handling for C# callers.

While the OneScript engine passes BslUndefinedValue when a script sets the property to Неопределено, direct C# callers might clear the property by passing null. The current switch throws an InvalidArgumentType exception for null.

Consider treating null identically to BslUndefinedValue.

♻️ Proposed refactor
             set
             {
                 switch (value)
                 {
+                    case null:
                     case BslUndefinedValue:
                         _availableValues = null;
                         break;
 
                     case ValueListImpl vl:
                         _availableValues = vl;
                         break;
 
                     default: throw RuntimeException.InvalidArgumentType();
                 }
             }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs` around
lines 87 - 101, Update the property setter containing the switch on value to
handle a C# null input the same way as BslUndefinedValue: clear _availableValues
and return without throwing. Preserve the existing ValueListImpl assignment and
InvalidArgumentType behavior for all other values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs`:
- Around line 157-170: Update CreateNewListItem so
_availableValues.FindByValue(newValue) is treated as a lookup result: use the
matched ValueListItem.Value when found, and retain or reapply
ListValueType.AdjustValue for a missing result such as BslUndefinedValue. Ensure
the returned ValueListItem.Value is never another ValueListItem.

---

Nitpick comments:
In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs`:
- Around line 87-101: Update the property setter containing the switch on value
to handle a C# null input the same way as BslUndefinedValue: clear
_availableValues and return without throwing. Preserve the existing
ValueListImpl assignment and InvalidArgumentType behavior for all other values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af84cea8-c1d8-40b8-ade6-4b86459beef3

📥 Commits

Reviewing files that changed from the base of the PR and between 1c19450 and 02c147d.

📒 Files selected for processing (4)
  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs
  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs
  • src/OneScript.StandardLibrary/TypeDescriptions/TypeDescription.cs
  • tests/value-list.os

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs (1)

157-173: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Defensively handle null for the presentation parameter.

Direct invocations to Add or Insert from C# code (where the default null is utilized) will result in ValueListItem.Presentation being set to null. A subsequent call to SortByPresentation() will throw a NullReferenceException when it invokes x.Presentation.CompareTo(...).

Normalize it to string.Empty to ensure stability. Based on learnings, explicitly handle null for optional string parameters to protect against direct C# invocations.

🛡️ Proposed fix
         private ValueListItem CreateNewListItem(IValue value, string presentation, bool check, IValue picture)
         {
             var newValue = ListValueType.AdjustValue(value);
             if (_availableValues is not null)
             {
                 var foundItem = _availableValues.FindByValue(newValue);
                 newValue = foundItem is ValueListItem li ? li.Value : ListValueType.AdjustValue();
             }
 
             return new ValueListItem
             {
                 Value = newValue,
-                Presentation = presentation,
+                Presentation = presentation ?? string.Empty,
                 Check = check,
                 Picture = picture
             };
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs` around
lines 157 - 173, Update CreateNewListItem so a null presentation argument is
normalized to string.Empty before assigning ValueListItem.Presentation. Preserve
the supplied presentation text for non-null values and keep the existing value
adjustment and item construction behavior unchanged.

Source: Learnings

🧹 Nitpick comments (2)
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs (2)

396-411: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use expression-bodied methods for the factory methods.

Since C# 12 language features are permitted, simplifying these methods to expression bodies will eliminate boilerplate and improve readability. As per coding guidelines, C# 12 language features can be applied when generating code for projects other than VSCode.DebugAdapter.

✨ Proposed refactor
         [ScriptConstructor]
-        public static ValueListImpl Constructor()
-        {
-            return new ValueListImpl();
-        }
+        public static ValueListImpl Constructor() => new();
 
-        public static RuntimeException IndexedIsReadonlyException()
-        {
-            return new("Индексированное значение доступно только для чтения", "Indexed value is read-only");
-        }
+        public static RuntimeException IndexedIsReadonlyException() => 
+            new("Индексированное значение доступно только для чтения", "Indexed value is read-only");
 
-        public static RuntimeException ElementDoesntBelongException()
-        {
-            return new("Элемент не принадлежит списку значений", "Element does not belong to values list");
-        }
+        public static RuntimeException ElementDoesntBelongException() => 
+            new("Элемент не принадлежит списку значений", "Element does not belong to values list");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs` around
lines 396 - 411, Convert the ValueListImpl factory-style methods Constructor,
IndexedIsReadonlyException, and ElementDoesntBelongException to
expression-bodied members, preserving their current return values and exception
messages.

Source: Coding guidelines


330-345: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Avoid reversing integer comparisons by multiplying by -1.

Multiplying a comparison result by -1 is a known anti-pattern because it can fail if the underlying comparer returns int.MinValue (-int.MinValue == int.MinValue due to integer overflow). The idiomatic and safe way to reverse the sort order is to swap the arguments, which is already correctly done in SortByPresentation.

♻️ Proposed refactor
         private class ItemComparator : IComparer<ValueListItem>
         {
             readonly GenericIValueComparer _comparer;
-            readonly int _direction;
+            readonly bool _ascending;
 
             public ItemComparator(IBslProcess process, bool ascending = true)
             {
                 _comparer = new GenericIValueComparer(process);
-                _direction = ascending ? 1 : -1;
+                _ascending = ascending;
             }
 
             public int Compare(ValueListItem x, ValueListItem y)
             {
-                return _comparer.Compare(x.Value, y.Value) * _direction;
+                return _ascending ? _comparer.Compare(x.Value, y.Value) : _comparer.Compare(y.Value, x.Value);
             }
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs` around
lines 330 - 345, Update ItemComparator.Compare to avoid multiplying the comparer
result by _direction; select the argument order passed to
GenericIValueComparer.Compare based on the requested ascending or descending
order, preserving ascending behavior and safely reversing descending
comparisons.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs`:
- Around line 157-173: Update CreateNewListItem so a null presentation argument
is normalized to string.Empty before assigning ValueListItem.Presentation.
Preserve the supplied presentation text for non-null values and keep the
existing value adjustment and item construction behavior unchanged.

---

Nitpick comments:
In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs`:
- Around line 396-411: Convert the ValueListImpl factory-style methods
Constructor, IndexedIsReadonlyException, and ElementDoesntBelongException to
expression-bodied members, preserving their current return values and exception
messages.
- Around line 330-345: Update ItemComparator.Compare to avoid multiplying the
comparer result by _direction; select the argument order passed to
GenericIValueComparer.Compare based on the requested ascending or descending
order, preserving ascending behavior and safely reversing descending
comparisons.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ed10b209-ad13-4198-90c1-537f8abb0050

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd24f1 and a98bb3f.

📒 Files selected for processing (2)
  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs
  • tests/value-list.os

@Mr-Rm Mr-Rm requested a review from EvilBeaver July 16, 2026 11:41
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.

1 participant