Skip to content

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

Merged
EvilBeaver merged 11 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-valuelist
Aug 7, 2026
Merged

Исправления и добавления в СписокЗначений#1710
EvilBeaver merged 11 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 normalize stored values by type and optionally restrict them to allowed values.
    • Value list items now retain unique identifiers through creation, loading, deletion, and sorting.
    • Type descriptions render as readable comma-separated lists.
  • Bug Fixes

    • Improved bounds validation and clearer errors for invalid or readonly operations.
    • Improved handling of items that do not belong to a list.
    • Value conversion and sorting now provide more consistent results.
  • Tests

    • Expanded coverage for indexes, value constraints, sorting, string conversion, and item identifiers.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b2d2fc10-0f7d-45b5-8c7e-4ef38a017a42

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9c00e and d1b4984.

📒 Files selected for processing (2)
  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs
  • tests/value-list.os
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/value-list.os
  • src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs

📝 Walkthrough

Walkthrough

ValueListImpl now normalizes values, validates indices and membership, assigns stable item identifiers, and sorts through GenericIValueComparer. ValueListItem, TypeDescription, and value-list tests cover revised string conversion and value-property behavior.

Changes

ValueList behavior

Layer / File(s) Summary
Value normalization and item representation
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs, src/OneScript.StandardLibrary/Collections/ValueList/ValueListItem.cs, src/OneScript.StandardLibrary/TypeDescriptions/TypeDescription.cs
Created and loaded items receive identifiers. Created values use ListValueType and AvailableValues. Null and undefined values have dedicated string output. TypeDescription.ToString() renders contained types.
Index validation, ownership, and sorting
src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs
Retrieval, insertion, lookup, and move operations validate bounds and membership. Localized exception factories handle readonly indexed values and non-member items. Sorting uses GenericIValueComparer.
ValueList behavior coverage
tests/value-list.os
Tests cover bounds errors, sorting, string conversion, ТипЗначения, ДоступныеЗначения, list conversion, loading, and item identifiers.

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 and identifier
  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 Заголовок точно описывает основные изменения в ValueList, включая исправления и добавление новых возможностей.
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
@EvilBeaver

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@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

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)

106-108: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Validate numeric indices before narrowing them.

GetValue narrows index.AsNumber() before checking _items.Count, and IndexByValue calls decimal.ToInt32 before the same check. Values outside the int range raise OverflowException instead of RuntimeException.IndexOutOfRange(). Validate the original numeric value as in-range before converting, and reject non-integral indices if only integer list positions are valid.

🤖 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 106 - 108, Update ValueListImpl.GetValue and IndexByValue so numeric
indexes are validated in their original numeric form before any narrowing
conversion; the current numericIndex and decimal.ToInt32 path can throw
OverflowException for values outside int range. First confirm the index is an
in-range integral list position, then convert and continue with the existing
_items.Count bounds check, preserving RuntimeException.IndexOutOfRange() for
invalid indices and rejecting non-integral values when only integer positions
are supported.
🤖 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 183-184: Update LoadValues to create each item through
CreateNewListItem rather than constructing ValueListItem and assigning Value
directly, so ListValueType and AvailableValues normalization matches Add and
Insert. Preserve the existing source ordering and ID assignment behavior.

---

Outside diff comments:
In `@src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs`:
- Around line 106-108: Update ValueListImpl.GetValue and IndexByValue so numeric
indexes are validated in their original numeric form before any narrowing
conversion; the current numericIndex and decimal.ToInt32 path can throw
OverflowException for values outside int range. First confirm the index is an
in-range integral list position, then convert and continue with the existing
_items.Count bounds check, preserving RuntimeException.IndexOutOfRange() for
invalid indices and rejecting non-integral values when only integer positions
are supported.
🪄 Autofix

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 Plus

Run ID: d821aa95-80b6-4286-bb26-d6fdea04d7b3

📥 Commits

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

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

Comment thread src/OneScript.StandardLibrary/Collections/ValueList/ValueListImpl.cs Outdated
@EvilBeaver
EvilBeaver merged commit 3a26ec7 into EvilBeaver:develop Aug 7, 2026
2 checks passed
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.

2 participants