rider-server 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.build.yml +3 -3
  3. data/CHANGELOG.md +23 -1
  4. data/COPYING +20 -0
  5. data/README.rdoc +39 -0
  6. data/Rakefile +5 -0
  7. data/exe/rider-server +3 -3
  8. data/lib/rider_server/config.rb +76 -0
  9. data/lib/rider_server/core_ext/array.rb +3 -1
  10. data/lib/rider_server/core_ext/class.rb +5 -0
  11. data/lib/rider_server/core_ext/env.rb +14 -0
  12. data/lib/rider_server/core_ext/hash.rb +3 -1
  13. data/lib/rider_server/core_ext/kernel.rb +5 -0
  14. data/lib/rider_server/core_ext/module.rb +18 -0
  15. data/lib/rider_server/core_ext/object.rb +7 -1
  16. data/lib/rider_server/core_ext/string.rb +3 -1
  17. data/lib/rider_server/core_ext/symbol.rb +3 -1
  18. data/lib/rider_server/exception_extension.rb +2 -0
  19. data/lib/rider_server/inspect.rb +115 -43
  20. data/lib/rider_server/logger.rb +11 -4
  21. data/lib/rider_server/operation.rb +39 -20
  22. data/lib/rider_server/{ops → operations}/clone.rb +3 -2
  23. data/lib/rider_server/{ops → operations}/close.rb +3 -2
  24. data/lib/rider_server/operations/completions.rb +146 -0
  25. data/lib/rider_server/operations/lookup.rb +102 -0
  26. data/lib/rider_server/operations/ls_sessions.rb +51 -0
  27. data/lib/rider_server/operations/toggle_catch_all_exceptions.rb +24 -0
  28. data/lib/rider_server/operations.rb +43 -69
  29. data/lib/rider_server/request.rb +61 -0
  30. data/lib/rider_server/response.rb +10 -2
  31. data/lib/rider_server/server.rb +29 -17
  32. data/lib/rider_server/services/capture_exceptions.rb +18 -2
  33. data/lib/rider_server/services/rails.rb +1 -1
  34. data/lib/rider_server/session.rb +77 -34
  35. data/lib/rider_server/session_operation.rb +17 -0
  36. data/lib/rider_server/session_operations/eval.rb +61 -0
  37. data/lib/rider_server/session_operations/inspect.rb +123 -0
  38. data/lib/rider_server/session_operations/inspect_exception.rb +46 -0
  39. data/lib/rider_server/session_operations/interrupt.rb +29 -0
  40. data/lib/rider_server/session_operations/load_path.rb +19 -0
  41. data/lib/rider_server/session_operations/ls_exceptions.rb +28 -0
  42. data/lib/rider_server/session_operations/ls_services.rb +18 -0
  43. data/lib/rider_server/session_operations/service.rb +42 -0
  44. data/lib/rider_server/session_operations/set_namespace.rb +82 -0
  45. data/lib/rider_server/session_operations/set_namespace_variable.rb +81 -0
  46. data/lib/rider_server/session_operations/stdin.rb +19 -0
  47. data/lib/rider_server/utils.rb +7 -7
  48. data/lib/rider_server/validate/array.rb +32 -0
  49. data/lib/rider_server/validate/base.rb +28 -0
  50. data/lib/rider_server/validate/boolean.rb +47 -0
  51. data/lib/rider_server/validate/hash.rb +32 -0
  52. data/lib/rider_server/validate/integer.rb +56 -0
  53. data/lib/rider_server/validate/predicates.rb +30 -0
  54. data/lib/rider_server/validate/string.rb +60 -0
  55. data/lib/rider_server/validate/symbol.rb +90 -0
  56. data/lib/rider_server/validate.rb +15 -0
  57. data/lib/rider_server/version.rb +1 -1
  58. data/lib/rider_server/workspace.rb +1 -1
  59. data/lib/rider_server.rb +3 -1
  60. metadata +55 -24
  61. data/README.md +0 -44
  62. data/lib/rider_server/ops/completions.rb +0 -100
  63. data/lib/rider_server/ops/eval.rb +0 -62
  64. data/lib/rider_server/ops/inspect.rb +0 -121
  65. data/lib/rider_server/ops/inspect_exception.rb +0 -47
  66. data/lib/rider_server/ops/interrupt.rb +0 -30
  67. data/lib/rider_server/ops/load_path.rb +0 -20
  68. data/lib/rider_server/ops/lookup.rb +0 -83
  69. data/lib/rider_server/ops/ls_exceptions.rb +0 -29
  70. data/lib/rider_server/ops/ls_services.rb +0 -19
  71. data/lib/rider_server/ops/ls_sessions.rb +0 -52
  72. data/lib/rider_server/ops/service.rb +0 -43
  73. data/lib/rider_server/ops/set_namespace.rb +0 -79
  74. data/lib/rider_server/ops/set_namespace_variable.rb +0 -80
  75. data/lib/rider_server/ops/stdin.rb +0 -20
  76. data/lib/rider_server/ops/toggle_catch_all_exceptions.rb +0 -27
@@ -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 name =~ /\A[a-zA-Z_]\w*\z/
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