From 71d7b96d4861f32550e6a0daa87b6dfa053196a2 Mon Sep 17 00:00:00 2001 From: aviatesk Date: Sun, 8 Sep 2019 23:13:52 +0900 Subject: [PATCH] small refactors: - remove unnecessary field from DebuggerState - type structs in outline.jl - more const - remove union type from `makedescription` --- src/completions.jl | 1 + src/debugger/stepper.jl | 10 ++++------ src/frontend.jl | 2 +- src/outline.jl | 25 +++++++++++++------------ src/path_matching.jl | 6 +++--- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/completions.jl b/src/completions.jl index 714087ed..2f38f15b 100644 --- a/src/completions.jl +++ b/src/completions.jl @@ -160,6 +160,7 @@ function makedescription(docs) return strlimit(desc, 200) end end + return "" end completionurl(c) = "" diff --git a/src/debugger/stepper.jl b/src/debugger/stepper.jl index 6d3d2971..f02ed832 100644 --- a/src/debugger/stepper.jl +++ b/src/debugger/stepper.jl @@ -8,12 +8,11 @@ using MacroTools mutable struct DebuggerState frame::Union{Nothing, Frame} - result broke_on_error::Bool level::Int end -DebuggerState(frame::Frame) = DebuggerState(frame, nothing, false, 1) -DebuggerState() = DebuggerState(nothing, nothing, false, 1) +DebuggerState(frame::Frame) = DebuggerState(frame, false, 1) +DebuggerState() = DebuggerState(nothing, false, 1) function active_frame(state::DebuggerState) frame = state.frame @@ -97,8 +96,7 @@ function startdebugging(frame, initial_continue = false) if initial_continue && !JuliaInterpreter.shouldbreak(frame, frame.pc) ret = debug_command(_compiledMode[], frame, :c, true) if ret === nothing - STATE.result = res = JuliaInterpreter.get_return(root(frame)) - return res + return res = JuliaInterpreter.get_return(root(frame)) end STATE.frame = frame = ret[1] pc = ret[2] @@ -157,7 +155,7 @@ function startdebugging(frame, initial_continue = false) end if ret === nothing - STATE.result = res = JuliaInterpreter.get_return(root(frame)) + res = JuliaInterpreter.get_return(root(frame)) break else STATE.frame = frame = ret[1] diff --git a/src/frontend.jl b/src/frontend.jl index ef936719..7a6829e6 100644 --- a/src/frontend.jl +++ b/src/frontend.jl @@ -23,7 +23,7 @@ plotsize() = (@rpc plotsize()) .- 1 ploturl(url::String) = @msg ploturl(url) -SELECTORS = Dict( +const SELECTORS = Dict( "number" => ["syntax--constant", "syntax--numeric", "syntax--julia"], "symbol" => ["syntax--constant", "syntax--other", "syntax--symbol", "syntax--julia"], "string" => ["syntax--string", "syntax--quoted", "syntax--double", "syntax--julia"], diff --git a/src/outline.jl b/src/outline.jl index e535d72d..b8576f43 100644 --- a/src/outline.jl +++ b/src/outline.jl @@ -77,28 +77,29 @@ function toplevel_bindings(expr, text, bindings = [], line = 1, pos = 1) return bindings end -struct LocalScope - name - span - children - expr +struct LocalBinding + name::String + span::UnitRange{Int} + expr::CSTParser.EXPR end -struct LocalBinding - name - span - expr +struct LocalScope + name::String + span::UnitRange{Int} + children::Vector{Union{LocalBinding, LocalScope}} + expr::CSTParser.EXPR end -function local_bindings(expr, bindings = [], pos = 1) +function local_bindings(expr, bindings = Vector{Union{LocalBinding, LocalScope}}([]), pos = 1) bind = CSTParser.bindingof(expr) scope = CSTParser.scopeof(expr) if bind !== nothing && scope === nothing push!(bindings, LocalBinding(bind.name, pos:pos+expr.span, expr)) end + if scope !== nothing range = pos:pos+expr.span - localbindings = [] + localbindings = Vector{Union{LocalBinding, LocalScope}}([]) if expr.args !== nothing for arg in expr.args local_bindings(arg, localbindings, pos) @@ -114,8 +115,8 @@ function local_bindings(expr, bindings = [], pos = 1) pos += arg.fullspan end end - return bindings + return bindings end function locals(text, line, col) diff --git a/src/path_matching.jl b/src/path_matching.jl index ac4f2f89..4dd5d715 100644 --- a/src/path_matching.jl +++ b/src/path_matching.jl @@ -1,16 +1,16 @@ -uri_regex = if Sys.iswindows() +const uri_regex = if Sys.iswindows() r"((?:(?:[a-zA-Z]:|\.\.?|\~)|(?:[^\0<>\?\|\/\s!$`&*()\[\]+'\":;])+)?(?:(?:\\|\/)(?:[^\0<>\?\|\/\s!$`&*()\[\]+'\":;])+)+)(?:\:(\d+))?" else r"((?:(?:\.\.?|\~)|(?:[^\0\s!$`&*()\[\]+'\":;\\])+)?(?:\/(?:[^\0\s!$`&*()\[\]+'\":;\\])+)+)(?:\:(\d+))?" end -buildbot_regex = if Sys.iswindows() +const buildbot_regex = if Sys.iswindows() r"C:\\cygwin\home\\Admininstrator\\buildbot\\.*?(\\julia\\stdlib\\.*?\.jl)" else r"\/buildworker\/worker\/.*?(\/julia\/stdlib\/.*?\.jl)" end -repl_at_regex = r"@ (?:[^\s]+)\s(.*?)\:(\d+)" +const repl_at_regex = r"@ (?:[^\s]+)\s(.*?)\:(\d+)" function fullREPLpath(uri) urimatch = match(repl_at_regex, uri)