ruby-lsp 0.7.0 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/ruby-lsp +1 -0
- data/lib/ruby_lsp/setup_bundler.rb +142 -75
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dba33af47ce558162b73c39422465b451e4af9e835d9446ff90414de0f44fd66
|
4
|
+
data.tar.gz: fb9b769fceb2563b2392b6395cb65a17511e5dee9614d8158fb28c5bd5628843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b879df720b44940dc838245a174bebc08849d6673a9076b612df90a47036e69fdc367cc7e0dc3df934a762758e36cebea2d6c84e4b3e992023f2bf9056b14f
|
7
|
+
data.tar.gz: 65856714024b1329d693cc49eb3e846af1b7737dfd4f914ddb2b677ddada993cca65f81ec9447605325380aee2564930ee2401efc87e57f9d11e92600533d9ca
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.3
|
data/exe/ruby-lsp
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
# the application's bundle
|
7
7
|
if ENV["BUNDLE_GEMFILE"].nil? && File.exist?("Gemfile.lock")
|
8
8
|
require_relative "../lib/ruby_lsp/setup_bundler"
|
9
|
+
RubyLsp::SetupBundler.new(Dir.pwd).setup!
|
9
10
|
|
10
11
|
# In some cases, like when the `ruby-lsp` is already a part of the bundle, we don't generate `.ruby-lsp/Gemfile`.
|
11
12
|
# However, we still want to run the server with `bundle exec`. We need to make sure we're pointing to the right
|
@@ -1,86 +1,153 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "sorbet-runtime"
|
4
5
|
require "bundler"
|
5
6
|
require "fileutils"
|
6
|
-
require "pathname"
|
7
7
|
|
8
8
|
# This file is a script that will configure a custom bundle for the Ruby LSP. The custom bundle allows developers to use
|
9
9
|
# the Ruby LSP without including the gem in their application's Gemfile while at the same time giving us access to the
|
10
10
|
# exact locked versions of dependencies.
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
module RubyLsp
|
13
|
+
class SetupBundler
|
14
|
+
extend T::Sig
|
15
|
+
|
16
|
+
sig { params(project_path: String).void }
|
17
|
+
def initialize(project_path)
|
18
|
+
@project_path = project_path
|
19
|
+
@dependencies = T.let(load_dependencies, T::Hash[String, T.untyped])
|
20
|
+
@custom_bundle_dependencies = T.let(
|
21
|
+
if File.exist?(".ruby-lsp/Gemfile.lock")
|
22
|
+
Bundler::LockfileParser.new(Bundler.read_file(".ruby-lsp/Gemfile.lock")).dependencies
|
23
|
+
else
|
24
|
+
{}
|
25
|
+
end,
|
26
|
+
T::Hash[String, T.untyped],
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
sig { void }
|
31
|
+
def setup!
|
32
|
+
# Do not setup a custom bundle if we're working on the Ruby LSP, since it's already included by default
|
33
|
+
if File.basename(@project_path) == "ruby-lsp"
|
34
|
+
warn("Ruby LSP> Skipping custom bundle setup since we're working on the Ruby LSP itself")
|
35
|
+
run_bundle_install
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
# Do not setup a custom bundle if both `ruby-lsp` and `debug` are already in the Gemfile
|
40
|
+
if @dependencies["ruby-lsp"] && @dependencies["debug"]
|
41
|
+
warn("Ruby LSP> Skipping custom bundle setup since both `ruby-lsp` and `debug` are already in the Gemfile")
|
42
|
+
|
43
|
+
# If the user decided to add the `ruby-lsp` and `debug` to their Gemfile after having already run the Ruby LSP,
|
44
|
+
# then we need to remove the `.ruby-lsp` folder, otherwise we will run `bundle install` for the top level and
|
45
|
+
# try to execute the Ruby LSP using the custom bundle, which will fail since the gems are not installed there
|
46
|
+
FileUtils.rm_r(".ruby-lsp") if Dir.exist?(".ruby-lsp")
|
47
|
+
run_bundle_install
|
48
|
+
return
|
49
|
+
end
|
50
|
+
|
51
|
+
# Automatically create and ignore the .ruby-lsp folder for users
|
52
|
+
FileUtils.mkdir(".ruby-lsp") unless Dir.exist?(".ruby-lsp")
|
53
|
+
File.write(".ruby-lsp/.gitignore", "*") unless File.exist?(".ruby-lsp/.gitignore")
|
54
|
+
|
55
|
+
# Write the custom `.ruby-lsp/Gemfile` if it doesn't exist or if the content doesn't match
|
56
|
+
content = custom_gemfile_content
|
57
|
+
|
58
|
+
unless File.exist?(".ruby-lsp/Gemfile") && File.read(".ruby-lsp/Gemfile") == content
|
59
|
+
File.write(".ruby-lsp/Gemfile", content)
|
60
|
+
end
|
61
|
+
|
62
|
+
# If .ruby-lsp/Gemfile.lock already exists and the top level Gemfile.lock hasn't been modified since it was last
|
63
|
+
# updated, then we're ready to boot the server
|
64
|
+
if File.exist?(".ruby-lsp/Gemfile.lock") &&
|
65
|
+
File.stat(".ruby-lsp/Gemfile.lock").mtime > File.stat("Gemfile.lock").mtime
|
66
|
+
warn("Ruby LSP> Skipping custom bundle setup since .ruby-lsp/Gemfile.lock already exists and is up to date")
|
67
|
+
run_bundle_install(".ruby-lsp/Gemfile")
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
FileUtils.cp("Gemfile.lock", ".ruby-lsp/Gemfile.lock")
|
72
|
+
run_bundle_install(".ruby-lsp/Gemfile")
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
sig { returns(String) }
|
78
|
+
def custom_gemfile_content
|
79
|
+
parts = [
|
80
|
+
"# This custom gemfile is automatically generated by the Ruby LSP.",
|
81
|
+
"# It should be automatically git ignored, but in any case: do not commit it to your repository.",
|
82
|
+
"",
|
83
|
+
"eval_gemfile(File.expand_path(\"../Gemfile\", __dir__))",
|
84
|
+
]
|
85
|
+
|
86
|
+
unless @dependencies["ruby-lsp"]
|
87
|
+
parts << 'gem "ruby-lsp", require: false, group: :development, source: "https://rubygems.org"'
|
88
|
+
end
|
89
|
+
|
90
|
+
unless @dependencies["debug"]
|
91
|
+
parts << 'gem "debug", require: false, group: :development, platforms: :mri, source: "https://rubygems.org"'
|
92
|
+
end
|
93
|
+
|
94
|
+
parts.join("\n")
|
95
|
+
end
|
96
|
+
|
97
|
+
sig { returns(T::Hash[String, T.untyped]) }
|
98
|
+
def load_dependencies
|
99
|
+
# We need to parse the Gemfile.lock manually here. If we try to do `bundler/setup` to use something more
|
100
|
+
# convenient, we may end up with issues when the globally installed `ruby-lsp` version mismatches the one included
|
101
|
+
# in the `Gemfile`
|
102
|
+
dependencies = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock")).dependencies
|
103
|
+
|
104
|
+
# When working on a gem, the `ruby-lsp` might be listed as a dependency in the gemspec. We need to make sure we
|
105
|
+
# check those as well or else we may get version mismatch errors
|
106
|
+
gemspec_path = Dir.glob("*.gemspec").first
|
107
|
+
if gemspec_path
|
108
|
+
gemspec_dependencies = Bundler.load_gemspec(gemspec_path).dependencies.to_h { |dep| [dep.name, dep] }
|
109
|
+
dependencies.merge!(gemspec_dependencies)
|
110
|
+
end
|
111
|
+
|
112
|
+
dependencies
|
113
|
+
end
|
114
|
+
|
115
|
+
sig { params(bundle_gemfile: T.untyped).void }
|
116
|
+
def run_bundle_install(bundle_gemfile = nil)
|
117
|
+
# If the user has a custom bundle path configured, we need to ensure that we will use the absolute and not
|
118
|
+
# relative version of it when running `bundle install`. This is necessary to avoid installing the gems under the
|
119
|
+
# `.ruby-lsp` folder, which is not the user's intention. For example, if the path is configured as `vendor`, we
|
120
|
+
# want to install it in the top level `vendor` and not `.ruby-lsp/vendor`
|
121
|
+
path = Bundler.settings["path"]
|
122
|
+
|
123
|
+
command = +""
|
124
|
+
# Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
|
125
|
+
command << "BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} " if path
|
126
|
+
command << "BUNDLE_GEMFILE=#{bundle_gemfile} " if bundle_gemfile
|
127
|
+
|
128
|
+
# If both `ruby-lsp` and `debug` are already in the Gemfile, then we shouldn't try to upgrade them or else we'll
|
129
|
+
# produce undesired source control changes. If the custom bundle was just created and either `ruby-lsp` or `debug`
|
130
|
+
# weren't a part of the Gemfile, then we need to run `bundle install` for the first time to generate the
|
131
|
+
# Gemfile.lock with them included or else Bundler will complain that they're missing. We can only update if the
|
132
|
+
# custom `.ruby-lsp/Gemfile.lock` already exists and includes both gems
|
133
|
+
if (@dependencies["ruby-lsp"] && @dependencies["debug"]) ||
|
134
|
+
@custom_bundle_dependencies["ruby-lsp"].nil? || @custom_bundle_dependencies["debug"].nil?
|
135
|
+
# Install gems using the custom bundle
|
136
|
+
command << "bundle install "
|
137
|
+
else
|
138
|
+
# If ruby-lsp or debug are not in the Gemfile, try to update them to the latest version
|
139
|
+
command << "bundle update "
|
140
|
+
command << "ruby-lsp " unless @dependencies["ruby-lsp"]
|
141
|
+
command << "debug " unless @dependencies["debug"]
|
142
|
+
end
|
143
|
+
|
144
|
+
# Redirect stdout to stderr to prevent going into an infinite loop. The extension might confuse stdout output with
|
145
|
+
# responses
|
146
|
+
command << "1>&2"
|
147
|
+
|
148
|
+
# Add bundle update
|
149
|
+
warn("Ruby LSP> Running bundle install for the custom bundle. This may take a while...")
|
150
|
+
system(command)
|
151
|
+
end
|
152
|
+
end
|
16
153
|
end
|
17
|
-
|
18
|
-
# We need to parse the Gemfile.lock manually here. If we try to do `bundler/setup` to use something more convenient, we
|
19
|
-
# may end up with issues when the globally installed `ruby-lsp` version mismatches the one included in the `Gemfile`
|
20
|
-
dependencies = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock")).dependencies
|
21
|
-
|
22
|
-
# When working on a gem, the `ruby-lsp` might be listed as a dependency in the gemspec. We need to make sure we check
|
23
|
-
# those as well or else we may get version mismatch errors
|
24
|
-
gemspec_path = Dir.glob("*.gemspec").first
|
25
|
-
if gemspec_path
|
26
|
-
gemspec_dependencies = Bundler.load_gemspec(gemspec_path).dependencies.to_h { |dep| [dep.name, dep] }
|
27
|
-
dependencies.merge!(gemspec_dependencies)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Do not setup a custom bundle if both `ruby-lsp` and `debug` are already in the Gemfile
|
31
|
-
if dependencies["ruby-lsp"] && dependencies["debug"]
|
32
|
-
warn("Ruby LSP> Skipping custom bundle setup since both `ruby-lsp` and `debug` are already in the Gemfile")
|
33
|
-
return
|
34
|
-
end
|
35
|
-
|
36
|
-
# Automatically create and ignore the .ruby-lsp folder for users
|
37
|
-
FileUtils.mkdir(".ruby-lsp") unless Dir.exist?(".ruby-lsp")
|
38
|
-
File.write(".ruby-lsp/.gitignore", "*") unless File.exist?(".ruby-lsp/.gitignore")
|
39
|
-
|
40
|
-
parts = [
|
41
|
-
"# This custom gemfile is automatically generated by the Ruby LSP.",
|
42
|
-
"# It should be automatically git ignored, but in any case: do not commit it to your repository.",
|
43
|
-
"",
|
44
|
-
"eval_gemfile(File.expand_path(\"../Gemfile\", __dir__))",
|
45
|
-
]
|
46
|
-
|
47
|
-
unless dependencies["ruby-lsp"]
|
48
|
-
parts << 'gem "ruby-lsp", require: false, group: :development, source: "https://rubygems.org"'
|
49
|
-
end
|
50
|
-
|
51
|
-
unless dependencies["debug"]
|
52
|
-
parts << 'gem "debug", require: false, group: :development, platforms: :mri, source: "https://rubygems.org"'
|
53
|
-
end
|
54
|
-
|
55
|
-
gemfile_content = parts.join("\n")
|
56
|
-
|
57
|
-
unless File.exist?(".ruby-lsp/Gemfile") && File.read(".ruby-lsp/Gemfile") == gemfile_content
|
58
|
-
File.write(".ruby-lsp/Gemfile", gemfile_content)
|
59
|
-
end
|
60
|
-
|
61
|
-
# If .ruby-lsp/Gemfile.lock already exists and the top level Gemfile.lock hasn't been modified since it was last
|
62
|
-
# updated, then we're ready to boot the server
|
63
|
-
if File.exist?(".ruby-lsp/Gemfile.lock") && File.stat(".ruby-lsp/Gemfile.lock").mtime > File.stat("Gemfile.lock").mtime
|
64
|
-
warn("Ruby LSP> Skipping custom bundle setup since .ruby-lsp/Gemfile.lock already exists and is up to date")
|
65
|
-
return
|
66
|
-
end
|
67
|
-
|
68
|
-
FileUtils.cp("Gemfile.lock", ".ruby-lsp/Gemfile.lock")
|
69
|
-
|
70
|
-
# If the user has a custom bundle path configured, we need to ensure that we will use the absolute and not relative
|
71
|
-
# version of it when running bundle install. This is necessary to avoid installing the gems under the `.ruby-lsp`
|
72
|
-
# folder, which is not the user's intention. For example, if path is configured as `vendor`, we want to install it in
|
73
|
-
# the top level `vendor` and not `.ruby-lsp/vendor`
|
74
|
-
path = Bundler.settings["path"]
|
75
|
-
|
76
|
-
command = +""
|
77
|
-
# Use the absolute `BUNDLE_PATH` to prevent accidentally creating unwanted folders under `.ruby-lsp`
|
78
|
-
command << "BUNDLE_PATH=#{File.expand_path(path, Dir.pwd)} " if path
|
79
|
-
# Install gems using the custom bundle
|
80
|
-
command << "BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle install "
|
81
|
-
# Redirect stdout to stderr to prevent going into an infinite loop. The extension might confuse stdout output with
|
82
|
-
# responses
|
83
|
-
command << "1>&2"
|
84
|
-
|
85
|
-
warn("Ruby LSP> Running bundle install for the custom bundle. This may take a while...")
|
86
|
-
system(command)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lsp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: language_server-protocol
|