Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 4, 2025

Issue/Feature Request/Bug report

Changes

Molang queries like query.is_owner_identifier_any and query.equipped_item_all_tags accept variable numbers of arguments (n ≥ minimum), but the diagnoser was enforcing exact parameter counts and not validating parameter types.

Core data model (packages/molang/src/data/molang-function.ts):

  • Added repeatable?: boolean field to MolangParameter interface to mark parameters that can be repeated indefinitely
  • Removed complex minParams and repeatableParam fields from MolangFunction interface in favor of simpler per-parameter approach

Query definitions (packages/molang/src/data/general.ts):

  • Updated 16 queries with type annotations and repeatable: true on the last parameter:
    • Entity queries: is_owner_identifier_any, is_name_any (type: string, repeatable)
    • Equipment: equipped_item_all_tags, equipped_item_any_tag (slot: string, tag: string repeatable)
    • Block position + tags: block_has_all_tags, block_neighbor_has_all_tags, etc (xyz: float, tag: string repeatable)
    • Client: graphics_mode_is_any, last_input_mode_is_any (mode: string repeatable)
    • Item: is_item_name_any (slot: string, index: float, item: string repeatable)
    • Biome: entity_biome_has_all_tags, entity_biome_has_any_tags, etc (tag/identifier: string repeatable)

Diagnostics (packages/bedrock-diagnoser/src/diagnostics/molang/expressions.ts):

  • Updated validation to detect if the last parameter has repeatable: true
  • When repeatable parameter exists, validates minimum parameter count equals parameters.length
  • Added parameter type validation for both fixed and repeatable parameters
  • Validates argument types match expected types (string, float, boolean)
  • Provides detailed error messages: "wrong argument type at position X, expected Y but got Z"
  • Falls back to exact count check when no repeatable parameter exists (backward compatible)

Examples

Before:

q.is_owner_identifier_any('zombie', 'skeleton', 'creeper')
// ❌ Error: expected 2 arguments but got 3

q.block_has_all_tags(0, 0, 0, 2, 1)
// ✅ No validation error (incorrect!)

After:

q.is_owner_identifier_any('zombie', 'skeleton', 'creeper')  // ✅
q.equipped_item_all_tags('slot.weapon.mainhand', 'tag1', 'tag2', 'tag3')  // ✅
q.block_has_all_tags(0, 0, 0, 'stone', 'solid')  // ✅

q.block_has_all_tags(0, 0, 0, 2, 1)
// ❌ Error: wrong argument type at position 4, expected string but got float

New structure:

{
  id: 'equipped_item_all_tags',
  parameters: [
    { id: 'slot_name', type: 'string' },
    { id: 'tag', type: 'string', repeatable: true }
  ]
}

Checklist

  • It can build
  • The tests are passing (530 tests across packages)
  • Code has been reviewed
Original prompt

This section details on the original issue you should resolve

<issue_title>feat: additional molang parameter support</issue_title>
<issue_description>https://github.com/Xterionix/minecraft-bedrock-language-server/blob/main/packages/molang/src/data/general.ts#L1199

I'm thinking the solution could be either optional args or, the better option, allowing a query to essentially take n >= c amount of a certain argument.

query.equipped_item_all_tags follows a similar format

query.equipped_item_all_tags('slot.name', tag1, tag2, tag3, tag4 ...)
```</issue_description>

<agent_instructions>Can you update the molang data structure to allows for specifiying the minimum amount of parameters, and then update the diagnoser to check this value? so we can support parameters that can have an inifite amount</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@DaanV2</author><body>
Think that a parameter on the query would be good enough for this 👍 easy to check in the diagnoser</body></comment_new>
<comment_new><author>@DaanV2</author><body>
Im going to do something bold (I want to test it), going to see if I can have copilot do it</body></comment_new>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add additional Molang parameter support feat: support variable parameter counts in molang queries Nov 4, 2025
Copilot AI requested a review from DaanV2 November 4, 2025 14:45
Copilot finished work on behalf of DaanV2 November 4, 2025 14:45
@DaanV2 DaanV2 marked this pull request as ready for review November 4, 2025 14:52
@github-actions github-actions bot added dependencies Pull requests that update a dependency file release vscode ide packages labels Nov 4, 2025
@DaanV2
Copy link
Contributor

DaanV2 commented Nov 4, 2025

@Xterionix This looks okay, what do you think?

@Xterionix
Copy link
Contributor

Pretty close to what I wanted. Issue with just accounting for minParameter is that I was hoping to validate the value used.

Invalid

q.block_has_all_tags(0, 0, 0, 2, 1)

Valid

q.block_has_all_tags(0, 0, 0, 'stone', 'solid')

@DaanV2
Copy link
Contributor

DaanV2 commented Nov 5, 2025

Pretty close to what I wanted. Issue with just accounting for minParameter is that I was hoping to validate the value used.

Invalid

q.block_has_all_tags(0, 0, 0, 2, 1)

Valid

q.block_has_all_tags(0, 0, 0, 'stone', 'solid')

@copilot can you come up with a solutions for this? that we still want to be able to support an N amount of parameters that either have to be more molang, or strings/int/bools

Copy link
Contributor Author

Copilot AI commented Nov 5, 2025

Pretty close to what I wanted. Issue with just accounting for minParameter is that I was hoping to validate the value used.

Invalid
...

Added type validation for variable parameters in commit b8b406b.

The solution introduces a repeatableParam field to MolangFunction that specifies the type constraint for additional parameters beyond the minimum. For example:

{
  id: 'block_has_all_tags',
  parameters: [
    { id: 'x', type: 'float' },
    { id: 'y', type: 'float' },
    { id: 'z', type: 'float' },
    { id: 'tag', type: 'string' },
  ],
  minParams: 4,
  repeatableParam: { id: 'tag', type: 'string' }
}

Now q.block_has_all_tags(0, 0, 0, 2, 1) will error with "wrong argument type at position 4, expected string but got float" while q.block_has_all_tags(0, 0, 0, 'stone', 'solid') validates correctly.

Copilot AI changed the title feat: support variable parameter counts in molang queries feat: support variable parameter counts with type validation in molang queries Nov 5, 2025
Copilot finished work on behalf of DaanV2 November 5, 2025 09:43
@Xterionix
Copy link
Contributor

Xterionix commented Nov 5, 2025

I do think having to specify the type again is redundant. But if it works, it works I suppose. Would be better imo if you just could directly do something like

parameters: [
    ...
    { id: 'tag', type: 'string', repeatable: true },
  ]

or

parameters: [
    ...
    { id: 'tag', type: 'string' }
  ]
repeatable: 'tag' // Id of param that is being repeated

@DaanV2
Copy link
Contributor

DaanV2 commented Nov 11, 2025

@copilot I think we need to refactor, whereby we now do things differently for the field parameters:

Implement the following new structure:

{
  "parameters": [
    { "id": "tag 1", "type": "string" },
    { "id": "tag 2", "type": "string" },
    { "id": "tag 3", "type": "string", "repeatable": true }
  ]
}

Copy link
Contributor Author

Copilot AI commented Nov 11, 2025

@copilot I think we need to refactor, whereby we now do things differently for the field parameters:

Implement the following new structure:
...

Refactored to use the new structure in commit 12c4dc5.

The implementation now uses repeatable: true on the last parameter instead of separate minParams and repeatableParam fields:

{
  parameters: [
    { id: "slot_name", type: "string" },
    { id: "tag", type: "string", repeatable: true }
  ]
}

The diagnoser automatically detects if the last parameter is repeatable and validates accordingly. All 530 tests pass.

Copilot finished work on behalf of DaanV2 November 11, 2025 08:47
@DaanV2
Copy link
Contributor

DaanV2 commented Nov 11, 2025

@Xterionix I had copilot combine your thoughts and thinking it might have been more suitable as a field on the last parameter. Since its only the last parameter that is allowed to be repeated 🤔

Im happy enough to approve this and merge it if you are

@DaanV2 DaanV2 force-pushed the copilot/add-molang-parameter-support branch from 12c4dc5 to 06dbb48 Compare November 11, 2025 13:42
@Xterionix
Copy link
Contributor

Xterionix commented Nov 11, 2025

Looks good to me. And yeah that makes sense: last field is the only one that'll ever be repeatable

@DaanV2 DaanV2 merged commit b8d1e67 into main Nov 12, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file ide packages release vscode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: additional molang parameter support

3 participants