Skip to content

Commit e58e772

Browse files
committed
Event listener implementation
1 parent 8aa982e commit e58e772

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

julia-runtime/run.jl

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ pluto_server_options = Pluto.Configuration.from_flat_kwargs(;
9999
# show_file_system=false,
100100
dismiss_update_notification = true,
101101
auto_reload_from_file = false,
102+
disable_writing_notebook_files = true,
102103
(Symbol(k) => v for (k, v) in JSON.parse(pluto_launch_params))...)
104+
103105
pluto_server_session = Pluto.ServerSession(;
104106
secret = secret,
105-
options = pluto_server_options
107+
options = pluto_server_options,
106108
)
107109

108110
extensionData = PlutoExtensionSessionData(
@@ -118,6 +120,21 @@ function whenNotebookUpdates(path, newString)
118120
sendCommand(path, newString)
119121
end
120122

123+
function event_listener(pe::Pluto.PlutoEvent)
124+
@info "Overriden PlutoEvent for" pe.path
125+
end
126+
127+
function event_listener(pe::Pluto.FileSaveEvent)
128+
@info "Overriden filesave event for" pe.path
129+
id = string(pe.notebook.notebook_id)
130+
oldContent = get(extensionData.textRepresentations, id, "")
131+
if oldContent != pe.fileContent
132+
whenNotebookUpdates(pe.path, pe.fileContent)
133+
extensionData.textRepresentations[id] = pe.fileContent
134+
end
135+
end
136+
137+
extensionData.session.event_listener = event_listener
121138
###
122139
@info "OPEN NOTEBOOK"
123140

@@ -168,16 +185,6 @@ try ## Note: This is to assist with co-developing Pluto & this Extension
168185
catch
169186
end
170187

171-
function registerOnFileSaveListener(notebook::Pluto.Notebook)
172-
function onfilechange(pe::Pluto.PlutoEvent)
173-
if pe isa Pluto.FileSaveEvent
174-
whenNotebookUpdates(pe.path, pe.fileContent)
175-
end
176-
end
177-
notebook.write_out_fs = false
178-
notebook.listeners = [onfilechange, notebook.listeners...]
179-
end
180-
181188
command_task = Pluto.@asynclog while true
182189
filenbmap = extensionData.notebooks
183190
new_command = getNextSTDINCommand()
@@ -202,7 +209,6 @@ command_task = Pluto.@asynclog while true
202209

203210
jlpath = detail["fsPath"] # joinpath(extensionData.jlfilesroot, detail["jlfile"])
204211
nb = Pluto.SessionActions.open(pluto_server_session, jlpath; notebook_id = UUID(detail["notebook_id"]))
205-
registerOnFileSaveListener(nb)
206212
filenbmap[detail["jlfile"]] = nb
207213
generate_output(nb, editor_html_filename, vscode_proxy_root, frontend_params)
208214

src/backend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ export class PlutoBackend {
143143
this._server.listen(await this.localport);
144144

145145
this._process.stdout!.on("data", (data) => {
146-
const text = data.slice(0, data.length - 1)
146+
const text = data.slice(0)
147147

148148
console.log(`📈${text}`)
149149
})
150150

151151
this._process.stderr!.on("data", (data) => {
152-
const text = data.slice(0, data.length - 1)
152+
const text = data.slice(0)
153153

154154
console.log(`📈${text}`)
155155
// @info prints to stderr

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TextDecoder, TextEncoder } from "util"
66
import { v4 as uuid } from "uuid"
77

88
// this is a commit on the vscode-webview-proxy branch, see https://github.com/fonsp/Pluto.jl/pull/1493
9-
export const PLUTO_BRANCH_NAME = "376b08851906afc9e52e2c09e823de8d7e656675"
9+
export const PLUTO_BRANCH_NAME = "12fc15932cbb6ac3bc83e4d758b590f168d069c9"
1010

1111
/*
1212
HELLO

0 commit comments

Comments
 (0)