Skip to content

Comments

DIY widget: autocomplete provide data-lake variables#2109

Merged
rafaellehmkuhl merged 3 commits intobluerobotics:masterfrom
mahdikarami8484:widgets-DIY-autocomplete
Sep 11, 2025
Merged

DIY widget: autocomplete provide data-lake variables#2109
rafaellehmkuhl merged 3 commits intobluerobotics:masterfrom
mahdikarami8484:widgets-DIY-autocomplete

Conversation

@mahdikarami8484
Copy link
Contributor

DIY widget autocomplete Provide Data-Lake Variables

Summary

Added intelligent autocomplete support for JavaScript in Monaco Editor that suggests variables from window.cockpit.dataLakeVariableData with proper documentation and insertion templates.

Changes

  • Registered a completion item provider for JavaScript language
  • Configured trigger character '(' to activate autocomplete
  • Implemented dynamic suggestion generation from data-lake variables

Technical Details

  • Range Detection: Uses getWordUntilPosition() to identify the current word boundary for precise text replacement
  • Dynamic Suggestions: Maps object entries to completion items with proper formatting
  • Documentation: Displays variable name, current value, and type in tooltips
  • Insertion Template: Generates proper JavaScript access syntax (window.cockpit.dataLakeVariableData['variableName'])

Benefits

  • Improves developer productivity with context-aware suggestions
  • Reduces errors by providing correct access syntax
  • Enhances code discovery with real-time value documentation
  • Maintains consistency in variable access patterns

Usage

Developers can now autocomplete cockpit variables by typing any character and selecting from the suggested list, which includes current values and types for better context.

# DIY widget autocomplete Provide Data-Lake Variables

## Summary
Added intelligent autocomplete support for JavaScript in Monaco Editor that suggests variables from `window.cockpit.dataLakeVariableData` with proper documentation and insertion templates.

## Changes
- Registered a completion item provider for JavaScript language
- Configured trigger character '(' to activate autocomplete
- Implemented dynamic suggestion generation from data-lake variables

## Technical Details
- **Range Detection**: Uses `getWordUntilPosition()` to identify the current word boundary for precise text replacement
- **Dynamic Suggestions**: Maps object entries to completion items with proper formatting
- **Documentation**: Displays variable name, current value, and type in tooltips
- **Insertion Template**: Generates proper JavaScript access syntax (`window.cockpit.dataLakeVariableData['variableName']`)

## Benefits
- Improves developer productivity with context-aware suggestions
- Reduces errors by providing correct access syntax
- Enhances code discovery with real-time value documentation
- Maintains consistency in variable access patterns

## Usage
Developers can now autocomplete cockpit variables by typing any character and selecting from the suggested list, which includes current values and types for better context.
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl left a comment

Choose a reason for hiding this comment

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

Amazing contribution @mahdikarami8484!

Could we use the getDataLakeVariableData(...) method as the insert text instead of the direct object access? They do the same thing today, but if we end up implementing some logic in this getter in the future, it would be better if this auto-completion is already using it.

i use getAllDataLakeVariablesInfo and getDataLakeVariableData instead of dataLakeVariableData
@mahdikarami8484
Copy link
Contributor Author

Thank you so much for the encouragement! Yes, I did it.
@rafaellehmkuhl

2025-09-07.11-05-02.1.mp4

@mahdikarami8484
Copy link
Contributor Author

I fixed the ESLint problem! 😅

@rafaellehmkuhl
Copy link
Member

Amazing @mahdikarami8484! I've tested it already and everything is working perfectly. Thanks for the updates!

I plan to release our v1.16.0 stable tomorrow and merge your PR right after that, so it enters our v1.17.0 beta cycle :)

Copy link
Member

@rafaellehmkuhl rafaellehmkuhl left a comment

Choose a reason for hiding this comment

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

Nice work :)

@rafaellehmkuhl rafaellehmkuhl merged commit bc2f556 into bluerobotics:master Sep 11, 2025
12 checks passed
@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-needed Change needs to be documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants