diff --git a/Project.toml b/Project.toml index 16a8e68..2ef386e 100644 --- a/Project.toml +++ b/Project.toml @@ -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"] diff --git a/src/debugger_requests.jl b/src/debugger_requests.jl index 3aa8de7..2a4e12d 100644 --- a/src/debugger_requests.jl +++ b/src/debugger_requests.jl @@ -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 diff --git a/src/packagedef.jl b/src/packagedef.jl index fbf4cf2..fe2f9c6 100644 --- a/src/packagedef.jl +++ b/src/packagedef.jl @@ -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 diff --git a/src/protocol/dap_message_defs.jl b/src/protocol/dap_message_defs.jl index 883cb30..594073f 100644 --- a/src/protocol/dap_message_defs.jl +++ b/src/protocol/dap_message_defs.jl @@ -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