Skip to content

Commit

Permalink
Event listener implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pankgeorg committed Dec 2, 2021
1 parent 8aa982e commit e58e772
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
30 changes: 18 additions & 12 deletions julia-runtime/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ pluto_server_options = Pluto.Configuration.from_flat_kwargs(;
# show_file_system=false,
dismiss_update_notification = true,
auto_reload_from_file = false,
disable_writing_notebook_files = true,
(Symbol(k) => v for (k, v) in JSON.parse(pluto_launch_params))...)

pluto_server_session = Pluto.ServerSession(;
secret = secret,
options = pluto_server_options
options = pluto_server_options,
)

extensionData = PlutoExtensionSessionData(
Expand All @@ -118,6 +120,21 @@ function whenNotebookUpdates(path, newString)
sendCommand(path, newString)
end

function event_listener(pe::Pluto.PlutoEvent)
@info "Overriden PlutoEvent for" pe.path
end

function event_listener(pe::Pluto.FileSaveEvent)
@info "Overriden filesave event for" pe.path
id = string(pe.notebook.notebook_id)
oldContent = get(extensionData.textRepresentations, id, "")
if oldContent != pe.fileContent
whenNotebookUpdates(pe.path, pe.fileContent)
extensionData.textRepresentations[id] = pe.fileContent
end
end

extensionData.session.event_listener = event_listener
###
@info "OPEN NOTEBOOK"

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

function registerOnFileSaveListener(notebook::Pluto.Notebook)
function onfilechange(pe::Pluto.PlutoEvent)
if pe isa Pluto.FileSaveEvent
whenNotebookUpdates(pe.path, pe.fileContent)
end
end
notebook.write_out_fs = false
notebook.listeners = [onfilechange, notebook.listeners...]
end

command_task = Pluto.@asynclog while true
filenbmap = extensionData.notebooks
new_command = getNextSTDINCommand()
Expand All @@ -202,7 +209,6 @@ command_task = Pluto.@asynclog while true

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

Expand Down
4 changes: 2 additions & 2 deletions src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ export class PlutoBackend {
this._server.listen(await this.localport);

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

console.log(`📈${text}`)
})

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

console.log(`📈${text}`)
// @info prints to stderr
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TextDecoder, TextEncoder } from "util"
import { v4 as uuid } from "uuid"

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

/*
HELLO
Expand Down

0 comments on commit e58e772

Please sign in to comment.