ruby-lsp-rails 0.3.14 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -20
- data/Rakefile +0 -15
- data/lib/ruby_lsp/ruby_lsp_rails/code_lens.rb +1 -1
- data/lib/ruby_lsp/ruby_lsp_rails/indexing_enhancement.rb +2 -2
- data/lib/ruby_lsp/ruby_lsp_rails/server.rb +30 -23
- data/lib/ruby_lsp_rails/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bab18094b00d6c5e6a61b22061f927fbca1f4b57ce40da04eca22081ab264385
|
4
|
+
data.tar.gz: 7a253986008708cb5d5af08b6409039aeba2b54d0d605270f652fba9178a99ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5021b0f2dadbb18464e473f26d9bfee94ed22b02b53eec5c1c44ade37f1ab989c0b80c4169f722ca4e38c498344ccd5e19334324508aac8f6d3c0e21bd6ec35
|
7
|
+
data.tar.gz: 26813fab8da91e99d6f708dadc1ef631df0d1791addb608e06a366bfebcac5643c5d0978d0bc0778d76c3d74572a78a0a8b361fba90f373db759b54a81f9a388
|
data/README.md
CHANGED
@@ -1,35 +1,20 @@
|
|
1
1
|
[![Ruby DX Slack](https://img.shields.io/badge/Slack-Ruby%20DX-success?logo=slack)](https://join.slack.com/t/ruby-dx/shared_invite/zt-2c8zjlir6-uUDJl8oIwcen_FS_aA~b6Q)
|
2
2
|
|
3
|
-
#
|
3
|
+
# Rails addon
|
4
4
|
|
5
|
-
|
5
|
+
The Rails addon is a [Ruby LSP](https://github.com/Shopify/ruby-lsp) [addon](https://shopify.github.io/ruby-lsp/addons.html) for extra [Rails editor features](https://shopify.github.io/ruby-lsp/rails-addon.html).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
If you haven't already done so, you'll need to first [set up Ruby LSP](https://github.
|
9
|
+
If you haven't already done so, you'll need to first [set up Ruby LSP](https://shopify.github.io/ruby-lsp/#usage).
|
10
10
|
|
11
11
|
As of v0.3.0, Ruby LSP will automatically include the Ruby LSP Rails addon in its custom bundle when a Rails app is detected.
|
12
12
|
There is no need to add the gem to your bundle.
|
13
13
|
|
14
14
|
## Documentation
|
15
15
|
|
16
|
-
See the [documentation](https://shopify.github.io/ruby-lsp-
|
17
|
-
[supported features](https://shopify.github.io/ruby-lsp-
|
18
|
-
|
19
|
-
## How Runtime Introspection Works
|
20
|
-
|
21
|
-
LSP tooling is typically based on static analysis, but `ruby-lsp-rails` actually communicates with your Rails app for
|
22
|
-
some features.
|
23
|
-
|
24
|
-
When Ruby LSP Rails starts, it spawns a `rails runner` instance which runs
|
25
|
-
[`server.rb`](https://github.com/Shopify/ruby-lsp-rails/blob/main/lib/ruby_lsp/ruby_lsp_rails/server.rb).
|
26
|
-
The addon communicates with this process over a pipe (i.e. `stdin` and `stdout`) to fetch runtime information about the application.
|
27
|
-
|
28
|
-
When extension is stopped (e.g. by quitting the editor), the server instance is shut down.
|
29
|
-
|
30
|
-
> [!NOTE]
|
31
|
-
> Prior to v0.3.0, `ruby-lsp-rails` used a different approach which involved mounting a Rack application within the Rails app.
|
32
|
-
> That approach was brittle and susceptible to the application's configuration, such as routing and middleware.
|
16
|
+
See the [documentation](https://shopify.github.io/ruby-lsp/rails-addon.html) for more in-depth details about the
|
17
|
+
[supported features](https://shopify.github.io/ruby-lsp/rails-addon.html#features).
|
33
18
|
|
34
19
|
## Contributing
|
35
20
|
|
data/Rakefile
CHANGED
@@ -9,8 +9,6 @@ load "rails/tasks/statistics.rake"
|
|
9
9
|
|
10
10
|
require "bundler/gem_tasks"
|
11
11
|
require "rake/testtask"
|
12
|
-
require "ruby_lsp/check_docs"
|
13
|
-
require "rdoc/task"
|
14
12
|
|
15
13
|
Rake::TestTask.new(:test) do |t|
|
16
14
|
t.libs << "test"
|
@@ -18,17 +16,4 @@ Rake::TestTask.new(:test) do |t|
|
|
18
16
|
t.test_files = FileList["test/**/*_test.rb"]
|
19
17
|
end
|
20
18
|
|
21
|
-
RDoc::Task.new do |rdoc|
|
22
|
-
rdoc.main = "README.md"
|
23
|
-
rdoc.rdoc_files.include("*.md", "lib/**/*.rb")
|
24
|
-
rdoc.rdoc_dir = "docs"
|
25
|
-
rdoc.markup = "markdown"
|
26
|
-
rdoc.title = "Ruby LSP Rails"
|
27
|
-
rdoc.generator = "snapper"
|
28
|
-
rdoc.options.push("--copy-files", "misc")
|
29
|
-
rdoc.options.push("--copy-files", "LICENSE.txt")
|
30
|
-
end
|
31
|
-
|
32
|
-
RubyLsp::CheckDocs.new(FileList["#{__dir__}/lib/ruby_lsp/**/*.rb"], FileList["#{__dir__}/misc/**/*.gif"])
|
33
|
-
|
34
19
|
task default: [:"db:setup", :test]
|
@@ -151,7 +151,7 @@ module RubyLsp
|
|
151
151
|
@group_id += 1
|
152
152
|
end
|
153
153
|
|
154
|
-
if superclass_name&.start_with?("ActiveRecord::Migration")
|
154
|
+
if @path && superclass_name&.start_with?("ActiveRecord::Migration")
|
155
155
|
command = "#{migrate_command} VERSION=#{migration_version}"
|
156
156
|
add_migrate_code_lens(node, name: class_name, command: command)
|
157
157
|
end
|
@@ -59,7 +59,7 @@ module RubyLsp
|
|
59
59
|
file_path,
|
60
60
|
name_arg.location,
|
61
61
|
name_arg.location,
|
62
|
-
|
62
|
+
nil,
|
63
63
|
[RubyIndexer::Entry::Signature.new([])],
|
64
64
|
RubyIndexer::Entry::Visibility::PUBLIC,
|
65
65
|
owner,
|
@@ -71,7 +71,7 @@ module RubyLsp
|
|
71
71
|
file_path,
|
72
72
|
name_arg.location,
|
73
73
|
name_arg.location,
|
74
|
-
|
74
|
+
nil,
|
75
75
|
[RubyIndexer::Entry::Signature.new([RubyIndexer::Entry::RequiredParameter.new(name: name.to_sym)])],
|
76
76
|
RubyIndexer::Entry::Visibility::PUBLIC,
|
77
77
|
owner,
|
@@ -9,13 +9,23 @@ require "json"
|
|
9
9
|
module RubyLsp
|
10
10
|
module Rails
|
11
11
|
class Server
|
12
|
-
|
12
|
+
def initialize(stdout: $stdout, override_default_output_device: true)
|
13
|
+
# Grab references to the original pipes so that we can change the default output device further down
|
14
|
+
@stdin = $stdin
|
15
|
+
@stdout = stdout
|
16
|
+
@stderr = $stderr
|
17
|
+
@stdin.sync = true
|
18
|
+
@stdout.sync = true
|
19
|
+
@stderr.sync = true
|
20
|
+
@stdin.binmode
|
21
|
+
@stdout.binmode
|
22
|
+
@stderr.binmode
|
23
|
+
|
24
|
+
# # Set the default output device to be $stderr. This means that using `puts` by itself will default to printing
|
25
|
+
# # to $stderr and only explicit `$stdout.puts` will go to $stdout. This reduces the chance that output coming
|
26
|
+
# # from the Rails app will be accidentally sent to the client
|
27
|
+
$> = $stderr if override_default_output_device
|
13
28
|
|
14
|
-
def initialize
|
15
|
-
$stdin.sync = true
|
16
|
-
$stdout.sync = true
|
17
|
-
$stdin.binmode
|
18
|
-
$stdout.binmode
|
19
29
|
@running = true
|
20
30
|
end
|
21
31
|
|
@@ -25,18 +35,14 @@ module RubyLsp
|
|
25
35
|
routes_reloader.execute_unless_loaded if routes_reloader&.respond_to?(:execute_unless_loaded)
|
26
36
|
|
27
37
|
initialize_result = { result: { message: "ok", root: ::Rails.root.to_s } }.to_json
|
28
|
-
|
38
|
+
@stdout.write("Content-Length: #{initialize_result.length}\r\n\r\n#{initialize_result}")
|
29
39
|
|
30
40
|
while @running
|
31
|
-
headers =
|
32
|
-
json =
|
41
|
+
headers = @stdin.gets("\r\n\r\n")
|
42
|
+
json = @stdin.read(headers[/Content-Length: (\d+)/i, 1].to_i)
|
33
43
|
|
34
44
|
request = JSON.parse(json, symbolize_names: true)
|
35
|
-
|
36
|
-
next if response == VOID
|
37
|
-
|
38
|
-
json_response = response.to_json
|
39
|
-
$stdout.write("Content-Length: #{json_response.length}\r\n\r\n#{json_response}")
|
45
|
+
execute(request.fetch(:method), request[:params])
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
@@ -44,27 +50,28 @@ module RubyLsp
|
|
44
50
|
case request
|
45
51
|
when "shutdown"
|
46
52
|
@running = false
|
47
|
-
VOID
|
48
53
|
when "model"
|
49
|
-
resolve_database_info_from_model(params.fetch(:name))
|
54
|
+
write_response(resolve_database_info_from_model(params.fetch(:name)))
|
50
55
|
when "association_target_location"
|
51
|
-
resolve_association_target(params)
|
56
|
+
write_response(resolve_association_target(params))
|
52
57
|
when "reload"
|
53
58
|
::Rails.application.reloader.reload!
|
54
|
-
VOID
|
55
59
|
when "route_location"
|
56
|
-
route_location(params.fetch(:name))
|
60
|
+
write_response(route_location(params.fetch(:name)))
|
57
61
|
when "route_info"
|
58
|
-
resolve_route_info(params)
|
59
|
-
else
|
60
|
-
VOID
|
62
|
+
write_response(resolve_route_info(params))
|
61
63
|
end
|
62
64
|
rescue => e
|
63
|
-
{ error: e.full_message(highlight: false) }
|
65
|
+
write_response({ error: e.full_message(highlight: false) })
|
64
66
|
end
|
65
67
|
|
66
68
|
private
|
67
69
|
|
70
|
+
def write_response(response)
|
71
|
+
json_response = response.to_json
|
72
|
+
@stdout.write("Content-Length: #{json_response.length}\r\n\r\n#{json_response}")
|
73
|
+
end
|
74
|
+
|
68
75
|
def resolve_route_info(requirements)
|
69
76
|
if requirements[:controller]
|
70
77
|
requirements[:controller] = requirements.fetch(:controller).underscore.delete_suffix("_controller")
|
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.3.
|
4
|
+
version: 0.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-lsp
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.18.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.19.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: 0.18.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.19.0
|
33
33
|
description: A Ruby LSP addon that adds extra editor functionality for Rails applications
|
34
34
|
email:
|
35
35
|
- ruby@shopify.com
|
@@ -65,6 +65,7 @@ metadata:
|
|
65
65
|
homepage_uri: https://github.com/Shopify/ruby-lsp-rails
|
66
66
|
source_code_uri: https://github.com/Shopify/ruby-lsp-rails
|
67
67
|
changelog_uri: https://github.com/Shopify/ruby-lsp-rails/releases
|
68
|
+
documentation_uri: https://shopify.github.io/ruby-lsp/rails-addon.html
|
68
69
|
post_install_message:
|
69
70
|
rdoc_options: []
|
70
71
|
require_paths:
|