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

wip: completions #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
17 changes: 9 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ uuid = "17994d07-08fe-42cc-bc1b-7af499b1ea47"
version = "1.0.1-DEV"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
JSONRPC = "b9b8584e-8fd3-41f9-ad0c-7255d428e418"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
JSONRPC = "b9b8584e-8fd3-41f9-ad0c-7255d428e418"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
JSON = "0.20, 0.21"
julia = "1"
JuliaInterpreter = "0.8.5, 0.9"
JSONRPC = "1.1"
JuliaInterpreter = "0.8.5, 0.9"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
76 changes: 76 additions & 0 deletions src/debugger_requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1078,3 +1078,79 @@ end
function breakpointlocations_request(conn, state::DebuggerState, params::BreakpointLocationsArguments)
return BreakpointLocationsResponseArguments(BreakpointLocation[])
end

using REPL
function completions_request(conn, state::DebuggerState, params::CompletionsArguments)
@debug "completions_request"

(c, l) = params.column, coalesce(params.line, 1)
io = IOBuffer()
for (i, line) in enumerate(eachline(IOBuffer(params.text)))
if i == l
print(io, first(line, c))
break
end
println(io, line)
end
text = String(take!(io))
split(text, )

completions = CompletionItem[]
for v in something(JuliaInterpreter.locals(state.frame), [])
push!(completions, CompletionItem(string(v.name), missing, "variable", missing, missing))
end
for v in something(collect_global_refs(state.frame), [])
push!(completions, CompletionItem(string(v.name), missing, "reference", missing, missing))
end
for (k,v) in REPL.REPLCompletions.latex_symbols
push!(completions, CompletionItem(v, k, "text", missing, missing))
end
for (k,v) in REPL.REPLCompletions.emoji_symbols
push!(completions, CompletionItem(v, k, "text", missing, missing))
end

return CompletionsResponseArguments(completions)
end

# function completions_request(conn, state::DebuggerState, params::CompletionsArguments)
# @debug "completions_request"

# (c, l) = params.column, coalesce(params.line, 1)
# io = IOBuffer()
# for (i, line) in enumerate(eachline(IOBuffer(params.text)))
# if i == l
# print(io, first(line, c))
# break
# end
# println(io, line)
# end
# text = String(take!(io))

# @show text c l

# thismod = state.frame.framecode.scope isa Module ? state.frame.framecode.scope : Main

# comps, range, should_complete = REPL.REPLCompletions.completions(text, lastindex(text), thismod)

# # locals = JuliaInterpreter.locals(state.frame)
# # globals = collect_global_refs(state.frame)
# # REPL.REPLCompletions.latex_symbols
# # REPL.REPLCompletions.emoji_symbols

# # comps = CompletionItem[]

# @show first(comps, 5) range should_complete

# return CompletionsResponseArguments(
# map(comps) do comp
# ct = REPL.REPLCompletions.completion_text(comp)
# CompletionItem(
# ct,
# ct,
# "value",
# range.start,
# length(range)
# )
# end
# )
# end
1 change: 1 addition & 0 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function startdebug(socket, error_handler=nothing)
msg_dispatcher[breakpointslocation_request_type] = (conn, params) -> breakpointlocations_request(conn, state, params)
msg_dispatcher[set_compiled_items_notification_type] = (conn, params) -> set_compiled_items_request(conn, state, params)
msg_dispatcher[set_compiled_mode_notification_type] = (conn, params) -> set_compiled_mode_request(conn, state, params)
msg_dispatcher[completions_request_type] = (conn, params) -> completions_request(conn, state, params)

@async try
for msg in endpoint
Expand Down
1 change: 1 addition & 0 deletions src/protocol/dap_message_defs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const set_variable_request_type = JSONRPC.RequestType("setVariable", SetVariable
const stopped_notification_type = JSONRPC.NotificationType("stopped", StoppedEventArguments)
const threads_request_type = JSONRPC.RequestType("threads", Nothing, ThreadsResponseArguments)
const breakpointslocation_request_type = JSONRPC.RequestType("breakpointLocations", BreakpointLocationsArguments, BreakpointLocationsResponseArguments)
const completions_request_type = JSONRPC.RequestType("completions", CompletionsArguments, CompletionsResponseArguments)

@dict_readable struct DebugArguments <: Outbound
stopOnEntry::Bool
Expand Down