Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
👋 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:
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 theLanguageClient
LanguageClient
constructs a request and sends it to HArender_template_completed
notification, show a new Output CHannel - "Home Assistant Template Renderer"I had to add an optional
body
argument toHaConnection.callApi
.Preview
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 :)