Skip to content

Commit 8ef154b

Browse files
committed
PLUG_EDITOR
1 parent c3b13a1 commit 8ef154b

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ window.addEventListener("phx:live_reload:connected", ({detail: reloader}) => {
4949

5050
## Jumping to HEEx function definitions
5151

52-
Many times it's useful to inspect the HTML DOM tree to find where markup is being rendered from within your application. HEEx supports annotating rendered HTML with HTML comments that give you the file/line of a HEEx function component. `:phoenix_live_reload` will look for the `ELIXIR_EDITOR_URL` environment export to launch a configured URL of your choice to open your code editor to the file-line of the HTML annotation. For example, the following export on your system would open vscode at the correct file/line:
52+
Many times it's useful to inspect the HTML DOM tree to find where markup is being rendered from within your application. HEEx supports annotating rendered HTML with HTML comments that give you the file/line of a HEEx function component. `:phoenix_live_reload` will look for the `PLUG_EDITOR` environment export to launch a configured URL of your choice to open your code editor to the file-line of the HTML annotation. For example, the following export on your system would open vscode at the correct file/line:
5353

5454
```
55-
export ELIXIR_EDITOR_URL="vscode://file/__FILE__:__LINE__"
55+
export PLUG_EDITOR="vscode://file/__FILE__:__LINE__"
5656
```
5757

5858
The `vscode://` protocol URL will open vscode with placeholders of `__FILE__:__LINE__` substited at runtime. Check your editor's documentation on protocol URL support. To open your configured editor URL when an element is clicked, say with alt-click, you can wire up an event listener within your `"phx:live_reload:connected"` callback and make use of the reloader's `openEditor` function, passing the event target as the DOM node to reference for HEEx file:line annotation information. For example:
@@ -61,7 +61,7 @@ The `vscode://` protocol URL will open vscode with placeholders of `__FILE__:__L
6161
window.addEventListener("phx:live_reload:connected", ({detail: reloader}) => {
6262
// enable server log streaming to client.
6363
reloader.enableServerLogs() // disable with reloader.disableServerLogs()
64-
// open configured ELIXIR_EDITOR_URL at file:line of the alt-clicked element's HEEx component
64+
// open configured PLUG_EDITOR at file:line of the alt-clicked element's HEEx component
6565
window.addEventListener("click", e => {
6666
if(!e.altKey){ return }
6767
e.preventDefault()

lib/phoenix_live_reload/channel.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ defmodule Phoenix.LiveReloader.Channel do
113113
end
114114

115115
defp join_info do
116-
if url = System.get_env("ELIXIR_EDITOR_URL") do
116+
if url = System.get_env("PLUG_EDITOR") do
117117
%{editor_url: url, relative_path: File.cwd!()}
118118
else
119119
%{}

lib/phoenix_live_reload/live_reloader.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ defmodule Phoenix.LiveReloader do
7575
*Note*: your appplication javascript bundle will need to enable logs.
7676
See the README for more information.
7777
78-
* `:elixir_editor_url` - The protocol URL of your elixir editor for opening HEEx
79-
files from annotated file:line comments. Defaults to `nil`.
80-
*Note*: your appplication javascript bundle will need to wire up invocation.
81-
See the README for more information.
82-
8378
In an umbrella app, if you want to enable live reloading based on code
8479
changes in sibling applications, set the `reloadable_apps` option on your
8580
endpoint to ensure the code will be recompiled, then add the dirs to

priv/static/phoenix_live_reload.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class LiveReloader {
8989

9090
openEditor(targetNode){
9191
if(!this.editorURL){
92-
return console.error("phoenix_live_reload cannot openEditor without configured ELIXIR_EDITOR_URL")
92+
return console.error("phoenix_live_reload cannot openEditor without configured PLUG_EDITOR")
9393
}
9494

9595
let fileLine = this.closestDebugFileLine(targetNode)

test/channel_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ defmodule Phoenix.LiveReloader.ChannelTest do
109109

110110
@endpoint MyApp.LogEndpoint
111111
test "sends logs for web console only when enabled" do
112-
System.delete_env("ELIXIR_EDITOR_URL")
112+
System.delete_env("PLUG_EDITOR")
113113
update_live_reload_env(@endpoint, fn conf ->
114114
Keyword.drop(conf, [:web_console_logger])
115115
end)
@@ -137,14 +137,14 @@ defmodule Phoenix.LiveReloader.ChannelTest do
137137
end
138138

139139
test "sends editor_url and relative_path only when configurd" do
140-
System.delete_env("ELIXIR_EDITOR_URL")
140+
System.delete_env("PLUG_EDITOR")
141141

142142
{:ok, info, _socket} =
143143
LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{})
144144

145145
assert info == %{}
146146

147-
System.put_env("ELIXIR_EDITOR_URL", "vscode://file/__FILE__:__LINE__")
147+
System.put_env("PLUG_EDITOR", "vscode://file/__FILE__:__LINE__")
148148

149149
{:ok, info, _socket} =
150150
LiveReloader.Socket |> socket() |> subscribe_and_join(Channel, "phoenix:live_reload", %{})

0 commit comments

Comments
 (0)