From e58e7720c5524819344e33ed023fcd850015c794 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Thu, 2 Dec 2021 18:38:47 +0200 Subject: [PATCH 1/5] Event listener implementation --- julia-runtime/run.jl | 30 ++++++++++++++++++------------ src/backend.ts | 4 ++-- src/extension.ts | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/julia-runtime/run.jl b/julia-runtime/run.jl index 8c48d4c..0e2b8ec 100644 --- a/julia-runtime/run.jl +++ b/julia-runtime/run.jl @@ -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( @@ -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" @@ -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() @@ -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) diff --git a/src/backend.ts b/src/backend.ts index b690084..186208c 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -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 diff --git a/src/extension.ts b/src/extension.ts index 4e881e8..e43e084 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 From 947fe406b0a7706ad336223b0cd6bca718707900 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Thu, 23 Dec 2021 16:14:55 +0200 Subject: [PATCH 2/5] Update/clean code --- julia-runtime/run.jl | 10 ++++++++++ src/extension.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/julia-runtime/run.jl b/julia-runtime/run.jl index 0e2b8ec..b19ff83 100644 --- a/julia-runtime/run.jl +++ b/julia-runtime/run.jl @@ -134,6 +134,16 @@ function event_listener(pe::Pluto.FileSaveEvent) 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.fileContent +# whenNotebookUpdates(pe.path, pe.fileContent) +# extensionData.textRepresentations[id] = pe.fileContent +# end +# end + extensionData.session.event_listener = event_listener ### @info "OPEN NOTEBOOK" diff --git a/src/extension.ts b/src/extension.ts index e43e084..f7710f6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 = "12fc15932cbb6ac3bc83e4d758b590f168d069c9" +export const PLUTO_BRANCH_NAME = "b1ada028a0c8a66de2cab211052681e05ed31203" /* HELLO From 82961359fbd63e1811136d2b95d69976ea972344 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Thu, 23 Dec 2021 17:24:46 +0200 Subject: [PATCH 3/5] Update to latest pluto events interface --- julia-runtime/run.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/julia-runtime/run.jl b/julia-runtime/run.jl index b19ff83..f8da436 100644 --- a/julia-runtime/run.jl +++ b/julia-runtime/run.jl @@ -128,9 +128,9 @@ 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 + if oldContent != pe.file_contents + whenNotebookUpdates(pe.path, pe.file_contents) + extensionData.textRepresentations[id] = pe.file_contents end end @@ -138,9 +138,9 @@ end # @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 +# if oldContent != pe.file_contents +# whenNotebookUpdates(pe.path, pe.file_contents) +# extensionData.textRepresentations[id] = pe.file_contents # end # end From 36d7f6196e499365a23834299b159a2d2f229f17 Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Thu, 23 Dec 2021 17:26:22 +0200 Subject: [PATCH 4/5] update branch name --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index f7710f6..80a1cd0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 = "b1ada028a0c8a66de2cab211052681e05ed31203" +export const PLUTO_BRANCH_NAME = "7f00dfd13ab19204fafa0a58d20c1808d0284d38" /* HELLO From 5e1e2d511462150217b83eadd7b8ca80df74485d Mon Sep 17 00:00:00 2001 From: Panagiotis Georgakopoulos Date: Wed, 6 Apr 2022 11:25:22 +0300 Subject: [PATCH 5/5] Update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e041d4..cf7dbcd 100644 --- a/package.json +++ b/package.json @@ -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",