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

Template rendering MVP #322

Merged
merged 2 commits into from
Jul 12, 2020
Merged

Template rendering MVP #322

merged 2 commits into from
Jul 12, 2020

Conversation

GeorgeSG
Copy link
Contributor

@GeorgeSG GeorgeSG commented May 8, 2020

👋 Hi,

I saw your idea in the README to "Render Jinja2 template locally (like/via CLI?) in preview pane". I agree it'll be really useful :)

I didn't do exactly that (it's not local), but this PR implements an initial version of Template Rendering.

Overview

To render templates, I use Home Assistant's /api/template endpoint. I reused the existing infrastructure to get request/responses out of the server, and the rest was really easy to do.

The workflow is mostly the same as error logs:

  • Registers the vscode-home-assistant.renderTemplate command. Adds it for command palette and editor/context menu. The command is available only when there is active text selection.
  • renderTemplate gets the text selection from the active window and sends a clientRequest to the LanguageClient
  • on request, LanguageClient constructs a request and sends it to HA
  • on response and a render_template_completed notification, show a new Output CHannel - "Home Assistant Template Renderer"
  • the Output Channel is cleared on each new request.

I had to add an optional body argument to HaConnection.callApi.

Preview

2020-05-08 21 51 56

To do

There's probably a better way to present the input/output data than what I've done with the Output Channel.

I know you mentioned a preview pane, but I tried working with vscode's WebviewPanel and I don't think it was more convenient.

I think this should be good enough for an initial version and hopefully someone else can take it from here and improve the presentation :)

@stale
Copy link

stale bot commented Jul 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jul 8, 2020
@keesschollaart81 keesschollaart81 changed the base branch from master to dev July 12, 2020 17:17
@stale stale bot removed the wontfix This will not be worked on label Jul 12, 2020
@keesschollaart81 keesschollaart81 merged commit 95c615b into keesschollaart81:dev Jul 12, 2020
@GeorgeSG GeorgeSG deleted the add-template-rendering branch July 13, 2020 11:47
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