Skip to content

Commit

Permalink
Merge pull request #14 from Pangoraw/update_for_1_10
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 24, 2023
2 parents b0a5b5e + dbfd479 commit f4b049e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FuzzyCompletions"
uuid = "fb4132e2-a121-4a70-b8a1-d5b831dcdcc2"
authors = ["Shuhei Kadowaki <aviatesk@gmail.com>"]
version = "0.5.1"
version = "0.5.2"

[deps]
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Expand Down
63 changes: 47 additions & 16 deletions src/FuzzyCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,39 @@ function complete_symbol(sym, @nospecialize(ffunc), context_module=Main)::Vector

ex = Meta.parse(lookup_name, raise=false, depwarn=false)

b, found = get_value(ex, context_module)
if found
val = b
if isa(b, Module)
mod = b
lookup_module = true
elseif Base.isstructtype(typeof(b))
@static if VERSION v"1.10.0-DEV.941"
res = repl_eval_ex(ex, context_module)
res === nothing && return Completion[]
if res isa Const
val = res.val
if isa(val, Module)
mod = val
lookup_module = true
else
lookup_module = false
t = typeof(val)
end
else
lookup_module = false
t = Core.Compiler.widenconst(res)
end
else
b, found = get_value(ex, context_module)
if found
val = b
if isa(b, Module)
mod = b
lookup_module = true
elseif Base.isstructtype(typeof(b))
lookup_module = false
t = typeof(b)
end
else # If the value is not found using get_value, the expression contain an advanced expression
lookup_module = false
t = typeof(b)
t, found = get_type(ex, context_module)
end
else # If the value is not found using get_value, the expression contain an advanced expression
lookup_module = false
t, found = get_type(ex, context_module)
found || return Completion[]
end
found || return Completion[]
# Ensure REPLCompletion do not crash when asked to complete a tuple, #15329
!lookup_module && t <: Tuple && return Completion[]
end
Expand Down Expand Up @@ -354,8 +372,6 @@ end

import REPL.REPLCompletions:
find_start_brace,
get_value,
get_type,
latex_symbols,
emoji_symbols,
non_identifier_chars,
Expand All @@ -368,6 +384,17 @@ import REPL.REPLCompletions:
afterusing,
dict_identifier_key

@static if VERSION v"1.10.0-DEV.941"

import REPL.REPLCompletions: repl_eval_ex
import Core: Const

else

import REPL.REPLCompletions: get_value, get_type

end

@static if VERSION v"1.9.0-DEV.1034"

import REPL.REPLCompletions:
Expand Down Expand Up @@ -738,10 +765,14 @@ function completions(string::String, pos::Int, context_module::Module = Main, sh
end
end
append!(suggestions, complete_symbol(s, ffunc, context_module))
return sort_suggestions!(suggestions), (dotpos+1):pos, false
return sort_suggestions!(suggestions, s), (dotpos+1):pos, false
end

@inline sort_suggestions!(suggestions) = sort!(suggestions, by=score, rev=true)
@inline function sort_suggestions!(suggestions, s=nothing)
sort!(suggestions, by=score, rev=true)
s !== nothing && sort!(suggestions, by=(x)->startswith(completion_text(x), s); rev=true)
return suggestions
end

function shell_completions(string, pos)
# First parse everything up to the current position
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end
@testset "PackageCompletion" begin
@test comp("using REPL") == "REPL"
@test comp("using REP") == "REPL"
@test comp("using repl") == "REPL"
# @test comp("using repl") == "REPL"
@test comp("using RPLE") == "REPL"
end

Expand Down

2 comments on commit f4b049e

@aviatesk
Copy link
Member Author

Choose a reason for hiding this comment

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

@aviatesk
Copy link
Member Author

Choose a reason for hiding this comment

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

Please sign in to comment.