rider-server 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.build.yml +23 -0
  3. data/.ruby-version +1 -0
  4. data/.standard.yml +3 -0
  5. data/CHANGELOG.md +5 -0
  6. data/README.md +44 -0
  7. data/Rakefile +12 -0
  8. data/exe/rider-server +11 -0
  9. data/lib/rider_server/core_ext/array.rb +32 -0
  10. data/lib/rider_server/core_ext/hash.rb +14 -0
  11. data/lib/rider_server/core_ext/object.rb +18 -0
  12. data/lib/rider_server/core_ext/string.rb +18 -0
  13. data/lib/rider_server/core_ext/symbol.rb +14 -0
  14. data/lib/rider_server/errors.rb +16 -0
  15. data/lib/rider_server/exception_extension.rb +34 -0
  16. data/lib/rider_server/inspect.rb +148 -0
  17. data/lib/rider_server/logger.rb +13 -0
  18. data/lib/rider_server/operation.rb +69 -0
  19. data/lib/rider_server/operations.rb +136 -0
  20. data/lib/rider_server/ops/clone.rb +32 -0
  21. data/lib/rider_server/ops/close.rb +25 -0
  22. data/lib/rider_server/ops/completions.rb +100 -0
  23. data/lib/rider_server/ops/eval.rb +62 -0
  24. data/lib/rider_server/ops/inspect.rb +121 -0
  25. data/lib/rider_server/ops/inspect_exception.rb +47 -0
  26. data/lib/rider_server/ops/interrupt.rb +30 -0
  27. data/lib/rider_server/ops/load_path.rb +20 -0
  28. data/lib/rider_server/ops/lookup.rb +83 -0
  29. data/lib/rider_server/ops/ls_exceptions.rb +29 -0
  30. data/lib/rider_server/ops/ls_services.rb +19 -0
  31. data/lib/rider_server/ops/ls_sessions.rb +52 -0
  32. data/lib/rider_server/ops/service.rb +43 -0
  33. data/lib/rider_server/ops/set_namespace.rb +79 -0
  34. data/lib/rider_server/ops/set_namespace_variable.rb +80 -0
  35. data/lib/rider_server/ops/stdin.rb +20 -0
  36. data/lib/rider_server/ops/toggle_catch_all_exceptions.rb +27 -0
  37. data/lib/rider_server/response.rb +69 -0
  38. data/lib/rider_server/server.rb +104 -0
  39. data/lib/rider_server/service.rb +20 -0
  40. data/lib/rider_server/services/capture_exceptions.rb +62 -0
  41. data/lib/rider_server/services/capture_io.rb +302 -0
  42. data/lib/rider_server/services/rails.rb +129 -0
  43. data/lib/rider_server/session.rb +190 -0
  44. data/lib/rider_server/transports/bencode.rb +0 -0
  45. data/lib/rider_server/utils.rb +63 -0
  46. data/lib/rider_server/version.rb +12 -0
  47. data/lib/rider_server/workspace.rb +111 -0
  48. data/lib/rider_server.rb +5 -0
  49. metadata +122 -0
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # workspace.rb -- The workspace that code is executed in
5
+ #
6
+ # Author: Russell Sim
7
+ # Copyright (c) 2024 Russell Sim
8
+ # SPDX-License-Identifier: MIT
9
+
10
+ require "rider_server/logger"
11
+ require "rider_server/utils"
12
+ require "parser/current"
13
+
14
+ RiderServer::TOPLEVEL_BINDING = binding
15
+ module RiderServer
16
+ class Workspace
17
+ include RiderServer::Logger
18
+
19
+ def initialize
20
+ @binding_name = "main"
21
+ @binding = TOPLEVEL_BINDING
22
+ end
23
+
24
+ def set_namespace(namespace)
25
+ if namespace == "main"
26
+ @binding_name = "main"
27
+ @binding = TOPLEVEL_BINDING
28
+ else
29
+ @binding, @binding_name = create_binding(namespace)
30
+ end
31
+ end
32
+
33
+ def namespace_name
34
+ @binding_name
35
+ end
36
+
37
+ # Evaluate the given statements in the context of the workspace
38
+ # See https://ruby-hacking-guide.github.io/anyeval.html
39
+ def evaluate(statements, ns = @binding, file = "", line = 0)
40
+ ns = if ns.nil?
41
+ @binding
42
+ elsif ns.is_a?(String) && ns.empty? || ns == "main"
43
+ TOPLEVEL_BINDING
44
+ elsif ns.is_a?(String)
45
+ ns, _ = create_binding(lookup_module(ns))
46
+ ns
47
+ else # ns is a class, module or instance
48
+ ns, _ = create_binding(ns)
49
+ ns
50
+ end
51
+
52
+ eval(statements, ns, file, line) # rubocop:disable Security/Eval
53
+ end
54
+
55
+ def binding_local_variable_set(name, value, ns = @binding)
56
+ ns.local_variable_set(name.to_sym, value)
57
+ end
58
+
59
+ # Lookup a module by a namespace for example ::RiderServer::Workspace
60
+ # the defaulting starting module is Object.
61
+ # https://ruby-doc.org/3.2.2/Module.html#method-i-const_get
62
+ def lookup_module(module_name, klass = ::Object)
63
+ if module_name.empty?
64
+ klass
65
+ else
66
+ lookup_module_ast(parse_string(module_name), klass)
67
+ end
68
+ end
69
+
70
+ def parse_string(string)
71
+ buffer = Parser::Source::Buffer.new("(string)")
72
+ buffer.source = string
73
+ Parser::CurrentRuby.new.parse(buffer)
74
+ end
75
+
76
+ def lookup_module_ast(node, klass = ::Object)
77
+ case node.type
78
+ when :cbase
79
+ ::Object
80
+ when :const
81
+ if node.children.first.nil?
82
+ klass.const_get(node.children.last)
83
+ else
84
+ lookup_module_ast(node.children.first, klass).const_get(node.children.last)
85
+ end
86
+ else
87
+ raise ModuleLookupError, "Unknown node type #{node.type}"
88
+ end
89
+ end
90
+
91
+ def create_binding(obj)
92
+ if obj.is_a?(Binding)
93
+ [obj, obj.inspect]
94
+ elsif obj.is_a?(Class)
95
+ [obj.class_eval("binding", __FILE__, __LINE__), obj.name]
96
+ elsif obj.is_a?(Module)
97
+ [obj.module_eval("binding", __FILE__, __LINE__), obj.name]
98
+ else
99
+ [obj.instance_eval("binding", __FILE__, __LINE__), obj.to_s]
100
+ end
101
+ end
102
+
103
+ def binding_name(obj)
104
+ if obj.is_a?(Class) || obj.is_a?(Module)
105
+ obj.name
106
+ else
107
+ obj.to_s
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ # Author: Russell Sim
2
+ # Copyright (c) 2024 Russell Sim
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ require_relative "rider_server/version"
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rider-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Russell Sim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bencode
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: binding_of_caller
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ description: ''
42
+ email:
43
+ - rsl@simopolis.xyz
44
+ executables:
45
+ - rider-server
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".build.yml"
50
+ - ".ruby-version"
51
+ - ".standard.yml"
52
+ - CHANGELOG.md
53
+ - README.md
54
+ - Rakefile
55
+ - exe/rider-server
56
+ - lib/rider_server.rb
57
+ - lib/rider_server/core_ext/array.rb
58
+ - lib/rider_server/core_ext/hash.rb
59
+ - lib/rider_server/core_ext/object.rb
60
+ - lib/rider_server/core_ext/string.rb
61
+ - lib/rider_server/core_ext/symbol.rb
62
+ - lib/rider_server/errors.rb
63
+ - lib/rider_server/exception_extension.rb
64
+ - lib/rider_server/inspect.rb
65
+ - lib/rider_server/logger.rb
66
+ - lib/rider_server/operation.rb
67
+ - 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
85
+ - lib/rider_server/response.rb
86
+ - lib/rider_server/server.rb
87
+ - lib/rider_server/service.rb
88
+ - lib/rider_server/services/capture_exceptions.rb
89
+ - lib/rider_server/services/capture_io.rb
90
+ - lib/rider_server/services/rails.rb
91
+ - lib/rider_server/session.rb
92
+ - lib/rider_server/transports/bencode.rb
93
+ - lib/rider_server/utils.rb
94
+ - lib/rider_server/version.rb
95
+ - lib/rider_server/workspace.rb
96
+ homepage: https://sr.ht/~rsl/rider-server/
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://sr.ht/~rsl/rider-server/
101
+ source_code_uri: https://git.sr.ht/~rsl/rider-server/
102
+ changelog_uri: https://git.sr.ht/~rsl/rider-server/tree/master/item/CHANGELOG.md
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "<"
110
+ - !ruby/object:Gem::Version
111
+ version: 3.2.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.3.27
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: RIDER an nREPL server for Ruby
122
+ test_files: []