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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rider-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Sim
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-27 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bencode
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.8'
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: binding_of_caller
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parser
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.1.0
41
55
  description: ''
42
56
  email:
43
57
  - rsl@simopolis.xyz
@@ -50,12 +64,18 @@ files:
50
64
  - ".ruby-version"
51
65
  - ".standard.yml"
52
66
  - CHANGELOG.md
53
- - README.md
67
+ - COPYING
68
+ - README.rdoc
54
69
  - Rakefile
55
70
  - exe/rider-server
56
71
  - lib/rider_server.rb
72
+ - lib/rider_server/config.rb
57
73
  - lib/rider_server/core_ext/array.rb
74
+ - lib/rider_server/core_ext/class.rb
75
+ - lib/rider_server/core_ext/env.rb
58
76
  - lib/rider_server/core_ext/hash.rb
77
+ - lib/rider_server/core_ext/kernel.rb
78
+ - lib/rider_server/core_ext/module.rb
59
79
  - lib/rider_server/core_ext/object.rb
60
80
  - lib/rider_server/core_ext/string.rb
61
81
  - lib/rider_server/core_ext/symbol.rb
@@ -65,23 +85,13 @@ files:
65
85
  - lib/rider_server/logger.rb
66
86
  - lib/rider_server/operation.rb
67
87
  - lib/rider_server/operations.rb
68
- - lib/rider_server/ops/clone.rb
69
- - lib/rider_server/ops/close.rb
70
- - lib/rider_server/ops/completions.rb
71
- - lib/rider_server/ops/eval.rb
72
- - lib/rider_server/ops/inspect.rb
73
- - lib/rider_server/ops/inspect_exception.rb
74
- - lib/rider_server/ops/interrupt.rb
75
- - lib/rider_server/ops/load_path.rb
76
- - lib/rider_server/ops/lookup.rb
77
- - lib/rider_server/ops/ls_exceptions.rb
78
- - lib/rider_server/ops/ls_services.rb
79
- - lib/rider_server/ops/ls_sessions.rb
80
- - lib/rider_server/ops/service.rb
81
- - lib/rider_server/ops/set_namespace.rb
82
- - lib/rider_server/ops/set_namespace_variable.rb
83
- - lib/rider_server/ops/stdin.rb
84
- - lib/rider_server/ops/toggle_catch_all_exceptions.rb
88
+ - lib/rider_server/operations/clone.rb
89
+ - lib/rider_server/operations/close.rb
90
+ - lib/rider_server/operations/completions.rb
91
+ - lib/rider_server/operations/lookup.rb
92
+ - lib/rider_server/operations/ls_sessions.rb
93
+ - lib/rider_server/operations/toggle_catch_all_exceptions.rb
94
+ - lib/rider_server/request.rb
85
95
  - lib/rider_server/response.rb
86
96
  - lib/rider_server/server.rb
87
97
  - lib/rider_server/service.rb
@@ -89,8 +99,29 @@ files:
89
99
  - lib/rider_server/services/capture_io.rb
90
100
  - lib/rider_server/services/rails.rb
91
101
  - lib/rider_server/session.rb
102
+ - lib/rider_server/session_operation.rb
103
+ - lib/rider_server/session_operations/eval.rb
104
+ - lib/rider_server/session_operations/inspect.rb
105
+ - lib/rider_server/session_operations/inspect_exception.rb
106
+ - lib/rider_server/session_operations/interrupt.rb
107
+ - lib/rider_server/session_operations/load_path.rb
108
+ - lib/rider_server/session_operations/ls_exceptions.rb
109
+ - lib/rider_server/session_operations/ls_services.rb
110
+ - lib/rider_server/session_operations/service.rb
111
+ - lib/rider_server/session_operations/set_namespace.rb
112
+ - lib/rider_server/session_operations/set_namespace_variable.rb
113
+ - lib/rider_server/session_operations/stdin.rb
92
114
  - lib/rider_server/transports/bencode.rb
93
115
  - lib/rider_server/utils.rb
116
+ - lib/rider_server/validate.rb
117
+ - lib/rider_server/validate/array.rb
118
+ - lib/rider_server/validate/base.rb
119
+ - lib/rider_server/validate/boolean.rb
120
+ - lib/rider_server/validate/hash.rb
121
+ - lib/rider_server/validate/integer.rb
122
+ - lib/rider_server/validate/predicates.rb
123
+ - lib/rider_server/validate/string.rb
124
+ - lib/rider_server/validate/symbol.rb
94
125
  - lib/rider_server/version.rb
95
126
  - lib/rider_server/workspace.rb
96
127
  homepage: https://sr.ht/~rsl/rider-server/
@@ -106,9 +137,9 @@ require_paths:
106
137
  - lib
107
138
  required_ruby_version: !ruby/object:Gem::Requirement
108
139
  requirements:
109
- - - "<"
140
+ - - ">="
110
141
  - !ruby/object:Gem::Version
111
- version: 3.2.0
142
+ version: '0'
112
143
  required_rubygems_version: !ruby/object:Gem::Requirement
113
144
  requirements:
114
145
  - - ">="
data/README.md DELETED
@@ -1,44 +0,0 @@
1
- # RIDER -- RIDER Interactive Development Environment for Ruby
2
-
3
- RIDER Server is the server component of the RIDER development
4
- environment.
5
-
6
- ## Installation
7
-
8
- TODO: Replace
9
- `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG`
10
- with your gem name right after releasing it to RubyGems.org. Please do
11
- not do it earlier due to security reasons. Alternatively, replace this
12
- section with instructions to install your gem from git if you don't
13
- plan to release to RubyGems.org.
14
-
15
- Install the gem and add to the application's Gemfile by executing:
16
-
17
- $ bundle add rider-server
18
-
19
- If bundler is not being used to manage dependencies, install the gem by executing:
20
-
21
- $ gem install rider-server
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install
30
- dependencies. Then, run `rake test` to run the tests. You can also run
31
- `bin/console` for an interactive prompt that will allow you to
32
- experiment.
33
-
34
- To install this gem onto your local machine, run `bundle exec rake
35
- install`. To release a new version, update the version number in
36
- `version.rb`, and then run `bundle exec rake release`, which will
37
- create a git tag for the version, push git commits and the created
38
- tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
-
40
- ## Contributing
41
-
42
- Bug reports https://todo.sr.ht/~rsl/rider
43
-
44
- Support or discussion https://lists.sr.ht/~rsl/rider-devel
@@ -1,100 +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 Completions < Operation
8
- documentation "Get completions for a given prefix"
9
-
10
- argument :id, :string, "The request id", required: true
11
- argument :prefix, :string, "The prefix to complete", required: true
12
- argument :ns, :string, "The namespace to search for completions"
13
-
14
- def initialize(*args)
15
- @workspace = Workspace.new
16
- super
17
- end
18
-
19
- def handle(session, operation)
20
- response = Response.new(operation)
21
-
22
- prefix = operation["prefix"]
23
- log.info "prefix: #{prefix}"
24
- ns = operation["ns"]
25
- # options = operation["options"]
26
-
27
- log.info "prefix: #{prefix}"
28
- ns_object = @workspace.lookup_module(ns)
29
- log.info "ns_object: #{ns_object}"
30
-
31
- response.set("completions", lookup_module(prefix, ns_object))
32
- log.info "completions: #{response["completions"]}"
33
-
34
- response.status("done")
35
- response
36
- rescue ScriptError, StandardError => e
37
- log.error "Error in completions: #{e}"
38
- log.error e.backtrace.join("\n")
39
- raise e
40
- end
41
-
42
- private
43
-
44
- def lookup_module(module_name, klass = ::Object)
45
- node = parse_string(module_name)
46
- case node.type
47
- when :const
48
- ns = lookup_module_ast(node.children.first, klass)
49
- prefix = node.children.last
50
- all_constants(ns, prefix) + all_methods(ns, prefix)
51
- when :send
52
- ns = lookup_module_ast(node.children.first, klass)
53
- prefix = node.children.last
54
- all_methods(ns, prefix)
55
- else
56
- []
57
- end
58
- end
59
-
60
- def parse_string(string)
61
- buffer = Parser::Source::Buffer.new("(string)")
62
- buffer.source = string
63
- Parser::CurrentRuby.new.parse(buffer)
64
- end
65
-
66
- def lookup_module_ast(node, klass = ::Object)
67
- case node.type
68
- when :cbase
69
- ::Object
70
- when :const
71
- if node.children.first.nil?
72
- klass.const_get(node.children.last)
73
- else
74
- lookup_module_ast(node.children.first, klass).const_get(node.children.last)
75
- end
76
- else
77
- raise ModuleLookupError, "Unknown node type #{node.type}"
78
- end
79
- end
80
-
81
- def all_constants(ns_object, prefix)
82
- ns_object.constants.grep(/^#{prefix}/).map do |constant|
83
- {
84
- "candidate" => constant.to_s,
85
- "type" => "constant"
86
- }
87
- end
88
- end
89
-
90
- def all_methods(ns_object, prefix)
91
- ns_object.methods.grep(/^#{prefix}/).map do |method|
92
- {
93
- "candidate" => method.to_s,
94
- "type" => "method"
95
- }
96
- end
97
- end
98
- end
99
- end
100
- end
@@ -1,62 +0,0 @@
1
- require "rider_server/operation"
2
- require "rider_server/response"
3
- require "rider_server/utils"
4
-
5
- module RiderServer
6
- module Ops
7
- class Eval < Operation
8
- documentation "Evaluate a string of code"
9
-
10
- argument :id, :string, "The request id", required: true
11
- argument :code, :string, "The code to evaluate"
12
- argument :ns, :string, "The namespace to evaluate the code in"
13
- argument :file, :string, "The file the code is from"
14
- argument :line, :integer, "The line number the code is from"
15
-
16
- def handle(session, operation)
17
- # TODO should do something if the session is nil
18
-
19
- response = Response.new(operation)
20
-
21
- # Abort if there is an evaluation with the same id
22
- if session.running_evaluation?(operation["id"])
23
- msg = "Evaluation already in progress for #{operation["id"]}"
24
- log.warn(msg)
25
- response.set("value", msg)
26
- response.status("eval-error", "done")
27
- send_response(response)
28
- return
29
- end
30
-
31
- session.push_history(operation)
32
- code = operation["code"]
33
- ns = operation["ns"]
34
- file = operation["file"] || ""
35
- line = operation["line"] || 0
36
-
37
- eval_thread = Thread.new do
38
- begin
39
- value = session.workspace.evaluate(code, ns, file, line)
40
- response.set("value", Utils.rider_inspect(value))
41
- response.set("ns", session.workspace.evaluate("inspect"))
42
- response.status("done")
43
- session.add_result(operation["id"], value)
44
- send_response(response)
45
- rescue EvalInterrupt, ScriptError, StandardError => e
46
- response.set("ex", e.inspect)
47
- response.set("ns", session.workspace.evaluate("inspect"))
48
- response.status("eval-error", "done")
49
- exception_id = session.add_exception(operation["id"], e)
50
- response.set("rider/exception-id", exception_id)
51
- send_response(response)
52
- end
53
-
54
- session.remove_evaluation(operation["id"])
55
- end
56
-
57
- session.add_evaluation(operation["id"], eval_thread)
58
- nil
59
- end
60
- end
61
- end
62
- end
@@ -1,121 +0,0 @@
1
- require "rider_server/inspect"
2
- require "rider_server/operation"
3
- require "rider_server/response"
4
- require "rider_server/utils"
5
-
6
- module RiderServer
7
- module Ops
8
- class Inspect < Operation
9
- documentation "Inspect an object"
10
-
11
- argument :id, :string, "The request id", required: true
12
- argument :location, :array, "The location of the object to inspect"
13
-
14
- def handle(session, operation)
15
- response = Response.new(operation)
16
- location = operation["location"]
17
- raise "Location is required" if location.nil? || location.empty?
18
-
19
- value = traverse_location(location, nil, session)
20
- response.set("name", Utils.rider_inspect(value))
21
-
22
- if value.is_a?(Array)
23
- value = value.map.with_index do |item, index|
24
- {
25
- "name" => item.to_s,
26
- "value" => Utils.rider_inspect(item),
27
- "inspect-location" => "rider_array_item:#{index}"
28
- }
29
- end
30
- response.set("value-array", value)
31
- elsif value.is_a?(Hash)
32
- value = value.map do |key, value|
33
- [
34
- {
35
- "name" => key.to_s,
36
- "value" => Utils.rider_inspect(key),
37
- "inspect-location" => "rider_hash_key:#{key.hash}"
38
- },
39
- {
40
- "name" => value.to_s,
41
- "value" => Utils.rider_inspect(value),
42
- "inspect-location" => "rider_hash_value:#{key.hash}"
43
- }
44
- ]
45
- end
46
- response.set("value-hash", value)
47
- elsif value.is_a?(String)
48
- response.set("value", value.inspect)
49
- elsif value.is_a?(Numeric)
50
- response.set("value", value.to_s)
51
- end
52
-
53
- response.set("inspect-location", location)
54
-
55
- response.set("class", RiderServer::Inspect.class(value))
56
- response.set("ancestors", RiderServer::Inspect.ancestors(value))
57
- response.set("constants", RiderServer::Inspect.constants(value))
58
- response.set("methods", RiderServer::Inspect.methods(value))
59
- response.set("instance-variables", RiderServer::Inspect.instance_variables(value))
60
- response.set("instance-methods", RiderServer::Inspect.instance_methods(value))
61
- response.set("class-variables", RiderServer::Inspect.class_variables(value))
62
- response.status("done")
63
- response
64
- end
65
-
66
- def traverse_location(location, ctx, session)
67
- loc = location.first
68
- locs = location.drop(1)
69
-
70
- if locs.empty?
71
- lookup_object(loc, ctx, session)
72
- else
73
- traverse_location(locs, lookup_object(loc, ctx, session), session)
74
- end
75
- end
76
-
77
- def lookup_object(loc, ctx, session)
78
- lookup, identifier = loc.split(":", 2)
79
-
80
- case lookup
81
- when "rider_main"
82
- "main"
83
- when "rider_history"
84
- rider_history(identifier, nil, session)
85
- when "rider_exception"
86
- rider_exception(identifier, nil, session)
87
- when "rider_stackframe_variable"
88
- frame_id, local_var = identifier.split(":", 2)
89
- ctx.__rider_bindings_stack[frame_id.to_i].local_variable_get(local_var)
90
- when "rider_array_item"
91
- ctx[identifier.to_i]
92
- when "rider_hash_key"
93
- hash = identifier.to_i
94
- ctx.keys.find { |key| key.hash == hash }
95
- when "rider_hash_value"
96
- hash = identifier.to_i
97
- key = ctx.keys.find { |key| key.hash == hash }
98
- ctx.fetch(key)
99
- when "toplevel_const_get"
100
- Object.const_get(identifier)
101
- when "instance_variable_get"
102
- ctx.instance_variable_get(identifier)
103
- when "const_get"
104
- ctx.const_get(identifier)
105
- when "ancestor_find"
106
- ctx.class.ancestors.find { |item| item.to_s == identifier }
107
- else
108
- raise "Unknown inspect function: #{lookup}"
109
- end
110
- end
111
-
112
- def rider_history(id, ctx, session)
113
- session.get_result(id)
114
- end
115
-
116
- def rider_exception(id, ctx, session)
117
- session.get_exception(id)["exception"]
118
- end
119
- end
120
- end
121
- end
@@ -1,47 +0,0 @@
1
- require "rider_server/operation"
2
- require "rider_server/response"
3
-
4
- module RiderServer
5
- module Ops
6
- class InspectException < Operation
7
- documentation "Inspect an exception."
8
-
9
- argument :id, :string, "The request id", required: true
10
- argument :"exception-id", :string, "The exception id"
11
-
12
- def handle(session, operation)
13
- response = Response.new(operation)
14
- exception_id = operation["exception-id"]
15
-
16
- value = session.get_exception(exception_id)
17
- response.set("inspect-location", value["id"])
18
- response.set("exception-id", value["id"])
19
- response.set("source-operation-id", value["operation_id"])
20
- response.set("created-at", value["created_at"].to_s)
21
-
22
- exception = value["exception"]
23
- response.set("value", exception.inspect)
24
- response.set("stacktrace", encode_stacktrace(exception, exception_id))
25
-
26
- response.status("done")
27
- response
28
- end
29
-
30
- def encode_stacktrace(exception, exception_id)
31
- exception.backtrace.zip(exception.__rider_bindings_stack).map.with_index do |(line, frame), frame_id|
32
- {
33
- "line" => line,
34
- "inspect-location" => ["rider_exception:#{exception_id}", "rider_stackframe:#{frame_id}"],
35
- "frame" => (frame&.local_variables || []).map do |var|
36
- {
37
- "name" => var.to_s,
38
- "value" => Utils.rider_inspect(frame.local_variable_get(var)),
39
- "inspect-location" => ["rider_exception:#{exception_id}", "rider_stackframe_variable:#{frame_id}:#{var}"]
40
- }
41
- end
42
- }
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,30 +0,0 @@
1
- require "rider_server/operation"
2
- require "rider_server/response"
3
-
4
- module RiderServer
5
- module Ops
6
- class Interrupt < Operation
7
- documentation "Interrupts the evaluation of a session."
8
-
9
- argument :id, :string, "The request id", required: true
10
- argument :"interrupt-id", :string, "The ID of the evaluation to interrupt.", required: true
11
-
12
- def handle(session, operation)
13
- # TODO should do something if the session is nil
14
-
15
- if operation["interrupt-id"].nil? || operation["interrupt-id"].empty?
16
- if session.evaluations.empty?
17
- raise ArgumentError, "No evaluations to interrupt"
18
- end
19
- session.interrupt_evaluation(session.evaluations.keys.max)
20
- else
21
- session.interrupt_evaluation(operation["interrupt-id"])
22
- end
23
-
24
- response = Response.new(operation)
25
- response.status("interrupted", "done")
26
- response
27
- end
28
- end
29
- end
30
- end
@@ -1,20 +0,0 @@
1
- require "rider_server/operation"
2
- require "rider_server/response"
3
-
4
- module RiderServer
5
- module Ops
6
- class LoadPath < Operation
7
- documentation "Return the current load path."
8
-
9
- argument :id, :string, "The request id", required: true
10
-
11
- def handle(session, operation)
12
- response = Response.new(operation)
13
- load_path = session.workspace.evaluate("$LOAD_PATH", "main")
14
- response.set("load-path", load_path)
15
- response.status("done")
16
- response
17
- end
18
- end
19
- end
20
- end
@@ -1,83 +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 completions for a given string"
9
-
10
- argument :id, :string, "The request id", required: true
11
- argument :sym, :string, "The symbol to lookup", required: true
12
- argument :ns, :string, "The namespace to search for completions"
13
-
14
- def initialize(*args)
15
- @workspace = Workspace.new
16
- super
17
- end
18
-
19
- def handle(session, operation)
20
- response = Response.new(operation)
21
- ns = operation["ns"]
22
- sym = operation["sym"]
23
-
24
- ns_object = @workspace.lookup_module(ns)
25
-
26
- method_type = nil
27
- if sym.include?("#")
28
- sym, method = sym.split("#")
29
- method_type = :instance
30
- method = method.to_sym
31
- elsif sym.start_with?("self.class")
32
- method = sym.split(".").last
33
- method_type = :class
34
- method = method.to_sym
35
- elsif sym.include?(".")
36
- sym, method = sym.split(".")
37
- method_type = :class
38
- method = method.to_sym
39
- end
40
-
41
- if sym.include?("::")
42
- ns_object = lookup_ns(sym.split("::"), ns_object)
43
- end
44
- constant = ns_object
45
-
46
- info = if sym.start_with?("@")
47
- constant = ns_object.instance_variable_get(sym)
48
- elsif method_type == :instance
49
- RiderServer::Inspect.describe_method(constant.instance_method(method))
50
- elsif method_type == :class
51
- RiderServer::Inspect.describe_method(constant.method(method))
52
- elsif constant.respond_to?(:instance_methods) && constant.instance_methods.include?(sym.to_sym)
53
- RiderServer::Inspect.describe_method(constant.instance_method(sym))
54
- elsif constant.respond_to?(:methods) && constant.methods.include?(sym.to_sym)
55
- RiderServer::Inspect.describe_method(constant.method(sym))
56
- else
57
- {}
58
- end
59
-
60
- response.set("info", info)
61
- response.status("done")
62
- response
63
- end
64
-
65
- private
66
-
67
- def lookup_ns(module_name, klass = Object)
68
- if module_name.start_with?("::")
69
- klass = Module
70
- module_name = module_name.delete_prefix("::")
71
- end
72
-
73
- path = module_name.split("::")
74
-
75
- path.inject(klass) do |acc, elem|
76
- acc.const_get(elem)
77
- end
78
- rescue NameError
79
- nil
80
- end
81
- end
82
- end
83
- 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 have occurred in the session."
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