ruby-lsp-rails 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5133a59bd3960baa206580c91b1504a91a94089591ea6211123038f28c40eaf7
4
- data.tar.gz: 618627944a25edf11210afebc4f45112554125f8021787048a159ac13af0d15f
3
+ metadata.gz: 23121486fc120767731f9aa1e710d7e6a80ffa6a3832ea87cf3d142e6a3adb59
4
+ data.tar.gz: 75d08ce0a40859d1d45a6244ba5efc4d582eef554df5ea36332d486190ec5e71
5
5
  SHA512:
6
- metadata.gz: 6f3e0395d614c55814e33fd52843e714458d7dd17b1460bb0ee64a796159138e42e6d4455d7a0e9cfb5648ca3b9609df9659f663e0d426aeb18938b62ef16517
7
- data.tar.gz: 7f3d0408b2122e4ff0a7f6ac82d4cd5e82e2c7d858f801ea19cac06c4043aca81efe4e2a75de1724d854669d1cd1e9fbe8f6b2e7258cd1e3f442868f48e382e3
6
+ metadata.gz: 1b1ffcb3291ab359dbd37218902feb2294e4092f4380111ded16824deab8980f77ce86e87525d34f4debcf7daceca73bac4d655ad52f7668265df943e821d0f5
7
+ data.tar.gz: 7c6d601aa7170cfa330079b1edae2c9d99bd70761c85b09eabdc0232b1789be88abe1451000bf308f57f2216ef6d8c57c29e8662d16b0b40b264952e60208ac3
data/README.md CHANGED
@@ -45,7 +45,7 @@ See the [documentation](https://shopify.github.io/ruby-lsp-rails) for more in-de
45
45
 
46
46
  ### Running Tests
47
47
 
48
- 1. Open a test which inherits from `ActiveSupport::TestCase` or one if its descendants, such as `ActionDispatch::IntegrationTest`.
48
+ 1. Open a test which inherits from `ActiveSupport::TestCase` or one of its descendants, such as `ActionDispatch::IntegrationTest`.
49
49
  2. Click on the "Run", "Run in Terminal" or "Debug" code lens which appears above the test class, or an individual test.
50
50
 
51
51
  Note: When using the Test Explorer view, if your code contains a statement to pause execution (e.g. `debugger`) it will
@@ -39,15 +39,13 @@ module RubyLsp
39
39
  ResponseType = type_member { { fixed: T::Array[::RubyLsp::Interface::CodeLens] } }
40
40
  BASE_COMMAND = "bin/rails test"
41
41
 
42
- ::RubyLsp::Requests::CodeLens.add_listener(self)
43
-
44
42
  sig { override.returns(ResponseType) }
45
43
  attr_reader :response
46
44
 
47
- sig { params(uri: String, emitter: EventEmitter, message_queue: Thread::Queue).void }
45
+ sig { params(uri: URI::Generic, emitter: EventEmitter, message_queue: Thread::Queue).void }
48
46
  def initialize(uri, emitter, message_queue)
49
47
  @response = T.let([], ResponseType)
50
- @path = T.let(URI(uri).path, T.nilable(String))
48
+ @path = T.let(uri.to_standardized_path, T.nilable(String))
51
49
  emitter.register(self, :on_command, :on_class, :on_def)
52
50
 
53
51
  super(emitter, message_queue)
@@ -59,16 +57,26 @@ module RubyLsp
59
57
  return unless message_value == "test" && node.arguments.parts.any?
60
58
 
61
59
  first_argument = node.arguments.parts.first
62
- return unless first_argument.is_a?(SyntaxTree::StringLiteral)
60
+
61
+ parts = case first_argument
62
+ when SyntaxTree::StringConcat
63
+ # 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]
67
+ end
68
+ when SyntaxTree::StringLiteral
69
+ first_argument.parts
70
+ end
63
71
 
64
72
  # The test name may be a blank string while the code is being typed
65
- return if first_argument.parts.empty?
73
+ return if parts.nil? || parts.empty?
66
74
 
67
75
  # We can't handle interpolation yet
68
- return unless first_argument.parts.all? { |part| part.is_a?(SyntaxTree::TStringContent) }
76
+ return unless parts.all? { |part| part.is_a?(SyntaxTree::TStringContent) }
69
77
 
70
- test_name = first_argument.parts.first.value
71
- return unless test_name
78
+ test_name = parts.map(&:value).join
79
+ return if test_name.empty?
72
80
 
73
81
  line_number = node.location.start_line
74
82
  command = "#{BASE_COMMAND} #{@path}:#{line_number}"
@@ -99,6 +107,8 @@ module RubyLsp
99
107
 
100
108
  sig { params(node: SyntaxTree::Node, name: String, command: String, kind: Symbol).void }
101
109
  def add_test_code_lens(node, name:, command:, kind:)
110
+ return unless @path
111
+
102
112
  arguments = [
103
113
  @path,
104
114
  name,
@@ -12,9 +12,39 @@ module RubyLsp
12
12
  class Extension < ::RubyLsp::Extension
13
13
  extend T::Sig
14
14
 
15
+ sig { returns(RailsClient) }
16
+ def client
17
+ @client ||= T.let(RailsClient.new, T.nilable(RailsClient))
18
+ end
19
+
15
20
  sig { override.void }
16
21
  def activate
17
- RubyLsp::Rails::RailsClient.instance.check_if_server_is_running!
22
+ client.check_if_server_is_running!
23
+ end
24
+
25
+ sig { override.void }
26
+ def deactivate; end
27
+
28
+ # Creates a new CodeLens listener. This method is invoked on every CodeLens request
29
+ sig do
30
+ override.params(
31
+ uri: URI::Generic,
32
+ emitter: EventEmitter,
33
+ message_queue: Thread::Queue,
34
+ ).returns(T.nilable(Listener[T::Array[Interface::CodeLens]]))
35
+ end
36
+ def create_code_lens_listener(uri, emitter, message_queue)
37
+ CodeLens.new(uri, emitter, message_queue)
38
+ end
39
+
40
+ sig do
41
+ override.params(
42
+ emitter: EventEmitter,
43
+ message_queue: Thread::Queue,
44
+ ).returns(T.nilable(Listener[T.nilable(Interface::Hover)]))
45
+ end
46
+ def create_hover_listener(emitter, message_queue)
47
+ Hover.new(client, emitter, message_queue)
18
48
  end
19
49
 
20
50
  sig { override.returns(String) }
@@ -20,28 +20,27 @@ module RubyLsp
20
20
 
21
21
  ResponseType = type_member { { fixed: T.nilable(::RubyLsp::Interface::Hover) } }
22
22
 
23
- ::RubyLsp::Requests::Hover.add_listener(self)
24
-
25
23
  sig { override.returns(ResponseType) }
26
24
  attr_reader :response
27
25
 
28
- sig { params(emitter: RubyLsp::EventEmitter, message_queue: Thread::Queue).void }
29
- def initialize(emitter, message_queue)
30
- super
26
+ sig { params(client: RailsClient, emitter: RubyLsp::EventEmitter, message_queue: Thread::Queue).void }
27
+ def initialize(client, emitter, message_queue)
28
+ super(emitter, message_queue)
31
29
 
32
30
  @response = T.let(nil, ResponseType)
31
+ @client = client
33
32
  emitter.register(self, :on_const)
34
33
  end
35
34
 
36
35
  sig { params(node: SyntaxTree::Const).void }
37
36
  def on_const(node)
38
- model = RailsClient.instance.model(node.value)
37
+ model = @client.model(node.value)
39
38
  return if model.nil?
40
39
 
41
40
  schema_file = model[:schema_file]
42
41
  content = +""
43
42
  if schema_file
44
- content << "[Schema](file://#{schema_file})\n\n"
43
+ content << "[Schema](#{URI::Generic.build(scheme: "file", path: schema_file)})\n\n"
45
44
  end
46
45
  content << model[:columns].map { |name, type| "**#{name}**: #{type}\n" }.join("\n")
47
46
  contents = RubyLsp::Interface::MarkupContent.new(kind: "markdown", value: content)
@@ -1,7 +1,6 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "singleton"
5
4
  require "net/http"
6
5
 
7
6
  module RubyLsp
@@ -10,35 +9,27 @@ module RubyLsp
10
9
  class ServerAddressUnknown < StandardError; end
11
10
 
12
11
  extend T::Sig
13
- include Singleton
14
12
 
15
13
  SERVER_NOT_RUNNING_MESSAGE = "Rails server is not running. " \
16
14
  "To get Rails features in the editor, boot the Rails server"
17
15
 
18
- sig { returns(String) }
16
+ sig { returns(Pathname) }
19
17
  attr_reader :root
20
18
 
21
19
  sig { void }
22
20
  def initialize
23
- project_root = Pathname.new(ENV["BUNDLE_GEMFILE"]).dirname
21
+ project_root = T.let(Bundler.with_unbundled_env { Bundler.default_gemfile }.dirname, Pathname)
22
+ dummy_path = project_root.join("test", "dummy")
24
23
 
25
- if project_root.basename.to_s == ".ruby-lsp"
26
- project_root = project_root.join("../")
27
- end
28
-
29
- dummy_path = File.join(project_root, "test", "dummy")
30
- @root = T.let(Dir.exist?(dummy_path) ? dummy_path : project_root.to_s, String)
31
- app_uri_path = "#{@root}/tmp/app_uri.txt"
32
-
33
- if File.exist?(app_uri_path)
34
- url = File.read(app_uri_path).chomp
24
+ @root = T.let(dummy_path.exist? ? dummy_path : project_root, Pathname)
25
+ app_uri_path = @root.join("tmp", "app_uri.txt")
35
26
 
36
- scheme, rest = url.split("://")
37
- uri, port = T.must(rest).split(":")
27
+ if app_uri_path.exist?
28
+ url = URI(app_uri_path.read.chomp)
38
29
 
39
- @ssl = T.let(scheme == "https", T::Boolean)
40
- @uri = T.let(T.must(uri), T.nilable(String))
41
- @port = T.let(T.must(port).to_i, Integer)
30
+ @ssl = T.let(url.scheme == "https", T::Boolean)
31
+ @uri = T.let(T.must(url.path), T.nilable(String))
32
+ @port = T.let(T.must(url.port).to_i, Integer)
42
33
  end
43
34
  end
44
35
 
@@ -48,16 +39,21 @@ module RubyLsp
48
39
  return unless response.code == "200"
49
40
 
50
41
  JSON.parse(response.body.chomp, symbolize_names: true)
51
- rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, Net::ReadTimeout, ServerAddressUnknown
42
+ rescue Errno::ECONNREFUSED,
43
+ Errno::EADDRNOTAVAIL,
44
+ Errno::ECONNRESET,
45
+ Net::ReadTimeout,
46
+ Net::OpenTimeout,
47
+ ServerAddressUnknown
52
48
  nil
53
49
  end
54
50
 
55
51
  sig { void }
56
52
  def check_if_server_is_running!
57
53
  request("activate", 0.2)
58
- rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, ServerAddressUnknown
54
+ rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, Errno::ECONNRESET, ServerAddressUnknown
59
55
  warn(SERVER_NOT_RUNNING_MESSAGE)
60
- rescue Net::ReadTimeout
56
+ rescue Net::ReadTimeout, Net::OpenTimeout
61
57
  # If the server is running, but the initial request is taking too long, we don't want to block the
62
58
  # initialization of the Ruby LSP
63
59
  end
@@ -23,8 +23,8 @@ module RubyLsp
23
23
  if defined?(::Rails::Server)
24
24
  ssl_enable, host, port = ::Rails::Server::Options.new.parse!(ARGV).values_at(:SSLEnable, :Host, :Port)
25
25
  app_uri = "#{ssl_enable ? "https" : "http"}://#{host}:#{port}"
26
- app_uri_path = "#{::Rails.root}/tmp/app_uri.txt"
27
- File.write(app_uri_path, app_uri)
26
+ app_uri_path = ::Rails.root.join("tmp", "app_uri.txt")
27
+ app_uri_path.write(app_uri)
28
28
 
29
29
  at_exit do
30
30
  # The app_uri.txt file should only exist when the server is running. The extension uses its presence to
@@ -3,6 +3,6 @@
3
3
 
4
4
  module RubyLsp
5
5
  module Rails
6
- VERSION = "0.2.2"
6
+ VERSION = "0.2.3"
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-06 00:00:00.000000000 Z
11
+ date: 2023-08-09 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.6.2
33
+ version: 0.8.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 0.8.0
36
+ version: 0.9.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.6.2
43
+ version: 0.8.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.8.0
46
+ version: 0.9.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sorbet-runtime
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.4.14
103
+ rubygems_version: 3.4.17
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: A Ruby LSP extension for Rails