Skip to content

Sync file with PlutoEvent interface #25

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 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,31 @@ 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.file_contents
whenNotebookUpdates(pe.path, pe.file_contents)
extensionData.textRepresentations[id] = pe.file_contents
end
end

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

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

Expand Down Expand Up @@ -168,16 +195,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 +219,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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pluto-vscode",
"displayName": "Pluto.jl (alpha preview)",
"description": "Pluto.jl inside VS Code",
"version": "0.1.1",
"version": "0.1.2",
"publisher": "juliacomputing",
"license": "MIT",
"icon": "media/favicon_unsaturated_bg_512.png",
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 = "7f00dfd13ab19204fafa0a58d20c1808d0284d38"

/*
HELLO
Expand Down