ruby-lsp-rails 0.2.5 → 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: 3f106a4e09cd422c12e9a0f37ccde59d2109b112ee3e18034c0bb936222163a9
4
- data.tar.gz: ca1913381a10880dcefd6acb8b0d9ae0bec710e2ab536f585cccb1d45a1d99ee
3
+ metadata.gz: 70557479de3e98dce68fda3bf76ee6ee6a547ee2d123b7e26bf687306bdd1879
4
+ data.tar.gz: 1c4560bc452b582ef4c40f793977ef4854cb4e8877bbd3850dbc1aa34b9e4f4a
5
5
  SHA512:
6
- metadata.gz: 465c65b6f461df63477df037c2215678cad6b281f446492d6bbb39bc507cee0e8c7d4041887fbef113150f1183e5227e7e9741cf900ec7f43d971e1aa57943ca
7
- data.tar.gz: e18b7e33f3fef5239bfe0bae3cd8b16baef0d7de692844f6e497add223aab9ecab0601beed1f7f6ffc03ddc3de2a4fa0b175503d1a7d9f423ffd3fcae41ab22e
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
 
@@ -46,47 +46,45 @@ module RubyLsp
46
46
  def initialize(uri, emitter, message_queue)
47
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
 
@@ -31,12 +31,17 @@ module RubyLsp
31
31
 
32
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
@@ -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.5"
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.5
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-09-12 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.10.0
33
+ version: 0.11.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 0.11.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.10.0
43
+ version: 0.11.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.11.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.19
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: []