Skip to content
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

fixes for 0.7 #671

Merged
merged 20 commits into from
Jul 6, 2018
Merged

fixes for 0.7 #671

merged 20 commits into from
Jul 6, 2018

Conversation

fredrikekre
Copy link
Member

@fredrikekre fredrikekre commented Jul 5, 2018

This is #623 + #667 + two additional fixes. Closes #661, #654, #637.

This PR works locally on both 0.7 and 0.6 for me, would be great to get IJulia to work properly on 0.7!

src/inline.jl Outdated
@@ -1,6 +1,9 @@
import Base: display, redisplay

immutable InlineDisplay <: Display end
@static if !isdefined(Base, :AbstractDisplay) # remove when Compat.jl#482 is merged and tagged
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

if !isdefined(Base, :AbstractDisplay) && !isdefined(Compat, :AbstractDisplay)
  ...

(No need for @static in global scope unless the expressions have ccall or macros...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this if statement can be deleted completely as the AbstractDisplay definition was tagged in Compat v0.52.0

@stevengj
Copy link
Member

stevengj commented Jul 5, 2018

Great, thanks for working on this! Sorry I haven't had time to bang on it.

Do things like println now work in both 0.6 and 0.7?

@fredrikekre
Copy link
Member Author

Pushed one more deprecation fix and updated to use Compat.AbstractDisplay directly.

Do things like println now work in both 0.6 and 0.7?

Yes! 🎉

src/stdio.jl Outdated
logger = Base.CoreLogging._global_logstate.logger

# Override logging if it's pointing at the default stderr
if logger.stream == Base.stderr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, there is something bugged here; this is only true on the first call, don't we need to reset it somewhere @staticfloat ? On this branch; with a @show logger.stream == Base.stderr inserted:

julia> using IJulia

julia> mktemp() do path, io
           redirect_stderr(IJulia.IJuliaStdio(io, "stderr")) do
               @warn("warn")
           end
           flush(io)
           seek(io, 0)
           @show read(io, String)
       end
logger.stream == Base.stderr = true
read(io, String) = "\e[33m\e[1m┌ \e[22m\e[39m\e[33m\e[1mWarning: \e[22m\e[39mwarn\n\e[33m\e[1m└ \e[22m\e[39m\e[90m@ Main REPL[2]:3\e[39m\n"
"\e[33m\e[1m┌ \e[22m\e[39m\e[33m\e[1mWarning: \e[22m\e[39mwarn\n\e[33m\e[1m└ \e[22m\e[39m\e[90m@ Main REPL[2]:3\e[39m\n"

julia> mktemp() do path, io
           redirect_stderr(IJulia.IJuliaStdio(io, "stderr")) do
               @warn("warn")
           end
           flush(io)
           seek(io, 0)
           @show read(io, String)
       end
logger.stream == Base.stderr = false
read(io, String) = ""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it does not matter; this seems to be called only once per session anyways and it works in a notebook
warning

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be simpler to just replace the global logger instead of checking the internal state?

@fredrikekre
Copy link
Member Author

I updated the logging redirect, now things seem to work:
working

src/handlers.jl Outdated
@@ -138,7 +138,7 @@ function complete_request(socket, msg)

codestart = find_parsestart(code, cursorpos)
comps, positions = Base.REPLCompletions.completions(code[codestart:end], cursorpos-codestart+1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need:

if VERSION < v"0.7.0-DEV.3500" # julia#25544
    import Base: REPLCompletions
else
    import REPL: REPLCompletions
end

above so that we can just call this as REPLCompletions.completions with no deprecation warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, there was a similar if VERSION check at the top so I added the imports there.

@fredrikekre
Copy link
Member Author

While trying the tab-completion for deprecations I got this

BoundsError: attempt to access 0-element Array{Int64,1} at index [0]

Seems to be a bug here

IJulia.jl/src/handlers.jl

Lines 144 to 145 in 90b0165

elseif isempty(positions) # true if comps to be inserted without replacement
cursor_start = (cursor_end = ind2chr(msg, code, last(positions)))
where we try to extract the last element although we just made sure it's empty.

@stevengj
Copy link
Member

stevengj commented Jul 6, 2018

Maybe should be cursor_start = cursor_end = cursor_chr, i.e. just merge it with the previous if clause to make it if isempty(comps) || isempty(positions)

(Or maybe we should use first(positions) instead of last? But probably there isn't any case where tab completion with an empty positions range wants to insert text at someplace other than the cursor location?)

src/handlers.jl Outdated
comps, positions = Base.REPLCompletions.completions(code[codestart:end], cursorpos-codestart+1)
positions += codestart-1
comps, positions = REPLCompletions.completions(code[codestart:end], cursorpos-codestart+1)
positions = positions .+ codestart-1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it is this fix that is missing a . on the - and the range turned into an array. Of course last works for an empty range.

src/handlers.jl Outdated
comps, positions = Base.REPLCompletions.completions(code[codestart:end], cursorpos-codestart+1)
positions += codestart-1
comps, positions = REPLCompletions.completions(code[codestart:end], cursorpos-codestart+1)
positions = positions .+ codestart .- 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, still not correct; this returns a Vector on Julia 0.6.

 - warn() -> at-warn
 - emtpy try-catch
 - remove_destination -> force
 - start -> firstindex
 - endof -> lastindex
 - broadcast +
@stevengj
Copy link
Member

stevengj commented Jul 6, 2018

LGTM, ready to merge?

@@ -198,7 +202,7 @@ function clear_history(indices)
end

# since a range could be huge, intersect it with 1:n first
clear_history{T<:Integer}(r::AbstractRange{T}) =
clear_history(r::AbstractRange{T}) where {T<:Integer} =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be clear_history(r::AbstractRange{<:Integer}) since we don't use T.

@@ -58,30 +56,50 @@ const displayqueue = Any[]

# remove x from the display queue
function undisplay(x)
i = findfirst(equalto(x), displayqueue)
if i > 0
i = findfirst(isequal(x), displayqueue)
Copy link
Member

@stevengj stevengj Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Compat.findfirst to get the version that returns nothing on 0.6? Then you can drop the i > 0 check.

function show_bt(io::IO, top_func::Symbol, t, set)
# follow PR #17570 code in removing top_func from backtrace
eval_ind = findlast(addr->Base.REPL.ip_matches_func(addr, top_func), t)
eval_ind != 0 && (t = t[1:eval_ind-1])
eval_ind = findlast(addr->ip_matches_func(addr, top_func), t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, use Compat.findlast and then you can skip the eval_ind != 0 check.

@stevengj
Copy link
Member

stevengj commented Jul 6, 2018

I'm just going to merge this as-is so that people can use IJulia with 0.7, and then add more fixes in another PR.

@stevengj stevengj merged commit 533ca5d into master Jul 6, 2018
@stevengj stevengj deleted the fe/nightly branch July 6, 2018 16:47
@stevengj stevengj mentioned this pull request Jul 6, 2018
@fredrikekre
Copy link
Member Author

Thanks! I have to admit that I did not review the changes from #623 myself.

@cstjean cstjean mentioned this pull request Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The kernel appears to have died. It will restart automatically Julia V0.7
4 participants