rider-server 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.build.yml +3 -3
- data/CHANGELOG.md +17 -1
- data/README.rdoc +39 -0
- data/Rakefile +5 -0
- data/exe/rider-server +3 -3
- data/lib/rider_server/config.rb +76 -0
- data/lib/rider_server/core_ext/array.rb +3 -1
- data/lib/rider_server/core_ext/class.rb +5 -0
- data/lib/rider_server/core_ext/env.rb +14 -0
- data/lib/rider_server/core_ext/hash.rb +3 -1
- data/lib/rider_server/core_ext/kernel.rb +5 -0
- data/lib/rider_server/core_ext/module.rb +18 -0
- data/lib/rider_server/core_ext/object.rb +7 -1
- data/lib/rider_server/core_ext/string.rb +3 -1
- data/lib/rider_server/core_ext/symbol.rb +3 -1
- data/lib/rider_server/exception_extension.rb +2 -0
- data/lib/rider_server/inspect.rb +108 -32
- data/lib/rider_server/logger.rb +11 -4
- data/lib/rider_server/operation.rb +39 -20
- data/lib/rider_server/{ops → operations}/clone.rb +3 -2
- data/lib/rider_server/{ops → operations}/close.rb +3 -2
- data/lib/rider_server/operations/completions.rb +146 -0
- data/lib/rider_server/operations/lookup.rb +102 -0
- data/lib/rider_server/operations/ls_sessions.rb +51 -0
- data/lib/rider_server/operations/toggle_catch_all_exceptions.rb +24 -0
- data/lib/rider_server/operations.rb +42 -68
- data/lib/rider_server/request.rb +61 -0
- data/lib/rider_server/response.rb +10 -2
- data/lib/rider_server/server.rb +28 -16
- data/lib/rider_server/services/capture_exceptions.rb +1 -1
- data/lib/rider_server/services/rails.rb +1 -1
- data/lib/rider_server/session.rb +75 -44
- data/lib/rider_server/session_operation.rb +17 -0
- data/lib/rider_server/session_operations/eval.rb +61 -0
- data/lib/rider_server/session_operations/inspect.rb +123 -0
- data/lib/rider_server/session_operations/inspect_exception.rb +46 -0
- data/lib/rider_server/session_operations/interrupt.rb +29 -0
- data/lib/rider_server/session_operations/load_path.rb +19 -0
- data/lib/rider_server/session_operations/ls_exceptions.rb +28 -0
- data/lib/rider_server/session_operations/ls_services.rb +18 -0
- data/lib/rider_server/session_operations/service.rb +42 -0
- data/lib/rider_server/session_operations/set_namespace.rb +82 -0
- data/lib/rider_server/session_operations/set_namespace_variable.rb +81 -0
- data/lib/rider_server/session_operations/stdin.rb +19 -0
- data/lib/rider_server/utils.rb +7 -7
- data/lib/rider_server/validate/array.rb +32 -0
- data/lib/rider_server/validate/base.rb +28 -0
- data/lib/rider_server/validate/boolean.rb +47 -0
- data/lib/rider_server/validate/hash.rb +32 -0
- data/lib/rider_server/validate/integer.rb +56 -0
- data/lib/rider_server/validate/predicates.rb +30 -0
- data/lib/rider_server/validate/string.rb +60 -0
- data/lib/rider_server/validate/symbol.rb +90 -0
- data/lib/rider_server/validate.rb +15 -0
- data/lib/rider_server/version.rb +1 -1
- data/lib/rider_server/workspace.rb +1 -1
- data/lib/rider_server.rb +3 -1
- metadata +54 -24
- data/README.md +0 -46
- data/lib/rider_server/ops/completions.rb +0 -145
- data/lib/rider_server/ops/eval.rb +0 -62
- data/lib/rider_server/ops/inspect.rb +0 -121
- data/lib/rider_server/ops/inspect_exception.rb +0 -47
- data/lib/rider_server/ops/interrupt.rb +0 -30
- data/lib/rider_server/ops/load_path.rb +0 -20
- data/lib/rider_server/ops/lookup.rb +0 -104
- data/lib/rider_server/ops/ls_exceptions.rb +0 -29
- data/lib/rider_server/ops/ls_services.rb +0 -19
- data/lib/rider_server/ops/ls_sessions.rb +0 -52
- data/lib/rider_server/ops/service.rb +0 -43
- data/lib/rider_server/ops/set_namespace.rb +0 -79
- data/lib/rider_server/ops/set_namespace_variable.rb +0 -80
- data/lib/rider_server/ops/stdin.rb +0 -20
- data/lib/rider_server/ops/toggle_catch_all_exceptions.rb +0 -27
@@ -1,104 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
require "rider_server/inspect"
|
4
|
-
|
5
|
-
module RiderServer
|
6
|
-
module Ops
|
7
|
-
class Lookup < Operation
|
8
|
-
documentation "Get info about a symbol."
|
9
|
-
|
10
|
-
argument :id, :string, "The request id", required: true
|
11
|
-
argument :sym, :string, "The symbol to lookup", required: true
|
12
|
-
argument :lookup_fn, :string, "What lookup function to use, top-level, module, method or singleton-method"
|
13
|
-
argument :ns, :string, "The namespace to search for completions"
|
14
|
-
|
15
|
-
def initialize(*args)
|
16
|
-
@workspace = Workspace.new
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
def handle(session, operation)
|
21
|
-
response = Response.new(operation)
|
22
|
-
ns = operation["ns"]
|
23
|
-
sym = operation["sym"]
|
24
|
-
lookup_fn = operation.fetch("lookup-fn", "top-level")
|
25
|
-
|
26
|
-
if sym.nil? || parse_string(sym).nil?
|
27
|
-
response.set("info", {})
|
28
|
-
else
|
29
|
-
ns_object = if ns.empty?
|
30
|
-
::Object
|
31
|
-
else
|
32
|
-
@workspace.lookup_module(ns)
|
33
|
-
end
|
34
|
-
|
35
|
-
# If the prefix isn't parseable, return an empty list
|
36
|
-
response.set("info", lookup_module(sym, klass: ns_object, lookup_fn: lookup_fn))
|
37
|
-
end
|
38
|
-
response.status("done")
|
39
|
-
response
|
40
|
-
end
|
41
|
-
|
42
|
-
def lookup_module(module_name, klass: ::Object, lookup_fn: "top-level")
|
43
|
-
node = parse_string(module_name)
|
44
|
-
case node.type
|
45
|
-
when :const
|
46
|
-
ns = lookup_module_ast(node.children.first, klass)
|
47
|
-
name = node.children.last
|
48
|
-
encode_const(ns, name)
|
49
|
-
when :send
|
50
|
-
ns = lookup_module_ast(node.children.first, klass)
|
51
|
-
prefix = node.children.last
|
52
|
-
if lookup_fn == "method"
|
53
|
-
encode_method(ns.instance_method(prefix))
|
54
|
-
else
|
55
|
-
encode_method(ns.method(prefix))
|
56
|
-
end
|
57
|
-
else
|
58
|
-
[]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def parse_string(string)
|
63
|
-
buffer = Parser::Source::Buffer.new("(string)")
|
64
|
-
buffer.source = string
|
65
|
-
Parser::CurrentRuby.new.parse(buffer)
|
66
|
-
end
|
67
|
-
|
68
|
-
def lookup_module_ast(node, klass = ::Object)
|
69
|
-
return klass if node.nil?
|
70
|
-
|
71
|
-
case node.type
|
72
|
-
when :cbase
|
73
|
-
::Object
|
74
|
-
when :const
|
75
|
-
if node.children.first.nil?
|
76
|
-
klass.const_get(node.children.last)
|
77
|
-
else
|
78
|
-
lookup_module_ast(node.children.first, klass).const_get(node.children.last)
|
79
|
-
end
|
80
|
-
else
|
81
|
-
raise ModuleLookupError, "Unknown node type #{node.type}"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def encode_const(ns, const_name)
|
86
|
-
if ns.const_defined? const_name
|
87
|
-
{
|
88
|
-
"name" => "#{ns}::#{const_name}",
|
89
|
-
"source_location" => ns.const_source_location(const_name)
|
90
|
-
}
|
91
|
-
else
|
92
|
-
{}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def encode_method(thing)
|
97
|
-
{
|
98
|
-
"name" => thing.name.to_s,
|
99
|
-
"source_location" => thing.source_location
|
100
|
-
}
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class LsExceptions < Operation
|
7
|
-
documentation "List all exceptions that exist in the sessions cache."
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
|
11
|
-
def handle(session, operation)
|
12
|
-
response = Response.new(operation)
|
13
|
-
|
14
|
-
exceptions = session.exceptions.map do |item|
|
15
|
-
{
|
16
|
-
"id" => item["id"],
|
17
|
-
"operation-id" => item["operation_id"],
|
18
|
-
"created-at" => item["created_at"].iso8601,
|
19
|
-
"exception" => item["exception"].inspect
|
20
|
-
}
|
21
|
-
end
|
22
|
-
|
23
|
-
response.set("exceptions", exceptions)
|
24
|
-
response.status("done")
|
25
|
-
response
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class LsServices < Operation
|
7
|
-
documentation "List all services."
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
|
11
|
-
def handle(session, operation)
|
12
|
-
response = Response.new(operation)
|
13
|
-
response.set("services", session.list_services)
|
14
|
-
response.status("done")
|
15
|
-
response
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class LsSessions < Operation
|
7
|
-
documentation "List all sessions"
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
|
11
|
-
def handle(session, operation)
|
12
|
-
response = Response.new(operation)
|
13
|
-
response.set("sessions", controller.sessions.map { |k, v| k })
|
14
|
-
response.set("rider/session-headings",
|
15
|
-
[
|
16
|
-
{
|
17
|
-
"id" => "id",
|
18
|
-
"name" => "ID",
|
19
|
-
"length" => 36
|
20
|
-
},
|
21
|
-
{
|
22
|
-
"id" => "namespace_name",
|
23
|
-
"name" => "Namespace",
|
24
|
-
"length" => 25
|
25
|
-
},
|
26
|
-
{
|
27
|
-
"id" => "history_items",
|
28
|
-
"name" => "History Items",
|
29
|
-
"length" => 5
|
30
|
-
},
|
31
|
-
{
|
32
|
-
"id" => "exceptions",
|
33
|
-
"name" => "Exceptions",
|
34
|
-
"length" => 5
|
35
|
-
}
|
36
|
-
])
|
37
|
-
response.set("rider/sessions", controller.sessions.map { |k, v| session_summary(v) })
|
38
|
-
response.status("done")
|
39
|
-
response
|
40
|
-
end
|
41
|
-
|
42
|
-
def session_summary(session)
|
43
|
-
{
|
44
|
-
"id" => session.id,
|
45
|
-
"namespace_name" => session.workspace.namespace_name,
|
46
|
-
"history_items" => session.history.length.to_s,
|
47
|
-
"exceptions" => session.exceptions.length.to_s
|
48
|
-
}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class Service < Operation
|
7
|
-
documentation "Control a Ruby service integration"
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
argument :service, :string, "The name of the Ruby service to control", required: true
|
11
|
-
argument :state, :string, "The desired state of the service", required: true
|
12
|
-
|
13
|
-
def handle(session, operation)
|
14
|
-
response = Response.new(operation)
|
15
|
-
|
16
|
-
service = operation["service"]
|
17
|
-
state = operation["state"]
|
18
|
-
|
19
|
-
current_state = session.service_state(service)
|
20
|
-
|
21
|
-
case state
|
22
|
-
when "start"
|
23
|
-
raise "Service already running" if current_state == "running"
|
24
|
-
session.start_service(service, response.id)
|
25
|
-
response.set("rider/stream", "true")
|
26
|
-
when "stop"
|
27
|
-
raise "Can't stop service #{service}. It's not running." if current_state == "stopped"
|
28
|
-
session.stop_service(service)
|
29
|
-
response.status("done")
|
30
|
-
else
|
31
|
-
# TODO: throwing this exception will caues a "done" response
|
32
|
-
# to be sent, which will implicitly close the stream. It
|
33
|
-
# might make sense to handle this more gracefully here.
|
34
|
-
raise "Unknown state #{state}"
|
35
|
-
end
|
36
|
-
|
37
|
-
response.set("service", service)
|
38
|
-
response.set("state", session.service_state(service).to_s)
|
39
|
-
response
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class SetNamespace < Operation
|
7
|
-
documentation "Set the namespace to the given location."
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
argument :location, :array, "The location to set the namespace to", required: true
|
11
|
-
|
12
|
-
def handle(session, operation)
|
13
|
-
response = Response.new(operation)
|
14
|
-
location = operation["location"]
|
15
|
-
|
16
|
-
value = traverse_location(location, nil, session)
|
17
|
-
session.workspace.set_namespace(value)
|
18
|
-
response.set("ns", session.workspace.namespace_name)
|
19
|
-
response.set("location", location)
|
20
|
-
response.status("done")
|
21
|
-
response
|
22
|
-
end
|
23
|
-
|
24
|
-
def traverse_location(location, ctx, session)
|
25
|
-
loc = location.first
|
26
|
-
locs = location.drop(1)
|
27
|
-
|
28
|
-
if locs.empty?
|
29
|
-
lookup_object(loc, ctx, session)
|
30
|
-
else
|
31
|
-
traverse_location(locs, lookup_object(loc, ctx, session), session)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def lookup_object(loc, ctx, session)
|
36
|
-
lookup, identifier = loc.split(":", 2)
|
37
|
-
|
38
|
-
case lookup
|
39
|
-
when "rider_main"
|
40
|
-
"main"
|
41
|
-
when "rider_history"
|
42
|
-
rider_history(identifier, nil, session)
|
43
|
-
when "rider_exception"
|
44
|
-
rider_exception(identifier, nil, session)
|
45
|
-
when "rider_stackframe"
|
46
|
-
ctx.__rider_bindings_stack[identifier.to_i]
|
47
|
-
when "rider_stackframe_variable"
|
48
|
-
frame_id, local_var = identifier.split(":", 2)
|
49
|
-
ctx.__rider_bindings_stack[frame_id.to_i].local_variable_get(local_var)
|
50
|
-
when "rider_hash_key"
|
51
|
-
hash = identifier.to_i
|
52
|
-
ctx.keys.find { |key| key.hash == hash }
|
53
|
-
when "rider_hash_value"
|
54
|
-
hash = identifier.to_i
|
55
|
-
key = ctx.keys.find { |key| key.hash == hash }
|
56
|
-
ctx.fetch(key)
|
57
|
-
when "toplevel_const_get"
|
58
|
-
Object.const_get(identifier)
|
59
|
-
when "instance_variable_get"
|
60
|
-
ctx.instance_variable_get(identifier)
|
61
|
-
when "const_get"
|
62
|
-
ctx.const_get(identifier)
|
63
|
-
when "ancestor_find"
|
64
|
-
ctx.class.ancestors.find { |item| item.to_s == identifier }
|
65
|
-
else
|
66
|
-
raise "Unknown inspect function: #{lookup}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def rider_history(value, ctx, session)
|
71
|
-
session.get_result(value)
|
72
|
-
end
|
73
|
-
|
74
|
-
def rider_exception(id, ctx, session)
|
75
|
-
session.get_exception(id)["exception"]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class SetNamespaceVariable < Operation
|
7
|
-
documentation "Set a variable in the current REPL binding."
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
argument :name, :string, "The name of the local variable to set", required: true
|
11
|
-
argument :location, :array, "The location to set the namespace to", required: true
|
12
|
-
|
13
|
-
def handle(session, operation)
|
14
|
-
response = Response.new(operation)
|
15
|
-
name = operation["name"]
|
16
|
-
raise "Name must be a valid Ruby identifier" unless /\A[a-zA-Z_]\w*\z/.match?(name)
|
17
|
-
location = operation["location"]
|
18
|
-
|
19
|
-
value = traverse_location(location, nil, session)
|
20
|
-
session.workspace.binding_local_variable_set(name, value)
|
21
|
-
response.status("done")
|
22
|
-
response
|
23
|
-
end
|
24
|
-
|
25
|
-
def traverse_location(location, ctx, session)
|
26
|
-
loc = location.first
|
27
|
-
locs = location.drop(1)
|
28
|
-
|
29
|
-
if locs.empty?
|
30
|
-
lookup_object(loc, ctx, session)
|
31
|
-
else
|
32
|
-
traverse_location(locs, lookup_object(loc, ctx, session), session)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def lookup_object(loc, ctx, session)
|
37
|
-
lookup, identifier = loc.split(":", 2)
|
38
|
-
|
39
|
-
case lookup
|
40
|
-
when "rider_main"
|
41
|
-
"main"
|
42
|
-
when "rider_history"
|
43
|
-
rider_history(identifier, nil, session)
|
44
|
-
when "rider_exception"
|
45
|
-
rider_exception(identifier, nil, session)
|
46
|
-
when "rider_stackframe"
|
47
|
-
ctx.__rider_bindings_stack[identifier.to_i]
|
48
|
-
when "rider_stackframe_variable"
|
49
|
-
frame_id, local_var = identifier.split(":", 2)
|
50
|
-
ctx.__rider_bindings_stack[frame_id.to_i].local_variable_get(local_var)
|
51
|
-
when "rider_hash_key"
|
52
|
-
hash = identifier.to_i
|
53
|
-
ctx.keys.find { |key| key.hash == hash }
|
54
|
-
when "rider_hash_value"
|
55
|
-
hash = identifier.to_i
|
56
|
-
key = ctx.keys.find { |key| key.hash == hash }
|
57
|
-
ctx.fetch(key)
|
58
|
-
when "toplevel_const_get"
|
59
|
-
Object.const_get(identifier)
|
60
|
-
when "instance_variable_get"
|
61
|
-
ctx.instance_variable_get(identifier)
|
62
|
-
when "const_get"
|
63
|
-
ctx.const_get(identifier)
|
64
|
-
when "ancestor_find"
|
65
|
-
ctx.class.ancestors.find { |item| item.to_s == identifier }
|
66
|
-
else
|
67
|
-
raise "Unknown inspect function: #{lookup}"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def rider_history(value, ctx, session)
|
72
|
-
session.get_result(value)
|
73
|
-
end
|
74
|
-
|
75
|
-
def rider_exception(id, ctx, session)
|
76
|
-
session.get_exception(id)["exception"]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class Stdin < Operation
|
7
|
-
documentation "List all exceptions that have occurred in the session."
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
argument :stdin, :string, "The input to write to the stdin of the process", required: true
|
11
|
-
|
12
|
-
def handle(session, operation)
|
13
|
-
controller.stdin.write(operation["stdin"])
|
14
|
-
response = Response.new(operation)
|
15
|
-
response.status("done")
|
16
|
-
response
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require "rider_server/operation"
|
2
|
-
require "rider_server/response"
|
3
|
-
|
4
|
-
module RiderServer
|
5
|
-
module Ops
|
6
|
-
class ToggleCatchAllExceptions < Operation
|
7
|
-
documentation "Enable catching all exceptions. Not just the ones with a session."
|
8
|
-
|
9
|
-
argument :id, :string, "The request id", required: true
|
10
|
-
|
11
|
-
def handle(session, operation)
|
12
|
-
if @controller.sessions_catching_exceptions.member?(session.id)
|
13
|
-
@controller.sessions_catching_exceptions.delete(session.id)
|
14
|
-
value = "disabled"
|
15
|
-
else
|
16
|
-
@controller.sessions_catching_exceptions.push(session.id)
|
17
|
-
value = "enabled"
|
18
|
-
end
|
19
|
-
|
20
|
-
response = Response.new(operation)
|
21
|
-
response.status("done")
|
22
|
-
response.set("value", value)
|
23
|
-
response
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|