ruby-lsp-rails 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79a5ef8571e1fd77b8bbd08a782ef68f1116ce4b71e206eee890d573dd2b90dd
4
- data.tar.gz: de8459cb09768c703b0f864f008238a40b78210acdef0e9eba8f4d4fd37c65d7
3
+ metadata.gz: 70557479de3e98dce68fda3bf76ee6ee6a547ee2d123b7e26bf687306bdd1879
4
+ data.tar.gz: 1c4560bc452b582ef4c40f793977ef4854cb4e8877bbd3850dbc1aa34b9e4f4a
5
5
  SHA512:
6
- metadata.gz: f0160d705fba4c081925b29efce3b2d8cc9a8243e8b9e53fa8a7820ffe62b5f0ecf12c73d5546b38f3289d807018f7bc7cbd82acbc296a2151c342ffcbf709be
7
- data.tar.gz: 7d033dea267d94c5068bbbf4698e2c5b8bab63708021f78c67a90eed6b2e43c7a48e731a68fa5bd7c8d3a0c49a55eb600b14f1d40001f70fb050cbb5a538a7d4
6
+ metadata.gz: 01c4c4e000f1d0fb7996ed31a9474bc36a0ddabebdfe3d71dc276572172f0421be818037fb5d001bb77a8bd48cfd58466d1c3431595b8aad071466011f4e4d02
7
+ data.tar.gz: 937340398445803a2413513a739c771bc9e21ae41813bd5529c3c68c654a2714803a0a9cf3d6d850df279188d8ef2d565767f1f157481091e5c8be891e3c0af5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ruby LSP Rails
2
2
 
3
- Ruby LSP Rails is a [Ruby LSP](https://github.com/Shopify/ruby-lsp) extension for extra Rails editor features, such as:
3
+ Ruby LSP Rails is a [Ruby LSP](https://github.com/Shopify/ruby-lsp) addon for extra Rails editor features, such as:
4
4
 
5
5
  - Displaying an ActiveRecord model's database columns and types when hovering over it
6
6
  - Running tests and debugging tests through the terminal or the editor's UI
@@ -56,7 +56,7 @@ cause the test runner to hang.
56
56
  This gem consists of two components that enable enhanced Rails functionality in the editor:
57
57
 
58
58
  1. A Rack app that automatically exposes APIs when Rails server is running
59
- 1. A Ruby LSP extension that connects to the exposed APIs to fetch runtime information from the Rails server
59
+ 1. A Ruby LSP addon that connects to the exposed APIs to fetch runtime information from the Rails server
60
60
 
61
61
  This is why the Rails server needs to be running for some features to work.
62
62
 
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "ruby_lsp/extension"
4
+ require "ruby_lsp/addon"
5
5
 
6
6
  require_relative "rails_client"
7
7
  require_relative "hover"
@@ -9,7 +9,7 @@ require_relative "code_lens"
9
9
 
10
10
  module RubyLsp
11
11
  module Rails
12
- class Extension < ::RubyLsp::Extension
12
+ class Addon < ::RubyLsp::Addon
13
13
  extend T::Sig
14
14
 
15
15
  sig { returns(RailsClient) }
@@ -39,11 +39,13 @@ module RubyLsp
39
39
 
40
40
  sig do
41
41
  override.params(
42
+ nesting: T::Array[String],
43
+ index: RubyIndexer::Index,
42
44
  emitter: EventEmitter,
43
45
  message_queue: Thread::Queue,
44
46
  ).returns(T.nilable(Listener[T.nilable(Interface::Hover)]))
45
47
  end
46
- def create_hover_listener(emitter, message_queue)
48
+ def create_hover_listener(nesting, index, emitter, message_queue)
47
49
  Hover.new(client, emitter, message_queue)
48
50
  end
49
51
 
@@ -40,53 +40,51 @@ module RubyLsp
40
40
  BASE_COMMAND = "bin/rails test"
41
41
 
42
42
  sig { override.returns(ResponseType) }
43
- attr_reader :response
43
+ attr_reader :_response
44
44
 
45
45
  sig { params(uri: URI::Generic, emitter: EventEmitter, message_queue: Thread::Queue).void }
46
46
  def initialize(uri, emitter, message_queue)
47
- @response = T.let([], ResponseType)
47
+ @_response = T.let([], ResponseType)
48
48
  @path = T.let(uri.to_standardized_path, T.nilable(String))
49
- emitter.register(self, :on_command, :on_class, :on_def)
49
+ emitter.register(self, :on_call, :on_class, :on_def)
50
50
 
51
51
  super(emitter, message_queue)
52
52
  end
53
53
 
54
- sig { params(node: SyntaxTree::Command).void }
55
- def on_command(node)
56
- message_value = node.message.value
57
- return unless message_value == "test" && node.arguments.parts.any?
54
+ sig { params(node: YARP::CallNode).void }
55
+ def on_call(node)
56
+ message_value = node.message
57
+ return unless message_value == "test"
58
58
 
59
- first_argument = node.arguments.parts.first
59
+ arguments = node.arguments&.arguments
60
+ return unless arguments&.any?
60
61
 
61
- parts = case first_argument
62
- when SyntaxTree::StringConcat
62
+ first_argument = arguments.first
63
+
64
+ content = case first_argument
65
+ when YARP::StringConcatNode
66
+ left = first_argument.left
67
+ right = first_argument.right
63
68
  # We only support two lines of concatenation on test names
64
- if first_argument.left.is_a?(SyntaxTree::StringLiteral) &&
65
- first_argument.right.is_a?(SyntaxTree::StringLiteral)
66
- [*first_argument.left.parts, *first_argument.right.parts]
69
+ if left.is_a?(YARP::StringNode) &&
70
+ right.is_a?(YARP::StringNode)
71
+ left.content + right.content
67
72
  end
68
- when SyntaxTree::StringLiteral
69
- first_argument.parts
73
+ when YARP::StringNode
74
+ first_argument.content
70
75
  end
71
76
 
72
- # The test name may be a blank string while the code is being typed
73
- return if parts.nil? || parts.empty?
74
-
75
- # We can't handle interpolation yet
76
- return unless parts.all? { |part| part.is_a?(SyntaxTree::TStringContent) }
77
-
78
- test_name = parts.map(&:value).join
79
- return if test_name.empty?
77
+ return unless content && !content.empty?
80
78
 
81
79
  line_number = node.location.start_line
82
80
  command = "#{BASE_COMMAND} #{@path}:#{line_number}"
83
- add_test_code_lens(node, name: test_name, command: command, kind: :example)
81
+ add_test_code_lens(node, name: content, command: command, kind: :example)
84
82
  end
85
83
 
86
84
  # Although uncommon, Rails tests can be written with the classic "def test_name" syntax.
87
- sig { params(node: SyntaxTree::DefNode).void }
85
+ sig { params(node: YARP::DefNode).void }
88
86
  def on_def(node)
89
- method_name = node.name.value
87
+ method_name = node.name.to_s
90
88
  if method_name.start_with?("test_")
91
89
  line_number = node.location.start_line
92
90
  command = "#{BASE_COMMAND} #{@path}:#{line_number}"
@@ -94,9 +92,9 @@ module RubyLsp
94
92
  end
95
93
  end
96
94
 
97
- sig { params(node: SyntaxTree::ClassDeclaration).void }
95
+ sig { params(node: YARP::ClassNode).void }
98
96
  def on_class(node)
99
- class_name = node.constant.constant.value
97
+ class_name = node.constant_path.slice
100
98
  if class_name.end_with?("Test")
101
99
  command = "#{BASE_COMMAND} #{@path}"
102
100
  add_test_code_lens(node, name: class_name, command: command, kind: :group)
@@ -105,7 +103,7 @@ module RubyLsp
105
103
 
106
104
  private
107
105
 
108
- sig { params(node: SyntaxTree::Node, name: String, command: String, kind: Symbol).void }
106
+ sig { params(node: YARP::Node, name: String, command: String, kind: Symbol).void }
109
107
  def add_test_code_lens(node, name:, command:, kind:)
110
108
  return unless @path
111
109
 
@@ -121,7 +119,7 @@ module RubyLsp
121
119
  },
122
120
  ]
123
121
 
124
- @response << create_code_lens(
122
+ @_response << create_code_lens(
125
123
  node,
126
124
  title: "Run",
127
125
  command_name: "rubyLsp.runTest",
@@ -129,7 +127,7 @@ module RubyLsp
129
127
  data: { type: "test", kind: kind },
130
128
  )
131
129
 
132
- @response << create_code_lens(
130
+ @_response << create_code_lens(
133
131
  node,
134
132
  title: "Run In Terminal",
135
133
  command_name: "rubyLsp.runTestInTerminal",
@@ -137,7 +135,7 @@ module RubyLsp
137
135
  data: { type: "test_in_terminal", kind: kind },
138
136
  )
139
137
 
140
- @response << create_code_lens(
138
+ @_response << create_code_lens(
141
139
  node,
142
140
  title: "Debug",
143
141
  command_name: "rubyLsp.debugTest",
@@ -23,20 +23,25 @@ module RubyLsp
23
23
  ResponseType = type_member { { fixed: T.nilable(::RubyLsp::Interface::Hover) } }
24
24
 
25
25
  sig { override.returns(ResponseType) }
26
- attr_reader :response
26
+ attr_reader :_response
27
27
 
28
28
  sig { params(client: RailsClient, emitter: RubyLsp::EventEmitter, message_queue: Thread::Queue).void }
29
29
  def initialize(client, emitter, message_queue)
30
30
  super(emitter, message_queue)
31
31
 
32
- @response = T.let(nil, ResponseType)
32
+ @_response = T.let(nil, ResponseType)
33
33
  @client = client
34
- emitter.register(self, :on_const, :on_command, :on_const_path_ref, :on_call)
34
+ emitter.register(self, :on_constant_path, :on_constant_read, :on_call)
35
35
  end
36
36
 
37
- sig { params(node: SyntaxTree::Const).void }
38
- def on_const(node)
39
- model = @client.model(node.value)
37
+ sig { params(node: YARP::ConstantPathNode).void }
38
+ def on_constant_path(node)
39
+ @_response = generate_rails_document_link_hover(node.slice, node.location)
40
+ end
41
+
42
+ sig { params(node: YARP::ConstantReadNode).void }
43
+ def on_constant_read(node)
44
+ model = @client.model(node.name.to_s)
40
45
  return if model.nil?
41
46
 
42
47
  schema_file = model[:schema_file]
@@ -46,37 +51,28 @@ module RubyLsp
46
51
  end
47
52
  content << model[:columns].map { |name, type| "**#{name}**: #{type}\n" }.join("\n")
48
53
  contents = RubyLsp::Interface::MarkupContent.new(kind: "markdown", value: content)
49
- @response = RubyLsp::Interface::Hover.new(range: range_from_syntax_tree_node(node), contents: contents)
50
- end
51
-
52
- sig { params(node: SyntaxTree::Command).void }
53
- def on_command(node)
54
- message = node.message
55
- @response = generate_rails_document_link_hover(message.value, message)
54
+ @_response = RubyLsp::Interface::Hover.new(range: range_from_node(node), contents: contents)
56
55
  end
57
56
 
58
- sig { params(node: SyntaxTree::ConstPathRef).void }
59
- def on_const_path_ref(node)
60
- @response = generate_rails_document_link_hover(full_constant_name(node), node)
61
- end
62
-
63
- sig { params(node: SyntaxTree::CallNode).void }
57
+ sig { params(node: YARP::CallNode).void }
64
58
  def on_call(node)
65
- message = node.message
66
- return if message.is_a?(Symbol)
59
+ message_value = node.message
60
+ message_loc = node.message_loc
61
+
62
+ return unless message_value && message_loc
67
63
 
68
- @response = generate_rails_document_link_hover(message.value, message)
64
+ @_response = generate_rails_document_link_hover(message_value, message_loc)
69
65
  end
70
66
 
71
67
  private
72
68
 
73
- sig { params(name: String, node: SyntaxTree::Node).returns(T.nilable(Interface::Hover)) }
74
- def generate_rails_document_link_hover(name, node)
69
+ sig { params(name: String, location: YARP::Location).returns(T.nilable(Interface::Hover)) }
70
+ def generate_rails_document_link_hover(name, location)
75
71
  urls = Support::RailsDocumentClient.generate_rails_document_urls(name)
76
72
  return if urls.empty?
77
73
 
78
74
  contents = RubyLsp::Interface::MarkupContent.new(kind: "markdown", value: urls.join("\n\n"))
79
- RubyLsp::Interface::Hover.new(range: range_from_syntax_tree_node(node), contents: contents)
75
+ RubyLsp::Interface::Hover.new(range: range_from_location(location), contents: contents)
80
76
  end
81
77
  end
82
78
  end
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "rails/railtie"
4
+ require "rails"
5
5
  require "ruby_lsp_rails/rack_app"
6
6
 
7
7
  module RubyLsp
@@ -27,8 +27,8 @@ module RubyLsp
27
27
  app_uri_path.write(app_uri)
28
28
 
29
29
  at_exit do
30
- # The app_uri.txt file should only exist when the server is running. The extension uses its presence to
31
- # report if the server is running or not. If the server is not running, some of the extension features
30
+ # The app_uri.txt file should only exist when the server is running. The addon uses its presence to
31
+ # report if the server is running or not. If the server is not running, some of the addon features
32
32
  # will not be available.
33
33
  File.delete(app_uri_path) if File.exist?(app_uri_path)
34
34
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module RubyLsp
5
5
  module Rails
6
- VERSION = "0.2.4"
6
+ VERSION = "0.2.6"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-30 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,20 +30,20 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.1
33
+ version: 0.11.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 0.10.0
36
+ version: 0.12.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.9.1
43
+ version: 0.11.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.10.0
46
+ version: 0.12.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sorbet-runtime
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 0.5.9897
61
- description: A Ruby LSP extension that adds extra editor functionality for Rails applications
61
+ description: A Ruby LSP addon that adds extra editor functionality for Rails applications
62
62
  email:
63
63
  - ruby@shopify.com
64
64
  executables: []
@@ -69,8 +69,8 @@ files:
69
69
  - README.md
70
70
  - Rakefile
71
71
  - lib/ruby-lsp-rails.rb
72
+ - lib/ruby_lsp/ruby_lsp_rails/addon.rb
72
73
  - lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
73
- - lib/ruby_lsp/ruby_lsp_rails/extension.rb
74
74
  - lib/ruby_lsp/ruby_lsp_rails/hover.rb
75
75
  - lib/ruby_lsp/ruby_lsp_rails/rails_client.rb
76
76
  - lib/ruby_lsp/ruby_lsp_rails/support/rails_document_client.rb
@@ -101,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  requirements: []
104
- rubygems_version: 3.4.18
104
+ rubygems_version: 3.4.20
105
105
  signing_key:
106
106
  specification_version: 4
107
- summary: A Ruby LSP extension for Rails
107
+ summary: A Ruby LSP addon for Rails
108
108
  test_files: []