Skip to content

Commit

Permalink
Merge branch 'main' into stdoutiocontext
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Mar 26, 2024
2 parents c2447ab + 1978e1b commit 811a25a
Show file tree
Hide file tree
Showing 32 changed files with 1,154 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
fail-fast: false
matrix:
# We test quite a lot of versions because we do some OS and version specific things unfortunately
julia-version: ["1.6", "1.8", "1.10", "nightly"] # "~1.11.0-0"]
julia-version: ["1.6", "1.10", "~1.11.0-0", "nightly"] # "~1.12.0-0"]
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>"]
version = "0.19.39"
version = "0.19.40"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/useEventListener.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect } from "../imports/Preact.js"

export const useEventListener = (
/** @type {Document | HTMLElement | Window | null} */ element,
/** @type {Document | HTMLElement | Window | EventSource | MediaQueryList | null} */ element,
/** @type {string} */ event_name,
/** @type {EventListenerOrEventListenerObject} */ handler,
/** @type {any[] | undefined} */ deps
Expand Down
7 changes: 7 additions & 0 deletions frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import { moveLineDown } from "../imports/CodemirrorPlutoSetup.js"

export const ENABLE_CM_MIXED_PARSER = window.localStorage.getItem("ENABLE_CM_MIXED_PARSER") === "true"
export const ENABLE_CM_SPELLCHECK = window.localStorage.getItem("ENABLE_CM_SPELLCHECK") === "true"
export const ENABLE_CM_AUTOCOMPLETE_ON_TYPE = window.localStorage.getItem("ENABLE_CM_AUTOCOMPLETE_ON_TYPE") === "true"

if (ENABLE_CM_MIXED_PARSER) {
console.log(`YOU ENABLED THE CODEMIRROR MIXED LANGUAGE PARSER
Expand All @@ -85,6 +86,12 @@ window.PLUTO_TOGGLE_CM_SPELLCHECK = (val = !ENABLE_CM_SPELLCHECK) => {
window.location.reload()
}

// @ts-ignore
window.PLUTO_TOGGLE_CM_AUTOCOMPLETE_ON_TYPE = (val = !ENABLE_CM_AUTOCOMPLETE_ON_TYPE) => {
window.localStorage.setItem("ENABLE_CM_AUTOCOMPLETE_ON_TYPE", String(val))
window.location.reload()
}

export const pluto_syntax_colors = HighlightStyle.define(
[
/* The following three need a specific version of the julia parser, will add that later (still messing with it 😈) */
Expand Down
290 changes: 162 additions & 128 deletions frontend/components/CellInput/pluto_autocomplete.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions frontend/components/CellInput/scopestate_statefield.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ export let explore_variable_usage = (
// Don't ask me why, but currently `do (x, y)` is parsed as `DoClauseArguments(ArgumentList(x, y))`
// while an actual argumentslist, `do x, y` is parsed as `DoClauseArguments(BareTupleExpression(x, y))`
let do_args_actually = do_args.firstChild
if (do_args_actually.name === "Identifier") {
if (do_args_actually?.name === "Identifier") {
inner_scope = scopestate_add_definition(inner_scope, doc, do_args_actually)
} else if (do_args_actually.name === "ArgumentList") {
} else if (do_args_actually?.name === "ArgumentList") {
for (let child of child_nodes(do_args_actually)) {
inner_scope = explorer_function_definition_argument(child, doc, inner_scope)
}
} else if (do_args_actually.name === "BareTupleExpression") {
} else if (do_args_actually?.name === "BareTupleExpression") {
for (let child of child_nodes(do_args_actually)) {
inner_scope = explorer_function_definition_argument(child, doc, inner_scope)
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/components/CellOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ const execute_scripttags = async ({ root_node, script_nodes, previous_results_ma
// @ts-ignore
getPublishedObject: (id) => cell.getPublishedObject(id),

_internal_getJSLinkResponse: (cell_id, link_id) => (input) =>
pluto_actions.request_js_link_response(cell_id, link_id, input).then(([success, result]) => {
if (success) return result
throw result
}),
getBoundElementValueLikePluto: get_input_value,
setBoundElementValueLikePluto: set_input_value,
getBoundElementEventNameLikePluto: eventof,
Expand Down
13 changes: 13 additions & 0 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,19 @@ export class Editor extends Component {
false
)
},
request_js_link_response: (cell_id, link_id, input) => {
return this.client
.send(
"request_js_link_response",
{
cell_id,
link_id,
input,
},
{ notebook_id: this.state.notebook.notebook_id }
)
.then((r) => r.message)
},
/** This actions avoids pushing selected cells all the way down, which is too heavy to handle! */
get_selected_cells: (cell_id, /** @type {boolean} */ allow_other_selected_cells) =>
allow_other_selected_cells ? this.state.selected_cells : [cell_id],
Expand Down
18 changes: 14 additions & 4 deletions frontend/components/ExportBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ export const ExportBanner = ({ notebook_id, print_title, open, onClose, notebook
useEventListener(
window,
"beforeprint",
() => {
console.log("beforeprint")
print_old_title_ref.current = document.title
document.title = print_title.replace(/\.jl$/, "").replace(/\.plutojl$/, "")
(e) => {
if (!e.detail?.fake) {
print_old_title_ref.current = document.title
document.title = print_title.replace(/\.jl$/, "").replace(/\.plutojl$/, "")
}
},
[print_title]
)
Expand All @@ -79,6 +80,15 @@ export const ExportBanner = ({ notebook_id, print_title, open, onClose, notebook
},
[print_title]
)
// https://github.com/codemirror/dev/issues/1354
useEventListener(
window.matchMedia("print"),
"change",
() => {
// window.dispatchEvent(new CustomEvent("beforeprint", { detail: { fake: true } }))
},
[]
)

const element_ref = useRef(/** @type {HTMLDialogElement?} */ (null))

Expand Down
16 changes: 9 additions & 7 deletions frontend/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ dialog#export {
height: 130px;
background: var(--export-bg-color);
color: var(--export-color);
transform: translateY(-100%);
transform: translateY(calc(-100% - 1px));
/* overlay: none !important; */
overflow: visible;
margin: 0;
Expand Down Expand Up @@ -1744,21 +1744,20 @@ pluto-input > .input_context_menu ul {

pluto-input {
position: relative;
display: block;
}
pluto-input > div.input_context_menu {
left: 100%;
top: -8px;
position: absolute;
z-index: 1400;
}
@media screen and (min-width: 921px) {
pluto-input > div.input_context_menu {
left: calc(100% - 3px);
}
}
@media screen and (max-width: 920px) {
pluto-input > div.input_context_menu {
z-index: 1400;
}
pluto-input > div.input_context_menu {
right: 0px;
left: unset;
Expand Down Expand Up @@ -3007,7 +3006,6 @@ pluto-log-dot-positioner {
--accent-color: var(--pluto-logs-info-accent-color);
--icon-image: unset;
background: var(--bg-color);
color: var(--accent-color);
margin: 2px;
border-radius: 6px;
/* border: 2px solid var(--accent-color); */
Expand All @@ -3017,8 +3015,8 @@ pluto-log-dot-positioner {
background-size: 200% 100%;
}

pluto-log-dot-positioner:last-child {
/* border-bottom: none; */
pluto-log-dot > pre {
color: var(--accent-color);
}

pluto-log-truncated {
Expand Down Expand Up @@ -3471,6 +3469,10 @@ pluto-cell.errored .cm-editor .cm-lineNumbers .cm-gutterElement::after {
color: var(--cm-string-color);
}

.cm-completionIcon-completion_keyword::before {
color: var(--cm-keyword-color);
}

.cm-completionIcon-c_Any::before,
pluto-output > assignee,
pluto-popup code.auto_disabled_variable {
Expand Down
4 changes: 4 additions & 0 deletions frontend/treeview.css
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ jlerror li .frame-line-preview pre:not(.asdfdsaf) {
border-radius: var(--br);
overflow: hidden;
position: relative;
display: block;
}

jlerror li:not(.from_this_cell) .frame-line-preview pre::after {
Expand All @@ -353,6 +354,9 @@ jlerror li:not(.from_this_cell) .frame-line-preview pre::after {
opacity: 0.6;
}

jlerror li .frame-line-preview pre > code {
padding: 0;
}
jlerror li .frame-line-preview pre > code:not(:only-child).frame-line {
background: var(--cm-highlighted);
}
Expand Down
5 changes: 3 additions & 2 deletions src/evaluation/Run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ function run_reactive_core!(
new_errable = keys(new_order.errable)
to_delete_vars = union!(to_delete_vars, defined_variables(new_topology, new_errable)...)
to_delete_funcs = union!(to_delete_funcs, defined_functions(new_topology, new_errable)...)

cells_to_macro_invalidate = Set{UUID}(c.cell_id for c in cells_with_deleted_macros(old_topology, new_topology))
cells_to_js_link_invalidate = Set{UUID}(c.cell_id for c in union!(Set{Cell}(), to_run, new_errable, indirectly_deactivated))

module_imports_to_move = reduce(all_cells(new_topology); init=Set{Expr}()) do module_imports_to_move, c
c to_run && return module_imports_to_move
Expand All @@ -156,7 +157,7 @@ function run_reactive_core!(

if will_run_code(notebook)
to_delete_funcs_simple = Set{Tuple{UUID,Tuple{Vararg{Symbol}}}}((id, name.parts) for (id,name) in to_delete_funcs)
deletion_hook((session, notebook), old_workspace_name, nothing, to_delete_vars, to_delete_funcs_simple, module_imports_to_move, cells_to_macro_invalidate; to_run) # `deletion_hook` defaults to `WorkspaceManager.move_vars`
deletion_hook((session, notebook), old_workspace_name, nothing, to_delete_vars, to_delete_funcs_simple, module_imports_to_move, cells_to_macro_invalidate, cells_to_js_link_invalidate; to_run) # `deletion_hook` defaults to `WorkspaceManager.move_vars`
end

foreach(v -> delete!(notebook.bonds, v), to_delete_vars)
Expand Down
3 changes: 2 additions & 1 deletion src/evaluation/RunBonds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function set_bond_values_reactive(;
bond_value_pairs = zip(syms_to_set, new_values)

syms_to_set_set = Set{Symbol}(syms_to_set)
function custom_deletion_hook((session, notebook)::Tuple{ServerSession,Notebook}, old_workspace_name, new_workspace_name, to_delete_vars::Set{Symbol}, methods_to_delete, module_imports_to_move, cells_to_macro_invalidate; to_run)
function custom_deletion_hook((session, notebook)::Tuple{ServerSession,Notebook}, old_workspace_name, new_workspace_name, to_delete_vars::Set{Symbol}, methods_to_delete, module_imports_to_move, cells_to_macro_invalidate, cells_to_js_link_invalidate; to_run)
to_delete_vars = union(to_delete_vars, syms_to_set_set) # also delete the bound symbols
WorkspaceManager.move_vars(
(session, notebook),
Expand All @@ -51,6 +51,7 @@ function set_bond_values_reactive(;
methods_to_delete,
module_imports_to_move,
cells_to_macro_invalidate,
cells_to_js_link_invalidate,
syms_to_set_set,
)
set_bond_value_pairs!(session, notebook, zip(syms_to_set, new_values))
Expand Down
10 changes: 7 additions & 3 deletions src/evaluation/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ function move_vars(
methods_to_delete::Set{Tuple{UUID,Tuple{Vararg{Symbol}}}},
module_imports_to_move::Set{Expr},
cells_to_macro_invalidate::Set{UUID},
cells_to_js_link_invalidate::Set{UUID},
keep_registered::Set{Symbol}=Set{Symbol}();
kwargs...
)
Expand All @@ -570,6 +571,7 @@ function move_vars(
$methods_to_delete,
$module_imports_to_move,
$cells_to_macro_invalidate,
$cells_to_js_link_invalidate,
$keep_registered,
)
end)
Expand All @@ -580,16 +582,18 @@ function move_vars(
to_delete::Set{Symbol},
methods_to_delete::Set{Tuple{UUID,Tuple{Vararg{Symbol}}}},
module_imports_to_move::Set{Expr},
cells_to_macro_invalidate::Set{UUID};
cells_to_macro_invalidate::Set{UUID},
cells_to_js_link_invalidate::Set{UUID};
kwargs...
)
move_vars(
session_notebook,
bump_workspace_module(session_notebook)...,
to_delete,
to_delete,
methods_to_delete,
module_imports_to_move,
cells_to_macro_invalidate;
cells_to_macro_invalidate,
cells_to_js_link_invalidate;
kwargs...
)
end
Expand Down
4 changes: 2 additions & 2 deletions src/notebook/Notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Base.@kwdef mutable struct Notebook
# per notebook compiler options
# nothing means to use global session compiler options
compiler_options::Union{Nothing,Configuration.CompilerOptions}=nothing
# nbpkg_ctx::Union{Nothing,PkgContext}=nothing
nbpkg_ctx::Union{Nothing,PkgContext}=PkgCompat.create_empty_ctx()
nbpkg_ctx::Union{Nothing,PkgContext}=nothing
# nbpkg_ctx::Union{Nothing,PkgContext}=PkgCompat.create_empty_ctx()
nbpkg_ctx_instantiated::Bool=false
nbpkg_restart_recommended_msg::Union{Nothing,String}=nothing
nbpkg_restart_required_msg::Union{Nothing,String}=nothing
Expand Down
27 changes: 22 additions & 5 deletions src/packages/PkgCompat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ module PkgCompat

export package_versions, package_completions

import REPL
import Pkg
import Pkg.Types: VersionRange
import RegistryInstances
import ..Pluto




@static if isdefined(Pkg,:REPLMode) && isdefined(Pkg.REPLMode,:complete_remote_package)
const REPLMode=Pkg.REPLMode
else
const REPLMode = Base.get_extension(Pkg, :REPLExt)
end

# Should be in Base
flatmap(args...) = vcat(map(args...)...)

Expand Down Expand Up @@ -171,14 +181,15 @@ _get_registries() = RegistryInstances.reachable_registries()

# (✅ "Public" API using RegistryInstances)
"The cached output value of `_get_registries`."
const _parsed_registries = Ref(_get_registries())
const _parsed_registries = Ref(RegistryInstances.RegistryInstance[])

# (✅ "Public" API using RegistryInstances)
"Re-parse the installed registries from disk."
function refresh_registry_cache()
_parsed_registries[] = _get_registries()
end


# ⚠️✅ Internal API with fallback
const _updated_registries_compat = @static if isdefined(Pkg, :UPDATED_REGISTRY_THIS_SESSION) && Pkg.UPDATED_REGISTRY_THIS_SESSION isa Ref{Bool}
Pkg.UPDATED_REGISTRY_THIS_SESSION
Expand Down Expand Up @@ -264,7 +275,13 @@ end
# ⚠️ Internal API with fallback
is_stdlib(package_name::AbstractString) = package_name _stdlibs()

global_ctx = PkgContext()


# Initial fill of registry cache
function __init__()
refresh_registry_cache()
global global_ctx=PkgContext()
end

###
# Package names
Expand All @@ -282,10 +299,10 @@ end
function _registered_package_completions(partial_name::AbstractString)::Vector{String}
# compat
try
@static if hasmethod(Pkg.REPLMode.complete_remote_package, (String,))
Pkg.REPLMode.complete_remote_package(partial_name)
@static if hasmethod(REPLMode.complete_remote_package, (String,))
REPLMode.complete_remote_package(partial_name)
else
Pkg.REPLMode.complete_remote_package(partial_name, 1, length(partial_name))[1]
REPLMode.complete_remote_package(partial_name, 1, length(partial_name))[1]
end
catch e
@warn "Pkg compat: failed to autocomplete packages" exception=(e,catch_backtrace())
Expand Down
14 changes: 7 additions & 7 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ PrecompileTools.@compile_workload begin
Pluto.topological_order(topology, topology.cell_order)
end

let
io = IOBuffer()
# Notebook file format.
Pluto.save_notebook(io, nb)
seekstart(io)
Pluto.load_notebook_nobackup(io, "whatever.jl")
end
# let
# io = IOBuffer()
# # Notebook file format.
# Pluto.save_notebook(io, nb)
# seekstart(io)
# Pluto.load_notebook_nobackup(io, "whatever.jl")
# end

let
state1 = Pluto.notebook_to_js(nb)
Expand Down
Loading

0 comments on commit 811a25a

Please sign in to comment.