Skip to content
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

Add entity id autocompletion to YAML code editors #11099

Merged
merged 13 commits into from Feb 4, 2022

Conversation

kubawolanin
Copy link
Contributor

@kubawolanin kubawolanin commented Jan 5, 2022

Breaking change

Proposed change

Add autocompletion to YAML code editors.
Accesses hass object and maps its states entity_id's as CodeMirror autocompletion labels.
This PR adds @codemirror/autocomplete package.

Autocompletion is not activated as editor's CodeMirror extension when:

  • component has a readOnly flag
  • component has no hasAutocomplete flag

Read more:
https://codemirror.net/6/docs/ref/#autocomplete.autocompletion
https://codemirror.net/6/examples/autocompletion/

Demo

autocomplete

autocomplete-template

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@kubawolanin kubawolanin marked this pull request as ready for review January 5, 2022 21:01
@zsarnett
Copy link
Contributor

I like this feature. I'll read up a bit more on the autocomplete and test with a lot of entities to see how the performance is.

@kubawolanin
Copy link
Contributor Author

kubawolanin commented Jan 11, 2022

Thanks @zsarnett, appreciate you taking a look.

test with a lot of entities to see how the performance is

Sure! Please note I've added maxRenderedOptions: 10, to the autocomplete plugin config having performance in mind, but also not to clutter the UI much.

Side note: I have a separate branch where I play a bit with ninja2-homeassistant extension. In the future our yaml/template editors may become more powerful 😎 But one step at a time

@zsarnett zsarnett self-assigned this Jan 24, 2022
@kubawolanin kubawolanin changed the title Add autocompletion to YAML code editors Add entity id autocompletion to YAML code editors Feb 3, 2022
@bramkragten
Copy link
Member

bramkragten commented Feb 3, 2022

When testing this, I got an error after every next char if autocomplete is open:

TypeError: Cannot read properties of undefined (reading 'breakAfter')
    at DocView.coordsAt (index.js?02d1:2628:1)
    at EditorView.coordsAtPos (index.js?02d1:6404:1)
    at eval (index.js?7cad:177:1)
    at Array.map (<anonymous>)
    at _codemirror_view__WEBPACK_IMPORTED_MODULE_1__.ViewPlugin.fromClass.eventHandlers.scroll.readMeasure (index.js?7cad:177:1)
    at eval (index.js?02d1:6043:1)
    at Array.map (<anonymous>)
    at EditorView.measure (index.js?02d1:6041:1)
    at eval (index.js?02d1:6158:1)
    at eval (timeline.js?905f:21:7)

And autocomplete would no longer work

@kubawolanin
Copy link
Contributor Author

kubawolanin commented Feb 3, 2022

When testing this, I got an error after every next char if autocomplete is open:

@bramkragten I think it's codemirror's bug:
https://discuss.codemirror.net/t/error-when-completing-brackets/3735

I've yet to find a solution

Edit: Thank you @bramkragten for fixing it in e56f313 <3

@frenck frenck added the Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Feb 3, 2022
@bramkragten
Copy link
Member

Updated the styling a bit, now looks like this:
image

bramkragten
bramkragten previously approved these changes Feb 3, 2022
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
@bramkragten bramkragten merged commit f474400 into home-assistant:dev Feb 4, 2022
@kubawolanin kubawolanin deleted the autocomplete branch February 4, 2022 10:10
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed Noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants