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

RFC: Improved tab completion for symbols #634

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ end
complete_type(::Type{<:Function}) = "function"
complete_type(::Type{<:Type}) = "type"
complete_type(::Type{<:Tuple}) = "tuple"
complete_type(::Void) = "void"

function complete_type(T::DataType)
s = string(T)
Expand Down Expand Up @@ -119,6 +120,21 @@ function complete_types(comps)
return typeMap
end

function complete_symbols(comps, symbol_dict)
newcomps = []
for c in comps
smb = get(symbol_dict, c, c)
scomps, positions = Base.REPLCompletions.completions(smb, 1)
(smb in scomps) || push!(newcomps, smb)
if !isempty(scomps)
for s in scomps
push!(newcomps, s)
end
end
end
return newcomps
end

function complete_request(socket, msg)
code = msg.content["code"]
cursor_chr = msg.content["cursor_pos"]
Expand Down Expand Up @@ -146,6 +162,12 @@ function complete_request(socket, msg)
else
cursor_start = ind2chr(msg, code, prevind(code, first(positions)))
cursor_end = ind2chr(msg, code, last(positions))
#Get completions for symbols
if startswith(comps[1], "\\:")
comps = complete_symbols(comps, emoji_symbols)
elseif startswith(comps[1], "\\")
comps = complete_symbols(comps, latex_symbols)
end
metadata["_jupyter_types_experimental"] = complete_types(comps)
end
send_ipython(requests[], msg_reply(msg, "complete_reply",
Expand Down